use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class CxxLibraryDescriptionTest method headersFromCxxGenrule.
@Test
public void headersFromCxxGenrule() throws Exception {
CxxGenruleBuilder srcBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:src")).setOut("foo.h");
CxxLibraryBuilder libraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.cpp")))).setHeaders(ImmutableSortedSet.of(new DefaultBuildTargetSourcePath(srcBuilder.getTarget())));
TargetGraph targetGraph = TargetGraphFactory.newInstance(srcBuilder.build(), libraryBuilder.build());
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.requireRule(libraryBuilder.getTarget().withAppendedFlavors(CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor(), CxxLibraryDescription.Type.STATIC.getFlavor()));
verifySourcePaths(ruleResolver);
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class JsLibraryDescriptionTest method buildTargetWithSubpathPair.
@Test
public void buildTargetWithSubpathPair() throws NoSuchBuildTargetException {
final String basePath = ".";
final BuildTarget target = BuildTargetFactory.newInstance("//:node_modules");
scenarioBuilder.arbitraryRule(target);
final JsTestScenario scenario = buildScenario(basePath, new Pair<>(new DefaultBuildTargetSourcePath(target), "node_modules/left-pad/index.js"));
assertEquals("arbitrary/path/node_modules/left-pad/index.js", findFileRule(scenario.resolver).getVirtualPath().get());
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class JsLibraryDescriptionTest method relativeBasePathReplacesBuildTargetSourcePath.
@Test
public void relativeBasePathReplacesBuildTargetSourcePath() throws NoSuchBuildTargetException {
final String basePath = "../path.js";
final BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
scenarioBuilder.arbitraryRule(target);
final JsTestScenario scenario = buildScenario(basePath, new DefaultBuildTargetSourcePath(target));
assertEquals("arbitrary/path.js", findFileRule(scenario.resolver).getVirtualPath().get());
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class CalculateAbiTest method inputRuleKeyDoesNotChangeIfGeneratedBinaryJarDoesNotChange.
@Test
public void inputRuleKeyDoesNotChangeIfGeneratedBinaryJarDoesNotChange() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup the initial java library.
Path input = Paths.get("input.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:library");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(new PathSourcePath(filesystem, input));
DefaultJavaLibrary javaLibrary = builder.build(resolver, filesystem);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("stuff", input);
filesystem.writeContentsToPath("stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
BuildTarget target = BuildTargetFactory.newInstance("//:library-abi");
CalculateAbi calculateAbi = CalculateAbi.of(target, ruleFinder, builder.createBuildRuleParams(resolver, filesystem), new DefaultBuildTargetSourcePath(javaLibraryTarget));
FileHashCache initialHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory initialRuleKeyFactory = new DefaultRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder);
RuleKey initialKey = initialRuleKeyFactory.build(calculateAbi);
RuleKey initialInputKey = new InputBasedRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder).build(calculateAbi);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("new stuff", input);
// Re-setup some entities to drop internal rule key caching.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
builder.build(resolver, filesystem);
FileHashCache alteredHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory alteredRuleKeyFactory = new DefaultRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder);
RuleKey alteredKey = alteredRuleKeyFactory.build(calculateAbi);
RuleKey alteredInputKey = new InputBasedRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder).build(calculateAbi);
assertThat(initialKey, Matchers.not(Matchers.equalTo(alteredKey)));
assertThat(initialInputKey, Matchers.equalTo(alteredInputKey));
}
use of com.facebook.buck.rules.DefaultBuildTargetSourcePath in project buck by facebook.
the class CalculateAbiTest method ruleKeysChangeIfGeneratedBinaryJarChanges.
@Test
public void ruleKeysChangeIfGeneratedBinaryJarChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup the initial java library.
Path input = Paths.get("input.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:library");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(new PathSourcePath(filesystem, input));
DefaultJavaLibrary javaLibrary = builder.build(resolver, filesystem);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("stuff", input);
filesystem.writeContentsToPath("stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
BuildTarget target = BuildTargetFactory.newInstance("//:library-abi");
CalculateAbi calculateAbi = CalculateAbi.of(target, ruleFinder, builder.createBuildRuleParams(resolver, filesystem), new DefaultBuildTargetSourcePath(javaLibraryTarget));
FileHashCache initialHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory initialRuleKeyFactory = new DefaultRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder);
RuleKey initialKey = initialRuleKeyFactory.build(calculateAbi);
RuleKey initialInputKey = new InputBasedRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder).build(calculateAbi);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("new stuff", input);
filesystem.writeContentsToPath("new stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
// Re-setup some entities to drop internal rule key caching.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
builder.build(resolver, filesystem);
FileHashCache alteredHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory alteredRuleKeyFactory = new DefaultRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder);
RuleKey alteredKey = alteredRuleKeyFactory.build(calculateAbi);
RuleKey alteredInputKey = new InputBasedRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder).build(calculateAbi);
assertThat(initialKey, Matchers.not(Matchers.equalTo(alteredKey)));
assertThat(initialInputKey, Matchers.not(Matchers.equalTo(alteredInputKey)));
}
Aggregations