コード例 #1
0
ファイル: ExportFileTest.java プロジェクト: rlxrlxrlx/buck
  @Test
  public void modifyingTheContentsOfTheFileChangesTheRuleKey() throws IOException {
    Path root = Files.createTempDirectory("root");
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem(root.toFile());
    Path temp = Paths.get("example_file");

    FileHashCache hashCache = new DefaultFileHashCache(filesystem);
    SourcePathResolver resolver = new SourcePathResolver(new BuildRuleResolver());
    RuleKeyBuilderFactory ruleKeyFactory = new DefaultRuleKeyBuilderFactory(hashCache, resolver);

    filesystem.writeContentsToPath("I like cheese", temp);

    ExportFileBuilder builder =
        ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//some:file"))
            .setSrc(new PathSourcePath(filesystem, temp));

    ExportFile rule = (ExportFile) builder.build(new BuildRuleResolver(), filesystem);

    RuleKey original = ruleKeyFactory.newInstance(rule).build();

    filesystem.writeContentsToPath("I really like cheese", temp);

    // Create a new rule. The FileHashCache held by the existing rule will retain a reference to the
    // previous content of the file, so we need to create an identical rule.
    rule = (ExportFile) builder.build(new BuildRuleResolver(), filesystem);

    hashCache = new DefaultFileHashCache(filesystem);
    resolver = new SourcePathResolver(new BuildRuleResolver());
    ruleKeyFactory = new DefaultRuleKeyBuilderFactory(hashCache, resolver);
    RuleKey refreshed = ruleKeyFactory.newInstance(rule).build();

    assertNotEquals(original, refreshed);
  }
コード例 #2
0
 @Override
 public void writeLinesToPath(Iterable<String> lines, Path path, FileAttribute<?>... attrs)
     throws IOException {
   StringBuilder builder = new StringBuilder();
   if (!Iterables.isEmpty(lines)) {
     Joiner.on('\n').appendTo(builder, lines);
     builder.append('\n');
   }
   writeContentsToPath(builder.toString(), path, attrs);
 }
コード例 #3
0
ファイル: RuleKeyTest.java プロジェクト: JoeHorn/buck
  /** Ensure that build rules with the same inputs but different deps have unique RuleKeys. */
  @Test
  public void testRuleKeyDependsOnDeps() throws Exception {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    FileHashCache hashCache = new DefaultFileHashCache(filesystem);
    BuildRuleResolver ruleResolver1 =
        new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer());
    BuildRuleResolver ruleResolver2 =
        new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer());
    RuleKeyBuilderFactory ruleKeyBuilderFactory1 =
        new DefaultRuleKeyBuilderFactory(hashCache, new SourcePathResolver(ruleResolver1));
    RuleKeyBuilderFactory ruleKeyBuilderFactory2 =
        new DefaultRuleKeyBuilderFactory(hashCache, new SourcePathResolver(ruleResolver2));

    // Create a dependent build rule, //src/com/facebook/buck/cli:common.
    JavaLibraryBuilder builder =
        JavaLibraryBuilder.createBuilder(
            BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:common"));
    BuildRule commonJavaLibrary = builder.build(ruleResolver1);
    builder.build(ruleResolver2);

    // Create a java_library() rule with no deps.
    Path mainSrc = Paths.get("src/com/facebook/buck/cli/Main.java");
    filesystem.mkdirs(mainSrc.getParent());
    filesystem.writeContentsToPath("hello", mainSrc);
    JavaLibraryBuilder javaLibraryBuilder =
        JavaLibraryBuilder.createBuilder(
                BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:cli"))
            .addSrc(mainSrc);
    BuildRule libraryNoCommon = javaLibraryBuilder.build(ruleResolver1, filesystem);

    // Create the same java_library() rule, but with a dep on //src/com/facebook/buck/cli:common.
    javaLibraryBuilder.addDep(commonJavaLibrary.getBuildTarget());
    BuildRule libraryWithCommon = javaLibraryBuilder.build(ruleResolver2, filesystem);

    // Assert that the RuleKeys are distinct.
    RuleKey r1 = ruleKeyBuilderFactory1.build(libraryNoCommon);
    RuleKey r2 = ruleKeyBuilderFactory2.build(libraryWithCommon);
    assertThat(
        "Rule keys should be distinct because the deps of the rules are different.",
        r1,
        not(equalTo(r2)));
  }
コード例 #4
0
 @Override
 public void copyFile(Path source, Path target) throws IOException {
   writeContentsToPath(readFileIfItExists(source).get(), target);
 }