Search in sources :

Example 66 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class DefaultJavaLibraryTest method testInputBasedRuleKeyWithJavaLibraryDep.

/**
   * Tests that input-based rule keys work properly with simple Java library deps.
   */
@Test
public void testInputBasedRuleKeyWithJavaLibraryDep() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    // Setup a Java library which builds against another Java library dep.
    TargetNode<JavaLibraryDescription.Arg, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).addSrc(Paths.get("Source.java")).build();
    TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib"), filesystem).addDep(depNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    JavaLibrary dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    JavaLibrary library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    filesystem.writeContentsToPath("JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
    writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "ABI JAR contents");
    FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
    RuleKey originalRuleKey = factory.build(library);
    // Now change the Java library dependency such that its rule key changes, and change its JAR
    // contents, but keep its ABI JAR the same.  This should *not* affect the input-based rule key
    // of the consuming java library, since it only cares about the contents of the ABI JAR.
    depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("Source.java")).setResourcesRoot(Paths.get("some root that changes the rule key")).build();
    targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    filesystem.writeContentsToPath("different JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
    FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
    RuleKey unaffectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
    // Now actually change the Java library dependency's ABI JAR.  This *should* affect the
    // input-based rule key of the consuming java library.
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "changed ABI JAR contents");
    FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
    RuleKey affectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) 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) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 67 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class DefaultJavaLibraryTest method testInputBasedRuleKeySourceChange.

/**
   * Tests that input-based rule keys work properly with generated sources.
   */
@Test
public void testInputBasedRuleKeySourceChange() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    // Setup a Java library consuming a source generated by a genrule and grab its rule key.
    BuildRule genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something").build(ruleResolver, filesystem);
    filesystem.writeContentsToPath("class Test {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
    JavaLibrary library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
    RuleKey originalRuleKey = factory.build(library);
    // Now change the genrule such that its rule key changes, but it's output stays the same (since
    // we don't change it).  This should *not* affect the input-based rule key of the consuming
    // java library, since it only cares about the contents of the source.
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
    library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
    RuleKey unaffectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
    // Now actually modify the source, which should make the input-based rule key change.
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
    filesystem.writeContentsToPath("class Test2 {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
    library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
    RuleKey affectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) 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) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 68 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class TestCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    LOG.debug("Running with arguments %s", getArguments());
    try (CommandThreadManager pool = new CommandThreadManager("Test", getConcurrencyLimit(params.getBuckConfig()))) {
        // Post the build started event, setting it to the Parser recorded start time if appropriate.
        BuildEvent.Started started = BuildEvent.started(getArguments());
        if (params.getParser().getParseStartTime().isPresent()) {
            params.getBuckEventBus().post(started, params.getParser().getParseStartTime().get());
        } else {
            params.getBuckEventBus().post(started);
        }
        // The first step is to parse all of the build files. This will populate the parser and find
        // all of the test rules.
        TargetGraphAndBuildTargets targetGraphAndBuildTargets;
        ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
        try {
            // If the user asked to run all of the tests, parse all of the build files looking for any
            // test rules.
            boolean ignoreBuckAutodepsFiles = false;
            if (isRunAllTests()) {
                targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), ImmutableList.of(TargetNodePredicateSpec.of(input -> Description.getBuildRuleType(input.getDescription()).isTestRule(), BuildFileSpec.fromRecursivePath(Paths.get(""), params.getCell().getRoot()))), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
                targetGraphAndBuildTargets = targetGraphAndBuildTargets.withBuildTargets(ImmutableSet.of());
            // Otherwise, the user specified specific test targets to build and run, so build a graph
            // around these.
            } else {
                LOG.debug("Parsing graph for arguments %s", getArguments());
                targetGraphAndBuildTargets = params.getParser().buildTargetGraphForTargetNodeSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()), ignoreBuckAutodepsFiles, parserConfig.getDefaultFlavorsMode());
                LOG.debug("Got explicit build targets %s", targetGraphAndBuildTargets.getBuildTargets());
                ImmutableSet.Builder<BuildTarget> testTargetsBuilder = ImmutableSet.builder();
                for (TargetNode<?, ?> node : targetGraphAndBuildTargets.getTargetGraph().getAll(targetGraphAndBuildTargets.getBuildTargets())) {
                    ImmutableSortedSet<BuildTarget> nodeTests = TargetNodes.getTestTargetsForNode(node);
                    if (!nodeTests.isEmpty()) {
                        LOG.debug("Got tests for target %s: %s", node.getBuildTarget(), nodeTests);
                        testTargetsBuilder.addAll(nodeTests);
                    }
                }
                ImmutableSet<BuildTarget> testTargets = testTargetsBuilder.build();
                if (!testTargets.isEmpty()) {
                    LOG.debug("Got related test targets %s, building new target graph...", testTargets);
                    TargetGraph targetGraph = params.getParser().buildTargetGraph(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), Iterables.concat(targetGraphAndBuildTargets.getBuildTargets(), testTargets));
                    LOG.debug("Finished building new target graph with tests.");
                    targetGraphAndBuildTargets = targetGraphAndBuildTargets.withTargetGraph(targetGraph);
                }
            }
            if (params.getBuckConfig().getBuildVersions()) {
                targetGraphAndBuildTargets = toVersionedTargetGraph(params, targetGraphAndBuildTargets);
            }
        } catch (BuildTargetException | BuildFileParseException | VersionException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        ActionGraphAndResolver actionGraphAndResolver = Preconditions.checkNotNull(params.getActionGraphCache().getActionGraph(params.getBuckEventBus(), params.getBuckConfig().isActionGraphCheckingEnabled(), params.getBuckConfig().isSkipActionGraphCache(), targetGraphAndBuildTargets.getTargetGraph(), params.getBuckConfig().getKeySeed()));
        // Look up all of the test rules in the action graph.
        Iterable<TestRule> testRules = Iterables.filter(actionGraphAndResolver.getActionGraph().getNodes(), TestRule.class);
        // the build.
        if (!isBuildFiltered(params.getBuckConfig())) {
            testRules = filterTestRules(params.getBuckConfig(), targetGraphAndBuildTargets.getBuildTargets(), testRules);
        }
        CachingBuildEngineBuckConfig cachingBuildEngineBuckConfig = params.getBuckConfig().getView(CachingBuildEngineBuckConfig.class);
        try (CommandThreadManager artifactFetchService = getArtifactFetchService(params.getBuckConfig(), pool.getExecutor());
            RuleKeyCacheScope<RuleKey> ruleKeyCacheScope = getDefaultRuleKeyCacheScope(params, new RuleKeyCacheRecycler.SettingsAffectingCache(params.getBuckConfig().getKeySeed(), actionGraphAndResolver.getActionGraph()))) {
            LocalCachingBuildEngineDelegate localCachingBuildEngineDelegate = new LocalCachingBuildEngineDelegate(params.getFileHashCache());
            CachingBuildEngine cachingBuildEngine = new CachingBuildEngine(new LocalCachingBuildEngineDelegate(params.getFileHashCache()), pool.getExecutor(), artifactFetchService == null ? pool.getExecutor() : artifactFetchService.getExecutor(), new DefaultStepRunner(), getBuildEngineMode().orElse(cachingBuildEngineBuckConfig.getBuildEngineMode()), cachingBuildEngineBuckConfig.getBuildDepFiles(), cachingBuildEngineBuckConfig.getBuildMaxDepFileCacheEntries(), cachingBuildEngineBuckConfig.getBuildArtifactCacheSizeLimit(), params.getObjectMapper(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getResourceAwareSchedulingInfo(), new RuleKeyFactoryManager(params.getBuckConfig().getKeySeed(), fs -> localCachingBuildEngineDelegate.getFileHashCache(), actionGraphAndResolver.getResolver(), cachingBuildEngineBuckConfig.getBuildInputRuleKeyFileSizeLimit(), ruleKeyCacheScope.getCache()));
            try (Build build = createBuild(params.getBuckConfig(), actionGraphAndResolver.getActionGraph(), actionGraphAndResolver.getResolver(), params.getCell(), params.getAndroidPlatformTargetSupplier(), cachingBuildEngine, params.getArtifactCacheFactory().newInstance(), params.getConsole(), params.getBuckEventBus(), getTargetDeviceOptional(), params.getPersistentWorkerPools(), params.getPlatform(), params.getEnvironment(), params.getObjectMapper(), params.getClock(), Optional.of(getAdbOptions(params.getBuckConfig())), Optional.of(getTargetDeviceOptions()), params.getExecutors())) {
                // Build all of the test rules.
                int exitCode = build.executeAndPrintFailuresToEventBus(RichStream.from(testRules).map(TestRule::getBuildTarget).collect(MoreCollectors.toImmutableList()), isKeepGoing(), params.getBuckEventBus(), params.getConsole(), getPathToBuildReport(params.getBuckConfig()));
                params.getBuckEventBus().post(BuildEvent.finished(started, exitCode));
                if (exitCode != 0) {
                    return exitCode;
                }
                // the filtering here, after we've done the build but before we run the tests.
                if (isBuildFiltered(params.getBuckConfig())) {
                    testRules = filterTestRules(params.getBuckConfig(), targetGraphAndBuildTargets.getBuildTargets(), testRules);
                }
                // Once all of the rules are built, then run the tests.
                Optional<ImmutableList<String>> externalTestRunner = params.getBuckConfig().getExternalTestRunner();
                if (externalTestRunner.isPresent()) {
                    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(actionGraphAndResolver.getResolver()));
                    return runTestsExternal(params, build, externalTestRunner.get(), testRules, pathResolver);
                }
                return runTestsInternal(params, cachingBuildEngine, build, testRules);
            }
        }
    }
}
Also used : TargetNodePredicateSpec(com.facebook.buck.parser.TargetNodePredicateSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) RichStream(com.facebook.buck.util.RichStream) AdbOptions(com.facebook.buck.step.AdbOptions) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) Map(java.util.Map) ConcurrencyLimit(com.facebook.buck.util.concurrent.ConcurrencyLimit) TestRule(com.facebook.buck.rules.TestRule) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildTargetException(com.facebook.buck.model.BuildTargetException) Set(java.util.Set) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) Option(org.kohsuke.args4j.Option) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Collectors(java.util.stream.Collectors) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) List(java.util.List) ForwardingProcessListener(com.facebook.buck.util.ForwardingProcessListener) ExternalTestRunnerTestSpec(com.facebook.buck.rules.ExternalTestRunnerTestSpec) Optional(java.util.Optional) Description(com.facebook.buck.rules.Description) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) ExternalTestRunnerRule(com.facebook.buck.rules.ExternalTestRunnerRule) Iterables(com.google.common.collect.Iterables) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) Build(com.facebook.buck.command.Build) VersionException(com.facebook.buck.versions.VersionException) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) MoreExceptions(com.facebook.buck.util.MoreExceptions) HashMap(java.util.HashMap) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Lists(com.google.common.collect.Lists) ParserConfig(com.facebook.buck.parser.ParserConfig) Label(com.facebook.buck.rules.Label) ImmutableList(com.google.common.collect.ImmutableList) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) PrintStream(java.io.PrintStream) Logger(com.facebook.buck.log.Logger) RuleKeyCacheScope(com.facebook.buck.rules.keys.RuleKeyCacheScope) BuildFileSpec(com.facebook.buck.parser.BuildFileSpec) Files(java.nio.file.Files) TargetNode(com.facebook.buck.rules.TargetNode) Channels(java.nio.channels.Channels) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) TargetDevice(com.facebook.buck.step.TargetDevice) ExecutionException(java.util.concurrent.ExecutionException) BuildEvent(com.facebook.buck.rules.BuildEvent) CoverageReportFormat(com.facebook.buck.test.CoverageReportFormat) Paths(java.nio.file.Paths) BuildEngine(com.facebook.buck.rules.BuildEngine) Preconditions(com.google.common.base.Preconditions) TargetNodes(com.facebook.buck.rules.TargetNodes) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) Comparator(java.util.Comparator) ImmutableList(com.google.common.collect.ImmutableList) TargetGraph(com.facebook.buck.rules.TargetGraph) RuleKeyFactoryManager(com.facebook.buck.rules.keys.RuleKeyFactoryManager) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) BuildTargetException(com.facebook.buck.model.BuildTargetException) LocalCachingBuildEngineDelegate(com.facebook.buck.rules.LocalCachingBuildEngineDelegate) RuleKey(com.facebook.buck.rules.RuleKey) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) TestRule(com.facebook.buck.rules.TestRule) BuildEvent(com.facebook.buck.rules.BuildEvent) RuleKeyCacheRecycler(com.facebook.buck.rules.keys.RuleKeyCacheRecycler) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) ParserConfig(com.facebook.buck.parser.ParserConfig) VersionException(com.facebook.buck.versions.VersionException) CachingBuildEngineBuckConfig(com.facebook.buck.rules.CachingBuildEngineBuckConfig)

Example 69 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class TestRuleKeyFileHelper method isRuleKeyInDir.

/**
   * Checks if a matching rule key file for a test is present in its directoryReturns
   * @return true if a rule key is written in the specified directory.
   */
public boolean isRuleKeyInDir(TestRule testRule) throws IOException {
    ProjectFilesystem filesystem = ((BuildRule) testRule).getProjectFilesystem();
    Path ruleKeyPath = filesystem.resolve(getRuleKeyFilePath(testRule));
    if (!Files.isRegularFile(ruleKeyPath)) {
        return false;
    }
    RuleKey ruleKey = buildEngine.getRuleKey(testRule.getBuildTarget());
    try (BufferedReader reader = Files.newBufferedReader(ruleKeyPath, UTF_8)) {
        return reader.readLine().equals(ruleKey.toString());
    }
}
Also used : Path(java.nio.file.Path) RuleKey(com.facebook.buck.rules.RuleKey) BufferedReader(java.io.BufferedReader) BuildRule(com.facebook.buck.rules.BuildRule) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 70 with RuleKey

use of com.facebook.buck.rules.RuleKey in project buck by facebook.

the class AaptPackageResourcesTest method testThatChangingFilteredResourcesProviderChangesRuleKey.

@Test
public void testThatChangingFilteredResourcesProviderChangesRuleKey() {
    // Generate a rule key for the defaults.
    AaptConstructorArgs args = new AaptConstructorArgs();
    RuleKey previousRuleKey = calculateRuleKey(args);
    args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
    args.filteredResourcesProvider = new IdentityResourcesProvider(ImmutableList.of(Paths.get("res1"), Paths.get("res2")));
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
    args.filteredResourcesProvider = new ResourcesFilter(params.withBuildTarget(params.getBuildTarget().withFlavors(InternalFlavor.of("filter"))).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(resource1, resource2)), Suppliers.ofInstance(ImmutableSortedSet.of())), ImmutableList.of(resource1.getRes(), resource2.getRes()), ImmutableSet.of(), ImmutableSet.of(), ResourcesFilter.ResourceCompressionMode.DISABLED, FilterResourcesStep.ResourceFilter.EMPTY_FILTER);
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
    args.filteredResourcesProvider = new ResourcesFilter(params.withBuildTarget(params.getBuildTarget().withFlavors(InternalFlavor.of("filter"))).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(resource1, resource2)), Suppliers.ofInstance(ImmutableSortedSet.of())), ImmutableList.of(resource1.getRes(), resource2.getRes()), ImmutableSet.of(), ImmutableSet.of("some_locale"), ResourcesFilter.ResourceCompressionMode.DISABLED, FilterResourcesStep.ResourceFilter.EMPTY_FILTER);
    previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) Test(org.junit.Test)

Aggregations

RuleKey (com.facebook.buck.rules.RuleKey)149 Test (org.junit.Test)112 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)71 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)71 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)71 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)57 Path (java.nio.file.Path)57 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)42 BuildTarget (com.facebook.buck.model.BuildTarget)42 BuildRule (com.facebook.buck.rules.BuildRule)42 LazyPath (com.facebook.buck.io.LazyPath)34 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)34 PathSourcePath (com.facebook.buck.rules.PathSourcePath)33 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)30 SourcePath (com.facebook.buck.rules.SourcePath)28 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)27 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)25 IOException (java.io.IOException)25 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)23