use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGeneratorTest method getBuildRuleResolverNodeFunction.
private Function<TargetNode<?, ?>, BuildRuleResolver> getBuildRuleResolverNodeFunction(final TargetGraph targetGraph) {
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException> bottomUpTraversal = new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(targetGraph) {
@Override
@SuppressWarnings("PMD.EmptyCatchBlock")
public void visit(TargetNode<?, ?> node) {
try {
resolver.requireRule(node.getBuildTarget());
} catch (Exception e) {
// NOTE(agallagher): A large number of the tests appear to setup their target nodes
// incorrectly, causing action graph creation to fail with lots of missing expected
// Apple C/C++ platform flavors. This is gross, but to support tests that need a
// complete sub-action graph, just skip over the errors.
}
}
};
bottomUpTraversal.traverse();
return input -> resolver;
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGeneratorTest method testAggregateTargetForLibraryForBuildWithBuck.
@Test
public void testAggregateTargetForLibraryForBuildWithBuck() throws IOException {
BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "library").build();
TargetNode<?, ?> binaryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(libraryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGenerator.createXcodeProjects();
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertHasConfigurations(buildWithBuckTarget, "Debug");
assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + libraryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGeneratorTest method testAggregateTargetForBundleForBuildWithBuck.
@Test
public void testAggregateTargetForBundleForBuildWithBuck() throws IOException {
BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(bundleNode, binaryNode);
final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(bundleTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGenerator.createXcodeProjects();
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertHasConfigurations(buildWithBuckTarget, "Debug");
assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
assertEquals("Should have exact number of build phases", 2, buildWithBuckTarget.getBuildPhases().size());
PBXBuildPhase buildPhase = Iterables.get(buildWithBuckTarget.getBuildPhases(), 0);
assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
assertThat(shellScriptBuildPhase.getShellScript(), containsString("-- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + bundleTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.dSYM") + " " + bundleTarget.getShortName()));
assertThat(shellScriptBuildPhase.getShellScript(), containsString("machoutils absolutify_object_paths --binary $BUCK_BUNDLE_OUTPUT_PATH/bundle " + "--output " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app/bundle") + " --old_compdir " + "\"./////////////////////"));
// skipping some slashes: ".//////////// ..... ///////"
assertThat(shellScriptBuildPhase.getShellScript(), containsString("////////\" --new_compdir \"" + filesystem.getRootPath().toString() + "\""));
PBXBuildPhase codesignPhase = buildWithBuckTarget.getBuildPhases().get(1);
assertThat(codesignPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase codesignShellScriptPhase = (PBXShellScriptBuildPhase) codesignPhase;
Path codesignScriptPath = ProjectGenerator.getCodesignScriptPath(filesystem);
assertThat(codesignShellScriptPhase.getShellScript(), containsString("python " + codesignScriptPath + " /usr/bin/codesign " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app")));
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetsCommandTest method testDetectTestChanges.
@Test
public void testDetectTestChanges() throws CmdLineException, IOException {
BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget libraryTestTarget1 = BuildTargetFactory.newInstance("//foo:xctest1");
BuildTarget libraryTestTarget2 = BuildTargetFactory.newInstance("//foo:xctest2");
BuildTarget testLibraryTarget = BuildTargetFactory.newInstance("//testlib:testlib");
BuildTarget testLibraryTestTarget = BuildTargetFactory.newInstance("//testlib:testlib-xctest");
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/foo.m")))).setTests(ImmutableSortedSet.of(libraryTestTarget1, libraryTestTarget2)).build();
TargetNode<?, ?> libraryTestNode1 = AppleTestBuilder.createBuilder(libraryTestTarget1).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/testfoo1.m")))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
TargetNode<?, ?> libraryTestNode2 = AppleTestBuilder.createBuilder(libraryTestTarget2).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo/testfoo2.m")))).setDeps(ImmutableSortedSet.of(testLibraryTarget)).build();
TargetNode<?, ?> testLibraryNode = AppleLibraryBuilder.createBuilder(testLibraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("testlib/testlib.m")))).setTests(ImmutableSortedSet.of(testLibraryTestTarget)).build();
TargetNode<?, ?> testLibraryTestNode = AppleTestBuilder.createBuilder(testLibraryTestTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("testlib/testlib-test.m")))).setDeps(ImmutableSortedSet.of(testLibraryTarget)).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(libraryNode, libraryTestNode1, libraryTestNode2, testLibraryNode, testLibraryTestNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
// No target depends on the referenced file.
SortedMap<String, TargetNode<?, ?>> matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/bar.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertTrue(matchingBuildRules.isEmpty());
// Test1, test2 and the library depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/testfoo1.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1"), matchingBuildRules.keySet());
// Test1, test2 and the library depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("foo/testfoo2.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2"), matchingBuildRules.keySet());
// Library, test1, test2, test library and its test depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("testlib/testlib.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2", "//testlib:testlib", "//testlib:testlib-xctest"), matchingBuildRules.keySet());
// Library, test1, test2, test library and its test depend on the referenced file.
matchingBuildRules = targetsCommand.getMatchingNodes(targetGraph, Optional.of(ImmutableSet.of(Paths.get("testlib/testlib-test.m"))), Optional.empty(), Optional.empty(), true, "BUCK");
assertEquals(ImmutableSet.of("//foo:lib", "//foo:xctest1", "//foo:xctest2", "//testlib:testlib", "//testlib:testlib-xctest"), matchingBuildRules.keySet());
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectTest method createActionGraphForTesting.
/**
* Creates an ActionGraph with two android_binary rules, each of which depends on the same
* android_library. The difference between the two is that one lists Guava in its no_dx list and
* the other does not.
* <p>
* The ActionGraph also includes three project_config rules: one for the android_library, and one
* for each of the android_binary rules.
*/
public Pair<ProjectWithModules, BuildRuleResolver> createActionGraphForTesting(@Nullable JavaPackageFinder javaPackageFinder) throws Exception {
ImmutableSet.Builder<TargetNode<?, ?>> nodes = ImmutableSet.builder();
// prebuilt_jar //third_party/guava:guava
TargetNode<?, ?> guavaNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/guava:guava")).setBinaryJar(PATH_TO_GUAVA_JAR).build();
nodes.add(guavaNode);
// android_resouce android_res/base:res
TargetNode<?, ?> androidResNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//android_res/base:res")).setRes(new FakeSourcePath("android_res/base/res")).setRDotJavaPackage("com.facebook").build();
nodes.add(androidResNode);
// project_config android_res/base:res
TargetNode<?, ?> projectConfigForResourceNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//android_res/base:project_config")).setSrcRule(androidResNode.getBuildTarget()).setSrcRoots(ImmutableList.of("res")).build();
nodes.add(projectConfigForResourceNode);
// java_library //java/src/com/facebook/grandchild:grandchild
BuildTarget grandchildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/grandchild:grandchild");
TargetNode<?, ?> grandchildNode = JavaLibraryBuilder.createBuilder(grandchildTarget).addSrc(Paths.get("Grandchild.java")).build();
nodes.add(grandchildNode);
// java_library //java/src/com/facebook/child:child
TargetNode<?, ?> childNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/child:child")).addSrc(Paths.get("Child.java")).addDep(grandchildNode.getBuildTarget()).build();
nodes.add(childNode);
// java_library //java/src/com/facebook/exportlib:exportlib
TargetNode<?, ?> exportLibNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/exportlib:exportlib")).addSrc(Paths.get("ExportLib.java")).addDep(guavaNode.getBuildTarget()).addExportedDep(guavaNode.getBuildTarget()).build();
nodes.add(exportLibNode);
// android_library //java/src/com/facebook/base:base
TargetNode<?, ?> baseNode = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/base:base")).addSrc(Paths.get("Base.java")).addDep(exportLibNode.getBuildTarget()).addDep(childNode.getBuildTarget()).addDep(androidResNode.getBuildTarget()).build();
nodes.add(baseNode);
// project_config //java/src/com/facebook/base:project_config
TargetNode<?, ?> projectConfigForLibraryNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/base:project_config")).setSrcRule(baseNode.getBuildTarget()).setSrcRoots(ImmutableList.of("src", "src-gen")).build();
nodes.add(projectConfigForLibraryNode);
TargetNode<?, ?> projectConfigForExportLibraryNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/src/com/facebook/exportlib:project_config")).setSrcRule(exportLibNode.getBuildTarget()).setSrcRoots(ImmutableList.of("src")).build();
nodes.add(projectConfigForExportLibraryNode);
// keystore //keystore:debug
BuildTarget keystoreTarget = BuildTargetFactory.newInstance("//keystore:debug");
TargetNode<?, ?> keystoreNode = KeystoreBuilder.createBuilder(keystoreTarget).setStore(new FakeSourcePath("keystore/debug.keystore")).setProperties(new FakeSourcePath("keystore/debug.keystore.properties")).build();
nodes.add(keystoreNode);
// android_binary //foo:app
ImmutableSortedSet<BuildTarget> androidBinaryRuleDepsTarget = ImmutableSortedSet.of(baseNode.getBuildTarget());
TargetNode<?, ?> androidBinaryNode = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:app")).setOriginalDeps(androidBinaryRuleDepsTarget).setManifest(new FakeSourcePath("foo/AndroidManifest.xml")).setKeystore(keystoreNode.getBuildTarget()).setBuildTargetsToExcludeFromDex(ImmutableSet.of(BuildTargetFactory.newInstance("//third_party/guava:guava"))).build();
nodes.add(androidBinaryNode);
// project_config //foo:project_config
TargetNode<?, ?> projectConfigUsingNoDxNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//foo:project_config")).setSrcRule(androidBinaryNode.getBuildTarget()).build();
nodes.add(projectConfigUsingNoDxNode);
// android_binary //bar:app
ImmutableSortedSet<BuildTarget> barAppBuildRuleDepsTarget = ImmutableSortedSet.of(baseNode.getBuildTarget());
TargetNode<?, ?> barAppBuildNode = AndroidBinaryBuilder.createBuilder(BuildTargetFactory.newInstance("//bar:app")).setOriginalDeps(barAppBuildRuleDepsTarget).setManifest(new FakeSourcePath("foo/AndroidManifest.xml")).setKeystore(keystoreNode.getBuildTarget()).build();
nodes.add(barAppBuildNode);
// project_config //bar:project_config
TargetNode<?, ?> projectConfigNode = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//bar:project_config")).setSrcRule(barAppBuildNode.getBuildTarget()).build();
nodes.add(projectConfigNode);
TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes.build());
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
guava = ruleResolver.requireRule(guavaNode.getBuildTarget());
ProjectConfig projectConfigForExportLibrary = (ProjectConfig) ruleResolver.requireRule(projectConfigForExportLibraryNode.getBuildTarget());
ProjectConfig projectConfigForLibrary = (ProjectConfig) ruleResolver.requireRule(projectConfigForLibraryNode.getBuildTarget());
ProjectConfig projectConfigForResource = (ProjectConfig) ruleResolver.requireRule(projectConfigForResourceNode.getBuildTarget());
ProjectConfig projectConfigUsingNoDx = (ProjectConfig) ruleResolver.requireRule(projectConfigUsingNoDxNode.getBuildTarget());
ProjectConfig projectConfig = (ProjectConfig) ruleResolver.requireRule(projectConfigNode.getBuildTarget());
return new Pair<>(getModulesForActionGraph(ruleResolver, ImmutableSortedSet.of(projectConfigForExportLibrary, projectConfigForLibrary, projectConfigForResource, projectConfigUsingNoDx, projectConfig), javaPackageFinder, null), ruleResolver);
}
Aggregations