use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyExecutableMacro.
@Test
public void inputBasedRuleKeyExecutableMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(exe //:dep)").setOut("output");
// Create an initial input-based rule key
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something", Paths.get("dep.exe"));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey originalRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the dep's resource list, which will change its normal rule key, but since we're
// keeping its output the same, the input-based rule key for the consuming rule will stay the
// same. This is because the input-based rule key for the consuming rule only cares about the
// contents of the output this rule produces.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
Genrule extra = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:extra")).setOut("something").build(resolver);
new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).setDeps(ImmutableSortedSet.of(extra.getBuildTarget())).build(resolver, filesystem);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey unchangedRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey unchangedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(unchangedRuleKey, Matchers.not(Matchers.equalTo(originalRuleKey)));
assertThat(unchangedInputBasedRuleKey, Matchers.equalTo(originalInputRuleKey));
// Make a change to the dep's output, which *should* affect the input-based rule key.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey changedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(changedInputBasedRuleKey, Matchers.not(Matchers.equalTo(originalInputRuleKey)));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class SrcZipAwareFileBundlerTest method shouldBundleFilesAndKeepHierarchy.
@Test
public void shouldBundleFilesAndKeepHierarchy() throws IOException {
filesystem = new ProjectFilesystem(tmp.getRoot());
src = Paths.get("src");
dest = filesystem.getRootPath().resolve("dest");
subDirectoryFile1 = filesystem.getRootPath().resolve("src/subDir/file1");
subDirectoryFile2 = filesystem.getRootPath().resolve("src/file1");
subDirectoryFile3 = filesystem.getRootPath().resolve("src/subDires/file1");
bundleFiles(ImmutableSortedSet.of(new PathSourcePath(filesystem, src)));
List<Path> bundledFilesCollection = getBundledFilesCollection();
assertSame(bundledFilesCollection.size(), 3);
for (Path path : bundledFilesCollection) {
Path relativePath = dest.relativize(filesystem.getPathForRelativePath(path));
assertTrue(subDirectoryFile1.endsWith(relativePath) || subDirectoryFile2.endsWith(relativePath) || subDirectoryFile3.endsWith(relativePath));
}
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class SrcZipAwareFileBundlerTest method shouldThrowAnExceptionIfBundlerOverwritesFiles.
@Test(expected = HumanReadableException.class)
public void shouldThrowAnExceptionIfBundlerOverwritesFiles() throws IOException {
filesystem = new ProjectFilesystem(tmp.getRoot());
dest = filesystem.getRootPath().resolve("dest");
subDirectoryFile1 = filesystem.getRootPath().resolve("src1/subDir/file1");
subDirectoryFile2 = filesystem.getRootPath().resolve("src2/subDir/file1");
subDirectoryFile3 = filesystem.getRootPath().resolve("src1/subDir/file3");
bundleFiles(ImmutableSortedSet.of(new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile1)), new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile2)), new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile3))));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class SrcZipAwareFileBundlerTest method shouldBundleFilesAndKeepSrcFilesUnderBasePath.
@Test
public void shouldBundleFilesAndKeepSrcFilesUnderBasePath() throws IOException {
filesystem = new ProjectFilesystem(tmp.getRoot());
dest = filesystem.getRootPath().resolve("dest");
subDirectoryFile1 = filesystem.getRootPath().resolve("src1/subDir/file1");
subDirectoryFile2 = filesystem.getRootPath().resolve("src2/subDir/file2");
subDirectoryFile3 = filesystem.getRootPath().resolve("src1/subDir/file3");
bundleFiles(ImmutableSortedSet.of(new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile1)), new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile2)), new PathSourcePath(filesystem, filesystem.getRootPath().relativize(subDirectoryFile3))));
List<Path> bundledFilesCollection = getBundledFilesCollection();
assertSame(bundledFilesCollection.size(), 3);
for (Path path : bundledFilesCollection) {
Path relativePath = dest.relativize(filesystem.getPathForRelativePath(path));
assertTrue(subDirectoryFile1.getFileName().equals(relativePath) || subDirectoryFile2.getFileName().equals(relativePath) || subDirectoryFile3.getFileName().equals(relativePath));
}
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class AppleDescriptions method createBuildRulesForSceneKitAssetsDependencies.
public static Optional<SceneKitAssets> createBuildRulesForSceneKitAssetsDependencies(TargetGraph targetGraph, BuildRuleParams params, AppleCxxPlatform appleCxxPlatform) {
TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
ImmutableSet<AppleWrapperResourceArg> sceneKitAssetsArgs = AppleBuildRules.collectTransitiveBuildRules(targetGraph, Optional.empty(), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES, ImmutableList.of(targetNode));
BuildRuleParams sceneKitAssetsParams = params.withAppendedFlavor(SceneKitAssets.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
if (sceneKitAssetsArgs.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(new SceneKitAssets(sceneKitAssetsParams, appleCxxPlatform, sceneKitAssetsArgs.stream().map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)).collect(MoreCollectors.toImmutableSet())));
}
}
Aggregations