@Test public void testThatOriginalBuildParamsDepsDoNotPropagateToArchive() { SourcePathResolver pathResolver = new SourcePathResolver( new BuildRuleResolver( TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())); // Create an `Archive` rule using build params with an existing dependency, // as if coming from a `TargetNode` which had declared deps. These should *not* // propagate to the `Archive` rule, since it only cares about dependencies generating // it's immediate inputs. BuildRule dep = new FakeBuildRule(new FakeBuildRuleParamsBuilder("//:fake").build(), pathResolver); BuildTarget target = BuildTargetFactory.newInstance("//:archive"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dummy")) .setDeclaredDeps(ImmutableSortedSet.of(dep)) .build(); Archive archive = Archive.from( target, params, pathResolver, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS); // Verify that the archive rules dependencies are empty. assertEquals(archive.getDeps(), ImmutableSortedSet.<BuildRule>of()); }
@Test public void flagsArePropagated() throws Exception { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build(); Archive archive = Archive.from( target, params, new SourcePathResolver(resolver), DEFAULT_ARCHIVER, ImmutableList.of("-foo"), DEFAULT_RANLIB, ImmutableList.of("-bar"), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"))); ImmutableList<Step> steps = archive.getBuildSteps(FakeBuildContext.NOOP_CONTEXT, new FakeBuildableContext()); Step archiveStep = FluentIterable.from(steps).filter(ArchiveStep.class).first().get(); assertThat( archiveStep.getDescription(TestExecutionContext.newInstance()), containsString("-foo")); Step ranlibStep = FluentIterable.from(steps).filter(RanlibStep.class).first().get(); assertThat( ranlibStep.getDescription(TestExecutionContext.newInstance()), containsString("-bar")); }
@Test public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build(); // Create a couple of genrules to generate inputs for an archive rule. Genrule genrule1 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")) .setOut("foo/bar.o") .build(resolver); Genrule genrule2 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")) .setOut("foo/test.o") .build(resolver); // Build the archive using a normal input the outputs of the genrules above. Archive archive = Archive.from( target, params, new SourcePathResolver(resolver), DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of( new FakeSourcePath("simple.o"), new BuildTargetSourcePath(genrule1.getBuildTarget()), new BuildTargetSourcePath(genrule2.getBuildTarget()))); // Verify that the archive dependencies include the genrules providing the // SourcePath inputs. assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps()); }
@Test public void testThatInputChangesCauseRuleKeyChanges() { SourcePathResolver pathResolver = new SourcePathResolver( new BuildRuleResolver( TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build(); FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings( ImmutableMap.<String, String>builder() .put(AR.toString(), Strings.repeat("0", 40)) .put(RANLIB.toString(), Strings.repeat("1", 40)) .put("a.o", Strings.repeat("a", 40)) .put("b.o", Strings.repeat("b", 40)) .put("c.o", Strings.repeat("c", 40)) .put(Paths.get("different").toString(), Strings.repeat("d", 40)) .build()); // Generate a rule key for the defaults. RuleKey defaultRuleKey = new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver) .build( Archive.from( target, params, pathResolver, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS)); // Verify that changing the archiver causes a rulekey change. RuleKey archiverChange = new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver) .build( Archive.from( target, params, pathResolver, new GnuArchiver(new HashedFileTool(Paths.get("different"))), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS)); assertNotEquals(defaultRuleKey, archiverChange); // Verify that changing the output path causes a rulekey change. RuleKey outputChange = new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver) .build( Archive.from( target, params, pathResolver, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, Paths.get("different"), DEFAULT_INPUTS)); assertNotEquals(defaultRuleKey, outputChange); // Verify that changing the inputs causes a rulekey change. RuleKey inputChange = new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver) .build( Archive.from( target, params, pathResolver, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("different")))); assertNotEquals(defaultRuleKey, inputChange); // Verify that changing the type of archiver causes a rulekey change. RuleKey archiverTypeChange = new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver) .build( Archive.from( target, params, pathResolver, new BsdArchiver(new HashedFileTool(AR)), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS)); assertNotEquals(defaultRuleKey, archiverTypeChange); }