Search in sources :

Example 51 with PathSourcePath

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)));
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 52 with PathSourcePath

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));
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 53 with PathSourcePath

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))));
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 54 with PathSourcePath

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));
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 55 with PathSourcePath

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())));
    }
}
Also used : OptionalCompat(com.facebook.buck.util.OptionalCompat) ProvidesLinkedBinaryDeps(com.facebook.buck.cxx.ProvidesLinkedBinaryDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleDescription(com.facebook.buck.shell.AbstractGenruleDescription) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) FlavorDomain(com.facebook.buck.model.FlavorDomain) CxxCompilationDatabase(com.facebook.buck.cxx.CxxCompilationDatabase) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourceList(com.facebook.buck.rules.coercer.SourceList) StripStyle(com.facebook.buck.cxx.StripStyle) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) BuildRules(com.facebook.buck.rules.BuildRules) FrameworkDependencies(com.facebook.buck.cxx.FrameworkDependencies) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) Sets(com.google.common.collect.Sets) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) CxxBinaryDescription(com.facebook.buck.cxx.CxxBinaryDescription) Joiner(com.google.common.base.Joiner) CxxStrip(com.facebook.buck.cxx.CxxStrip) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) HashSet(java.util.HashSet) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) MorePaths(com.facebook.buck.io.MorePaths) Ordering(com.google.common.collect.Ordering) BuildRuleWithBinary(com.facebook.buck.cxx.BuildRuleWithBinary) Paths(java.nio.file.Paths) SWIFT_EXTENSION(com.facebook.buck.swift.SwiftDescriptions.SWIFT_EXTENSION) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14