aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-06-01 08:16:18 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-06-01 15:49:42 +0000
commit2b17ce29daefb3a49f2552c417349c35cb4ff715 (patch)
treea222736781caa10c89843c6c993fcc1436461e8a /src/main/java/com/google/devtools/build/lib
parent0833ac6f2ed098ccbe25e986f10437d8e6ddfad6 (diff)
Use the -nf option of ApkBuilder (which is available in the Android SDK) instead of the -nl one (which is not) to include native libraries.
The alternative implementation uses a symlink tree, but given that we never have many native libraries, I opted for the simpler approach. -- MOS_MIGRATED_REVID=94891099
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java18
2 files changed, 26 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
index 2a36d8df5f..76d8d5702f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
@@ -1042,13 +1042,14 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.addInputArgument(javaResourceZip);
}
- for (Map.Entry<String, Iterable<Artifact>> entry : nativeLibs.getMap().entrySet()) {
- for (Artifact library : entry.getValue()) {
- actionBuilder
- .addArgument("-nl")
- .addArgument(entry.getKey())
- .addInputArgument(library);
- }
+ ImmutableList<Artifact> nativeSymlinks = nativeLibs.createApkBuilderSymlinks(ruleContext);
+ if (!nativeSymlinks.isEmpty()) {
+ actionBuilder
+ .addInputs(nativeSymlinks)
+ .addArgument("-nf")
+ // If the native libs are "foo/bar/x86/foo.so", we need to pass "foo/bar" here
+ .addArgument(nativeSymlinks.get(0).getExecPath()
+ .getParentDirectory().getParentDirectory().getPathString());
}
if (nativeLibs.getName() != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
index 3acf1fc350..965106e7aa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java
@@ -20,6 +20,7 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
+import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.rules.cpp.CcLinkParams;
@@ -106,6 +107,23 @@ public final class NativeLibs {
return nativeLibs;
}
+ public ImmutableList<Artifact> createApkBuilderSymlinks(RuleContext ruleContext) {
+ ImmutableList.Builder<Artifact> result = ImmutableList.builder();
+ for (Map.Entry<String, Iterable<Artifact>> entry : nativeLibs.entrySet()) {
+ String arch = entry.getKey();
+ for (Artifact lib : entry.getValue()) {
+ Artifact symlink = AndroidBinary.getDxArtifact(ruleContext,
+ "native_symlinks/" + arch + "/" + lib.getExecPath().getBaseName());
+ ruleContext.registerAction(new SymlinkAction(
+ ruleContext.getActionOwner(), lib, symlink,
+ "Symlinking Android native library for " + ruleContext.getLabel()));
+ result.add(symlink);
+ }
+ }
+
+ return result.build();
+ }
+
/**
* Returns the artifact containing the names of the native libraries or null if it does not exist.
*