Search in sources :

Example 1 with WorkerMacroExpander

use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.

the class WorkerMacroArgTest method testWorkerMacroArgWithNoMacros.

@Test
public void testWorkerMacroArgWithNoMacros() throws MacroException, NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    try {
        new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "no macros here");
    } catch (MacroException e) {
        assertThat(e.getMessage(), Matchers.containsString("Unable to extract any build targets"));
    }
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) MacroException(com.facebook.buck.model.MacroException) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with WorkerMacroExpander

use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.

the class WorkerMacroArgTest method testWorkerMacroArgWithBadReference.

@Test
public void testWorkerMacroArgWithBadReference() throws MacroException, NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule nonWorkerBuildRule = new FakeBuildRule(BuildTargetFactory.newInstance("//:not_worker_rule"), new SourcePathResolver(new SourcePathRuleFinder(resolver)));
    resolver.addToIndex(nonWorkerBuildRule);
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    try {
        new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "$(worker //:not_worker_rule)");
    } catch (MacroException e) {
        assertThat(e.getMessage(), Matchers.containsString("does not correspond to a worker_tool"));
    }
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) MacroException(com.facebook.buck.model.MacroException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 3 with WorkerMacroExpander

use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.

the class WorkerMacroArgTest method testWorkerMacroArgWithMacroInWrongLocation.

@Test
public void testWorkerMacroArgWithMacroInWrongLocation() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    try {
        new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "mkdir && $(worker :worker)");
    } catch (MacroException e) {
        assertThat(e.getMessage(), Matchers.containsString("must be at the beginning"));
    }
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) MacroException(com.facebook.buck.model.MacroException) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 4 with WorkerMacroExpander

use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.

the class WorkerMacroArgTest method testWorkerMacroArgConstruction.

@Test
public void testWorkerMacroArgConstruction() throws MacroException, NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildRule shBinaryRule = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe")).setMain(new FakeSourcePath("bin/exe")).build(resolver);
    String startupArgs = "startupargs";
    Integer maxWorkers = 5;
    WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule")).setExe(shBinaryRule.getBuildTarget()).setArgs(startupArgs).setMaxWorkers(maxWorkers).build(resolver);
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    String jobArgs = "jobargs";
    WorkerMacroArg arg = new WorkerMacroArg(macroHandler, target, TestCellBuilder.createCellRoots(filesystem), resolver, "$(worker //:worker_rule) " + jobArgs);
    assertThat(arg.getJobArgs(), Matchers.equalTo(jobArgs));
    assertThat(arg.getStartupArgs(pathResolver), Matchers.equalTo(startupArgs));
    assertThat(arg.getMaxWorkers(), Matchers.equalTo(maxWorkers));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 MacroHandler (com.facebook.buck.rules.macros.MacroHandler)4 WorkerMacroExpander (com.facebook.buck.rules.macros.WorkerMacroExpander)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 Test (org.junit.Test)4 MacroException (com.facebook.buck.model.MacroException)3 BuildRule (com.facebook.buck.rules.BuildRule)2 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 ShBinaryBuilder (com.facebook.buck.shell.ShBinaryBuilder)1