예제 #1
0
  @Test
  public void testArgsWithLocationMacroAffectDependenciesAndExpands() throws Exception {
    BuildRuleResolver resolver =
        new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(resolver);

    BuildRule shBinaryRule =
        new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe"))
            .setMain(new FakeSourcePath("bin/exe"))
            .build(resolver);

    BuildRule exportFileRule =
        ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:file"))
            .setSrc(new FakeSourcePath("file.txt"))
            .build(resolver);

    WorkerToolBuilder workerToolBuilder =
        WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule"))
            .setExe(shBinaryRule.getBuildTarget())
            .setArgs("--input $(location //:file)");
    WorkerTool workerTool = (WorkerTool) workerToolBuilder.build(resolver);

    assertThat(
        workerToolBuilder.findImplicitDeps(), Matchers.hasItem(exportFileRule.getBuildTarget()));
    assertThat(workerTool.getDeps(), Matchers.hasItems(shBinaryRule, exportFileRule));
    assertThat(workerTool.getRuntimeDeps(), Matchers.hasItems(shBinaryRule, exportFileRule));
    assertThat(
        workerTool.getArgs(),
        Matchers.containsString(
            pathResolver
                .getAbsolutePath(new BuildTargetSourcePath(exportFileRule.getBuildTarget()))
                .toString()));
  }
예제 #2
0
  @Test
  public void testCreateWorkerTool() throws NoSuchBuildTargetException {
    BuildRuleResolver resolver =
        new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());

    BuildRule shBinaryRule =
        new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe"))
            .setMain(new FakeSourcePath("bin/exe"))
            .build(resolver);

    BuildRule workerRule =
        WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule"))
            .setExe(shBinaryRule.getBuildTarget())
            .setArgs("arg1 arg2")
            .build(resolver);

    assertThat(
        "getBinaryBuildRule should return the build rule supplied in the definition.",
        shBinaryRule,
        Matchers.equalToObject(((WorkerTool) workerRule).getBinaryBuildRule()));

    assertThat(
        "getArgs should return the args string supplied in the definition.",
        "arg1 arg2",
        Matchers.is(((WorkerTool) workerRule).getArgs()));
  }
예제 #3
0
  @Test
  public void testCreateWorkerToolWithBadExeValue() throws NoSuchBuildTargetException {
    BuildRuleResolver resolver =
        new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());

    BuildRule nonBinaryBuildRule =
        new FakeBuildRule(
            BuildTargetFactory.newInstance("//:fake"), new SourcePathResolver(resolver));
    resolver.addToIndex(nonBinaryBuildRule);

    BuildTarget workerTarget = BuildTargetFactory.newInstance("//:worker_rule");
    try {
      WorkerToolBuilder.newWorkerToolBuilder(workerTarget)
          .setExe(nonBinaryBuildRule.getBuildTarget())
          .build(resolver);
    } catch (HumanReadableException e) {
      assertThat(
          e.getHumanReadableErrorMessage(),
          Matchers.containsString("needs to correspond to a binary rule"));
    }
  }