use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class SwiftLibrary method getSharedLibraries.
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, SourcePath> libs = ImmutableMap.builder();
BuildRule sharedLibraryBuildRule = requireSwiftLinkRule(cxxPlatform.getFlavor());
String sharedLibrarySoname = CxxDescriptionEnhancer.getSharedLibrarySoname(Optional.empty(), sharedLibraryBuildRule.getBuildTarget(), cxxPlatform);
libs.put(sharedLibrarySoname, sharedLibraryBuildRule.getSourcePathToOutput());
return libs.build();
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class SrcZipAwareFileBundler method createRelativeMap.
private ImmutableMap<Path, Path> createRelativeMap(ProjectFilesystem filesystem, final SourcePathResolver resolver, ImmutableSortedSet<SourcePath> toCopy) {
Map<Path, Path> relativePathMap = new HashMap<>();
for (SourcePath sourcePath : toCopy) {
Path absoluteBasePath = resolver.getAbsolutePath(sourcePath);
try {
if (Files.isDirectory(absoluteBasePath)) {
ImmutableSet<Path> files = filesystem.getFilesUnderPath(absoluteBasePath);
Path absoluteBasePathParent = absoluteBasePath.getParent();
for (Path file : files) {
Path absoluteFilePath = filesystem.resolve(file);
findAndAddRelativePathToMap(absoluteFilePath, file, absoluteBasePathParent, relativePathMap);
}
} else {
findAndAddRelativePathToMap(absoluteBasePath, resolver.getRelativePath(sourcePath), absoluteBasePath.getParent(), relativePathMap);
}
} catch (IOException e) {
throw new RuntimeException(String.format("Couldn't read directory [%s].", absoluteBasePath.toString()), e);
}
}
return ImmutableMap.copyOf(relativePathMap);
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AndroidInstrumentationApkTest method testAndroidInstrumentationApkExcludesClassesFromInstrumentedApk.
@Test
public void testAndroidInstrumentationApkExcludesClassesFromInstrumentedApk() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildTarget javaLibrary1Target = BuildTargetFactory.newInstance("//java/com/example:lib1");
final FakeJavaLibrary javaLibrary1 = new FakeJavaLibrary(javaLibrary1Target, pathResolver);
FakeJavaLibrary javaLibrary2 = new FakeJavaLibrary(BuildTargetFactory.newInstance("//java/com/example:lib2"), pathResolver, /* deps */
ImmutableSortedSet.of((BuildRule) javaLibrary1)) {
@Override
public ImmutableSet<SourcePath> getTransitiveClasspaths() {
return ImmutableSet.of(new DefaultBuildTargetSourcePath(javaLibrary1Target), getSourcePathToOutput());
}
};
BuildTarget javaLibrary3Target = BuildTargetFactory.newInstance("//java/com/example:lib3");
final FakeJavaLibrary javaLibrary3 = new FakeJavaLibrary(javaLibrary3Target, pathResolver);
FakeJavaLibrary javaLibrary4 = new FakeJavaLibrary(BuildTargetFactory.newInstance("//java/com/example:lib4"), pathResolver, /* deps */
ImmutableSortedSet.of((BuildRule) javaLibrary3)) {
@Override
public ImmutableSet<SourcePath> getTransitiveClasspaths() {
return ImmutableSet.of(new DefaultBuildTargetSourcePath(javaLibrary3Target), getSourcePathToOutput());
}
};
ruleResolver.addToIndex(javaLibrary1);
ruleResolver.addToIndex(javaLibrary2);
ruleResolver.addToIndex(javaLibrary3);
ruleResolver.addToIndex(javaLibrary4);
BuildRule keystore = KeystoreBuilder.createBuilder(BuildTargetFactory.newInstance("//keystores:debug")).setProperties(new FakeSourcePath("keystores/debug.properties")).setStore(new FakeSourcePath("keystores/debug.keystore")).build(ruleResolver);
// AndroidBinaryRule transitively depends on :lib1, :lib2, and :lib3.
AndroidBinaryBuilder androidBinaryBuilder = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//apps:app"));
ImmutableSortedSet<BuildTarget> originalDepsTargets = ImmutableSortedSet.of(javaLibrary2.getBuildTarget(), javaLibrary3.getBuildTarget());
androidBinaryBuilder.setManifest(new FakeSourcePath("apps/AndroidManifest.xml")).setKeystore(keystore.getBuildTarget()).setOriginalDeps(originalDepsTargets);
AndroidBinary androidBinary = androidBinaryBuilder.build(ruleResolver);
// AndroidInstrumentationApk transitively depends on :lib1, :lib2, :lib3, and :lib4.
ImmutableSortedSet<BuildTarget> apkOriginalDepsTargets = ImmutableSortedSet.of(javaLibrary2.getBuildTarget(), javaLibrary4.getBuildTarget());
AndroidInstrumentationApkDescription.Arg arg = new AndroidInstrumentationApkDescription.Arg();
arg.apk = androidBinary.getBuildTarget();
arg.deps = apkOriginalDepsTargets;
arg.manifest = new FakeSourcePath("apps/InstrumentationAndroidManifest.xml");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//apps:instrumentation")).setDeclaredDeps(ruleResolver.getAllRules(apkOriginalDepsTargets)).setExtraDeps(ImmutableSortedSet.of(androidBinary)).build();
AndroidInstrumentationApk androidInstrumentationApk = (AndroidInstrumentationApk) new AndroidInstrumentationApkDescription(new ProGuardConfig(FakeBuckConfig.builder().build()), DEFAULT_JAVAC_OPTIONS, ImmutableMap.of(), MoreExecutors.newDirectExecutorService(), CxxPlatformUtils.DEFAULT_CONFIG, new DxConfig(FakeBuckConfig.builder().build())).createBuildRule(TargetGraph.EMPTY, params, ruleResolver, arg);
assertEquals("//apps:app should have three JAR files to dex.", ImmutableSet.of(BuildTargets.getGenPath(javaLibrary1.getProjectFilesystem(), javaLibrary1.getBuildTarget(), "%s.jar"), BuildTargets.getGenPath(javaLibrary2.getProjectFilesystem(), javaLibrary2.getBuildTarget(), "%s.jar"), BuildTargets.getGenPath(javaLibrary3.getProjectFilesystem(), javaLibrary3.getBuildTarget(), "%s.jar")), androidBinary.getAndroidPackageableCollection().getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
assertEquals("//apps:instrumentation should have one JAR file to dex.", ImmutableSet.of(BuildTargets.getGenPath(javaLibrary4.getProjectFilesystem(), javaLibrary4.getBuildTarget(), "%s.jar")), androidInstrumentationApk.getAndroidPackageableCollection().getClasspathEntriesToDex().stream().map(pathResolver::getRelativePath).collect(MoreCollectors.toImmutableSet()));
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AndroidPackageableCollectorTest method testFindTransitiveDependencies.
/**
* This is a regression test to ensure that an additional 1 second startup cost is not
* re-introduced to fb4a.
*/
@Test
public void testFindTransitiveDependencies() throws Exception {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
Path prebuiltNativeLibraryPath = Paths.get("java/com/facebook/prebuilt_native_library/libs");
projectFilesystem.mkdirs(prebuiltNativeLibraryPath);
// Create an AndroidBinaryRule that transitively depends on two prebuilt JARs. One of the two
// prebuilt JARs will be listed in the AndroidBinaryRule's no_dx list.
BuildTarget guavaTarget = BuildTargetFactory.newInstance("//third_party/guava:guava");
TargetNode<?, ?> guava = PrebuiltJarBuilder.createBuilder(guavaTarget).setBinaryJar(Paths.get("third_party/guava/guava-10.0.1.jar")).build();
BuildTarget jsr305Target = BuildTargetFactory.newInstance("//third_party/jsr-305:jsr-305");
TargetNode<?, ?> jsr = PrebuiltJarBuilder.createBuilder(jsr305Target).setBinaryJar(Paths.get("third_party/jsr-305/jsr305.jar")).build();
TargetNode<?, ?> ndkLibrary = new NdkLibraryBuilder(BuildTargetFactory.newInstance("//java/com/facebook/native_library:library"), projectFilesystem).build();
BuildTarget prebuiltNativeLibraryTarget = BuildTargetFactory.newInstance("//java/com/facebook/prebuilt_native_library:library");
TargetNode<?, ?> prebuiltNativeLibraryBuild = PrebuiltNativeLibraryBuilder.newBuilder(prebuiltNativeLibraryTarget, projectFilesystem).setNativeLibs(prebuiltNativeLibraryPath).setIsAsset(true).build();
BuildTarget libraryRuleTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:example");
TargetNode<?, ?> library = JavaLibraryBuilder.createBuilder(libraryRuleTarget).setProguardConfig(new FakeSourcePath("debug.pro")).addSrc(Paths.get("Example.java")).addDep(guavaTarget).addDep(jsr305Target).addDep(prebuiltNativeLibraryBuild.getBuildTarget()).addDep(ndkLibrary.getBuildTarget()).build();
BuildTarget manifestTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:res");
TargetNode<?, ?> manifest = AndroidResourceBuilder.createBuilder(manifestTarget).setManifest(new PathSourcePath(projectFilesystem, Paths.get("java/src/com/facebook/module/AndroidManifest.xml"))).setAssets(new FakeSourcePath("assets")).build();
BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//keystore:debug");
TargetNode<?, ?> keystore = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath(projectFilesystem, "keystore/debug.keystore")).setProperties(new FakeSourcePath(projectFilesystem, "keystore/debug.keystore.properties")).build();
ImmutableSortedSet<BuildTarget> originalDepsTargets = ImmutableSortedSet.of(libraryRuleTarget, manifestTarget);
BuildTarget binaryTarget = BuildTargetFactory.newInstance("//java/src/com/facebook:app");
TargetNode<?, ?> binary = AndroidBinaryBuilder.createBuilder(binaryTarget).setOriginalDeps(originalDepsTargets).setBuildTargetsToExcludeFromDex(ImmutableSet.of(BuildTargetFactory.newInstance("//third_party/guava:guava"))).setManifest(new FakeSourcePath("java/src/com/facebook/AndroidManifest.xml")).setKeystore(keystoreTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(binary, library, manifest, keystore, ndkLibrary, prebuiltNativeLibraryBuild, guava, jsr);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
AndroidBinary binaryRule = (AndroidBinary) ruleResolver.requireRule(binaryTarget);
NdkLibrary ndkLibraryRule = (NdkLibrary) ruleResolver.requireRule(ndkLibrary.getBuildTarget());
NativeLibraryBuildRule prebuildNativeLibraryRule = (NativeLibraryBuildRule) ruleResolver.requireRule(prebuiltNativeLibraryTarget);
// Verify that the correct transitive dependencies are found.
AndroidPackageableCollection packageableCollection = binaryRule.getAndroidPackageableCollection();
assertResolvedEquals("Because guava was passed to no_dx, it should not be in the classpathEntriesToDex list", pathResolver, ImmutableSet.of(ruleResolver.getRule(jsr305Target).getSourcePathToOutput(), ruleResolver.getRule(libraryRuleTarget).getSourcePathToOutput()), packageableCollection.getClasspathEntriesToDex());
assertResolvedEquals("Because guava was passed to no_dx, it should not be treated as a third-party JAR whose " + "resources need to be extracted and repacked in the APK. If this is done, then code " + "in the guava-10.0.1.dex.1.jar in the APK's assets/ tmp may try to load the resource " + "from the APK as a ZipFileEntry rather than as a resource within " + "guava-10.0.1.dex.1.jar. Loading a resource in this way could take substantially " + "longer. Specifically, this was observed to take over one second longer to load " + "the resource in fb4a. Because the resource was loaded on startup, this introduced a " + "substantial regression in the startup time for the fb4a app.", pathResolver, ImmutableSet.of(ruleResolver.getRule(jsr305Target).getSourcePathToOutput()), packageableCollection.getPathsToThirdPartyJars());
assertResolvedEquals("Because assets directory was passed an AndroidResourceRule it should be added to the " + "transitive dependencies", pathResolver, ImmutableSet.of(new DefaultBuildTargetSourcePath(manifestTarget.withAppendedFlavors(AndroidResourceDescription.ASSETS_SYMLINK_TREE_FLAVOR))), packageableCollection.getAssetsDirectories());
assertResolvedEquals("Because a native library was declared as a dependency, it should be added to the " + "transitive dependencies.", pathResolver, ImmutableSet.<SourcePath>of(new PathSourcePath(new FakeProjectFilesystem(), ndkLibraryRule.getLibraryPath())), ImmutableSet.copyOf(packageableCollection.getNativeLibsDirectories().values()));
assertResolvedEquals("Because a prebuilt native library was declared as a dependency (and asset), it should " + "be added to the transitive dependecies.", pathResolver, ImmutableSet.<SourcePath>of(new PathSourcePath(new FakeProjectFilesystem(), prebuildNativeLibraryRule.getLibraryPath())), ImmutableSet.copyOf(packageableCollection.getNativeLibAssetsDirectories().values()));
assertEquals(ImmutableSet.of(new FakeSourcePath("debug.pro")), packageableCollection.getProguardConfigs());
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AndroidResourceDescriptionTest method testNonAssetFilesAndDirsAreIgnored.
@Test
public void testNonAssetFilesAndDirsAreIgnored() throws IOException {
tmpFolder.newFolder("res");
tmpFolder.newFile("res/image.png");
tmpFolder.newFile("res/layout.xml");
tmpFolder.newFile("res/_file");
tmpFolder.newFile("res/.gitkeep");
tmpFolder.newFile("res/.svn");
tmpFolder.newFile("res/.git");
tmpFolder.newFile("res/.ds_store");
tmpFolder.newFile("res/.scc");
tmpFolder.newFile("res/CVS");
tmpFolder.newFile("res/thumbs.db");
tmpFolder.newFile("res/picasa.ini");
tmpFolder.newFile("res/file.bak~");
tmpFolder.newFolder("res", "dirs", "values");
tmpFolder.newFile("res/dirs/values/strings.xml");
tmpFolder.newFile("res/dirs/values/strings.xml.orig");
tmpFolder.newFolder("res", "dirs", ".gitkeep");
tmpFolder.newFile("res/dirs/.gitkeep/ignore");
tmpFolder.newFolder("res", "dirs", ".svn");
tmpFolder.newFile("res/dirs/.svn/ignore");
tmpFolder.newFolder("res", "dirs", ".git");
tmpFolder.newFile("res/dirs/.git/ignore");
tmpFolder.newFolder("res", "dirs", ".ds_store");
tmpFolder.newFile("res/dirs/.ds_store/ignore");
tmpFolder.newFolder("res", "dirs", ".scc");
tmpFolder.newFile("res/dirs/.scc/ignore");
tmpFolder.newFolder("res", "dirs", "CVS");
tmpFolder.newFile("res/dirs/CVS/ignore");
tmpFolder.newFolder("res", "dirs", "thumbs.db");
tmpFolder.newFile("res/dirs/thumbs.db/ignore");
tmpFolder.newFolder("res", "dirs", "picasa.ini");
tmpFolder.newFile("res/dirs/picasa.ini/ignore");
tmpFolder.newFolder("res", "dirs", "file.bak~");
tmpFolder.newFile("res/dirs/file.bak~/ignore");
tmpFolder.newFolder("res", "dirs", "_dir");
tmpFolder.newFile("res/dirs/_dir/ignore");
AndroidResourceDescription description = new AndroidResourceDescription(false);
ProjectFilesystem filesystem = new ProjectFilesystem(tmpFolder.getRoot().toPath());
Map<Path, SourcePath> inputs = description.collectInputFiles(filesystem, Paths.get("res"));
assertThat(inputs, equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get("image.png"), new FakeSourcePath(filesystem, "res/image.png"), Paths.get("layout.xml"), new FakeSourcePath(filesystem, "res/layout.xml"), Paths.get("_file"), new FakeSourcePath(filesystem, "res/_file"), Paths.get("dirs/values/strings.xml"), new FakeSourcePath(filesystem, "res/dirs/values/strings.xml"))));
}
Aggregations