Search in sources :

Example 6 with MacroHandler

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

the class MacroArgTest method getDeps.

@Test
public void getDeps() throws Exception {
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("loc", new LocationMacroExpander()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
    MacroArg arg = new MacroArg(macroHandler, rule.getBuildTarget(), TestCellBuilder.createCellRoots(filesystem), resolver, "$(loc //:rule)");
    assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 7 with MacroHandler

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

the class MacroArgTest method stringify.

@Test
public void stringify() {
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("macro", new StringExpander("expanded")));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    MacroArg arg = new MacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "$(macro)");
    assertThat(Arg.stringifyList(arg, pathResolver), Matchers.contains("expanded"));
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) StringExpander(com.facebook.buck.rules.macros.StringExpander) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 8 with MacroHandler

use of com.facebook.buck.rules.macros.MacroHandler 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 9 with MacroHandler

use of com.facebook.buck.rules.macros.MacroHandler 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 10 with MacroHandler

use of com.facebook.buck.rules.macros.MacroHandler 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

MacroHandler (com.facebook.buck.rules.macros.MacroHandler)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)8 MacroException (com.facebook.buck.model.MacroException)7 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 Test (org.junit.Test)6 BuildRule (com.facebook.buck.rules.BuildRule)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)4 WorkerMacroExpander (com.facebook.buck.rules.macros.WorkerMacroExpander)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 LocationMacroExpander (com.facebook.buck.rules.macros.LocationMacroExpander)3 StringExpander (com.facebook.buck.rules.macros.StringExpander)3 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)2 TargetGraph (com.facebook.buck.rules.TargetGraph)2 AbstractMacroExpander (com.facebook.buck.rules.macros.AbstractMacroExpander)2 ExecutableMacroExpander (com.facebook.buck.rules.macros.ExecutableMacroExpander)2 MacroExpander (com.facebook.buck.rules.macros.MacroExpander)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2