Search in sources :

Example 56 with DefaultBuildTargetSourcePath

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

the class DependencyFileRuleKeyFactoryTest method testKeysWhenInputTargetOutputChanges.

@Test
public void testKeysWhenInputTargetOutputChanges() throws Exception {
    BuildRuleResolver ruleResolver = newRuleResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget usedTarget = BuildTargetFactory.newInstance("//:used");
    BuildTarget unusedTarget = BuildTargetFactory.newInstance("//:unused");
    BuildTarget noncoveredTarget = BuildTargetFactory.newInstance("//:noncovered");
    BuildTarget interestingTarget = BuildTargetFactory.newInstance("//:interesting");
    SourcePath usedSourcePath = new DefaultBuildTargetSourcePath(usedTarget);
    SourcePath unusedSourcePath = new DefaultBuildTargetSourcePath(unusedTarget);
    SourcePath noncoveredSourcePath = new DefaultBuildTargetSourcePath(noncoveredTarget);
    SourcePath interestingSourcePath = new DefaultBuildTargetSourcePath(interestingTarget);
    ruleResolver.addToIndex(new FakeBuildRule(usedTarget, pathResolver).setOutputFile("used"));
    ruleResolver.addToIndex(new FakeBuildRule(unusedTarget, pathResolver).setOutputFile("unused"));
    ruleResolver.addToIndex(new FakeBuildRule(noncoveredTarget, pathResolver).setOutputFile("nc"));
    ruleResolver.addToIndex(new FakeBuildRule(interestingTarget, pathResolver).setOutputFile("in"));
    testKeysWhenInputContentsChanges(ruleFinder, pathResolver, usedSourcePath, unusedSourcePath, noncoveredSourcePath, interestingSourcePath, pathResolver.getAbsolutePath(usedSourcePath), pathResolver.getAbsolutePath(unusedSourcePath), pathResolver.getAbsolutePath(noncoveredSourcePath), pathResolver.getAbsolutePath(interestingSourcePath), DependencyFileEntry.fromSourcePath(usedSourcePath, pathResolver));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 57 with DefaultBuildTargetSourcePath

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

the class RustBinaryDescriptionTest method testGeneratedSourceFromCxxGenrule.

@Test
public void testGeneratedSourceFromCxxGenrule() throws NoSuchBuildTargetException {
    CxxGenruleBuilder srcBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:src")).setOut("main.rs");
    RustBinaryBuilder binaryBuilder = RustBinaryBuilder.from("//:bin").setSrcs(ImmutableSortedSet.of(new DefaultBuildTargetSourcePath(srcBuilder.getTarget())));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(srcBuilder.build(), binaryBuilder.build());
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleResolver.requireRule(binaryBuilder.getTarget());
}
Also used : CxxGenruleBuilder(com.facebook.buck.cxx.CxxGenruleBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 58 with DefaultBuildTargetSourcePath

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

the class AbstractRuleKeyHasherTest method testConsistency.

@Test
public void testConsistency() {
    // same sequence of operations should produce the same hash
    assertEquals(newHasher().hash(), newHasher().hash());
    assertEquals(newHasher().putKey("abc").hash(), newHasher().putKey("abc").hash());
    assertEquals(newHasher().putNull().hash(), newHasher().putNull().hash());
    assertEquals(newHasher().putBoolean(false).hash(), newHasher().putBoolean(false).hash());
    assertEquals(newHasher().putBoolean(true).hash(), newHasher().putBoolean(true).hash());
    assertEquals(newHasher().putNumber(4).hash(), newHasher().putNumber(4).hash());
    assertEquals(newHasher().putNumber((long) 4).hash(), newHasher().putNumber((long) 4).hash());
    assertEquals(newHasher().putNumber((short) 4).hash(), newHasher().putNumber((short) 4).hash());
    assertEquals(newHasher().putNumber((byte) 4).hash(), newHasher().putNumber((byte) 4).hash());
    assertEquals(newHasher().putNumber((float) 4).hash(), newHasher().putNumber((float) 4).hash());
    assertEquals(newHasher().putNumber((double) 4).hash(), newHasher().putNumber((double) 4).hash());
    assertEquals(newHasher().putBytes(new byte[] { 42 }).hash(), newHasher().putBytes(new byte[] { 42 }).hash());
    assertEquals(newHasher().putPattern(Pattern.compile("42")).hash(), newHasher().putPattern(Pattern.compile("42")).hash());
    assertEquals(newHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash(), newHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash(), newHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newHasher().putNonHashingPath("42").hash(), newHasher().putNonHashingPath("42").hash());
    assertEquals(newHasher().putSourceRoot(new SourceRoot("42")).hash(), newHasher().putSourceRoot(new SourceRoot("42")).hash());
    assertEquals(newHasher().putRuleKey(RULE_KEY_1).hash(), newHasher().putRuleKey(RULE_KEY_1).hash());
    assertEquals(newHasher().putBuildRuleType(BuildRuleType.of("42")).hash(), newHasher().putBuildRuleType(BuildRuleType.of("42")).hash());
    assertEquals(newHasher().putBuildTarget(TARGET_1).hash(), newHasher().putBuildTarget(TARGET_1).hash());
    assertEquals(newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash(), newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash());
}
Also used : SourceRoot(com.facebook.buck.rules.SourceRoot) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 59 with DefaultBuildTargetSourcePath

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

the class CountingRuleKeyHasherTest method testCounting.

@Test
public void testCounting() {
    CountingRuleKeyHasher<HashCode> hasher = newCountHasher();
    int count = 0;
    assertEquals(count, hasher.getCount());
    hasher.putKey("");
    assertEquals(++count, hasher.getCount());
    hasher.putKey("42").putKey("43").putKey("44");
    assertEquals(count += 3, hasher.getCount());
    hasher.putNull();
    assertEquals(++count, hasher.getCount());
    hasher.putBoolean(true);
    assertEquals(++count, hasher.getCount());
    hasher.putBoolean(false).putBoolean(true);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber(0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber(42).putNumber(43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber((long) 0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber((long) 42).putNumber((long) 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber((short) 0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber((short) 42).putNumber((short) 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber((byte) 0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber((byte) 42).putNumber((byte) 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber((float) 0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber((float) 42).putNumber((float) 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putNumber((double) 0);
    assertEquals(++count, hasher.getCount());
    hasher.putNumber((double) 42).putNumber((double) 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putString("");
    assertEquals(++count, hasher.getCount());
    hasher.putString("42").putString("43");
    assertEquals(count += 2, hasher.getCount());
    hasher.putBytes(new byte[0]);
    assertEquals(++count, hasher.getCount());
    hasher.putBytes(new byte[] { 42 });
    assertEquals(++count, hasher.getCount());
    hasher.putBytes(new byte[] { 42, 42 }).putBytes(new byte[] { 43 });
    assertEquals(count += 2, hasher.getCount());
    hasher.putPattern(Pattern.compile(""));
    assertEquals(++count, hasher.getCount());
    hasher.putPattern(Pattern.compile("42")).putPattern(Pattern.compile("43"));
    assertEquals(count += 2, hasher.getCount());
    hasher.putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"));
    assertEquals(++count, hasher.getCount());
    hasher.putSha1(Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd")).putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"));
    assertEquals(count += 2, hasher.getCount());
    hasher.putPath(Paths.get(""), HashCode.fromInt(0));
    assertEquals(++count, hasher.getCount());
    hasher.putPath(Paths.get(""), HashCode.fromInt(42));
    assertEquals(++count, hasher.getCount());
    hasher.putPath(Paths.get("42"), HashCode.fromInt(0));
    assertEquals(++count, hasher.getCount());
    hasher.putPath(Paths.get("42"), HashCode.fromInt(42));
    assertEquals(++count, hasher.getCount());
    hasher.putPath(Paths.get("42/42"), HashCode.fromInt(42)).putPath(Paths.get("43"), HashCode.fromInt(43));
    assertEquals(count += 2, hasher.getCount());
    hasher.putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(0));
    assertEquals(++count, hasher.getCount());
    hasher.putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(42));
    assertEquals(++count, hasher.getCount());
    hasher.putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(0));
    assertEquals(++count, hasher.getCount());
    hasher.putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(42));
    assertEquals(++count, hasher.getCount());
    hasher.putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).putArchiveMemberPath(newArchiveMember("43/43", "43/43"), HashCode.fromInt(43));
    assertEquals(count += 2, hasher.getCount());
    hasher.putNonHashingPath("");
    assertEquals(++count, hasher.getCount());
    hasher.putNonHashingPath("42").putNonHashingPath("43");
    assertEquals(count += 2, hasher.getCount());
    hasher.putSourceRoot(new SourceRoot(""));
    assertEquals(++count, hasher.getCount());
    hasher.putSourceRoot(new SourceRoot("42")).putSourceRoot(new SourceRoot("43"));
    assertEquals(count += 2, hasher.getCount());
    hasher.putRuleKey(RULE_KEY_1);
    assertEquals(++count, hasher.getCount());
    hasher.putRuleKey(RULE_KEY_2).putRuleKey(RULE_KEY_1);
    assertEquals(count += 2, hasher.getCount());
    hasher.putBuildRuleType(BuildRuleType.of(""));
    assertEquals(++count, hasher.getCount());
    hasher.putBuildRuleType(BuildRuleType.of("42")).putBuildRuleType(BuildRuleType.of("43"));
    assertEquals(count += 2, hasher.getCount());
    hasher.putBuildTarget(TARGET_1);
    assertEquals(++count, hasher.getCount());
    hasher.putBuildTarget(TARGET_2).putBuildTarget(TARGET_1);
    assertEquals(count += 2, hasher.getCount());
    hasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1));
    assertEquals(++count, hasher.getCount());
    hasher.putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_2)).putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1));
    assertEquals(count += 2, hasher.getCount());
    hasher.putContainer(RuleKeyHasher.Container.LIST, 0);
    assertEquals(++count, hasher.getCount());
    hasher.putContainer(RuleKeyHasher.Container.LIST, 42).putContainer(RuleKeyHasher.Container.LIST, 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putContainer(RuleKeyHasher.Container.MAP, 0);
    assertEquals(++count, hasher.getCount());
    hasher.putContainer(RuleKeyHasher.Container.MAP, 42).putContainer(RuleKeyHasher.Container.MAP, 43);
    assertEquals(count += 2, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.OPTIONAL);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.APPENDABLE);
    assertEquals(++count, hasher.getCount());
    hasher.putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).putWrapper(RuleKeyHasher.Wrapper.OPTIONAL);
    assertEquals(count += 7, hasher.getCount());
    hasher.putKey("key").putContainer(RuleKeyHasher.Container.LIST, 3).putString("a").putNumber(1).putNull();
    assertEquals(count += 5, hasher.getCount());
}
Also used : HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) SourceRoot(com.facebook.buck.rules.SourceRoot) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 60 with DefaultBuildTargetSourcePath

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

the class SourceListTest method translatedNamedSourcesTargets.

@Test
public void translatedNamedSourcesTargets() {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildTarget newTarget = BuildTargetFactory.newInstance("//something:else");
    TargetNodeTranslator translator = new FixedTargetNodeTranslator(ImmutableMap.of(target, newTarget));
    assertThat(translator.translate(CELL_PATH_RESOLVER, PATTERN, SourceList.ofNamedSources(ImmutableSortedMap.of("name", new DefaultBuildTargetSourcePath(target)))), Matchers.equalTo(Optional.of(SourceList.ofNamedSources(ImmutableSortedMap.of("name", new DefaultBuildTargetSourcePath(newTarget))))));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNodeTranslator(com.facebook.buck.versions.TargetNodeTranslator) FixedTargetNodeTranslator(com.facebook.buck.versions.FixedTargetNodeTranslator) Test(org.junit.Test)

Aggregations

DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)71 Test (org.junit.Test)64 BuildTarget (com.facebook.buck.model.BuildTarget)53 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)26 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)25 SourcePath (com.facebook.buck.rules.SourcePath)25 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)21 TargetGraph (com.facebook.buck.rules.TargetGraph)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)18 Path (java.nio.file.Path)16 BuildRule (com.facebook.buck.rules.BuildRule)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)9 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)5