Search in sources :

Example 1 with LocationMacroExpander

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

the class CxxGenruleDescription method getMacroHandlerForParseTimeDeps.

@Override
protected MacroHandler getMacroHandlerForParseTimeDeps() {
    ImmutableMap.Builder<String, MacroExpander> macros = ImmutableMap.builder();
    macros.put("exe", new ExecutableMacroExpander());
    macros.put("location", new LocationMacroExpander());
    macros.put("location-platform", new LocationMacroExpander());
    macros.put("platform-name", new StringExpander(""));
    macros.put("cc", new CxxPlatformParseTimeDepsExpander(cxxPlatforms));
    macros.put("cxx", new CxxPlatformParseTimeDepsExpander(cxxPlatforms));
    macros.put("cflags", new StringExpander(""));
    macros.put("cxxflags", new StringExpander(""));
    macros.put("cppflags", new ParseTimeDepsExpander(Filter.NONE));
    macros.put("cxxppflags", new ParseTimeDepsExpander(Filter.NONE));
    macros.put("solibs", new ParseTimeDepsExpander(Filter.NONE));
    macros.put("ld", new CxxPlatformParseTimeDepsExpander(cxxPlatforms));
    for (Linker.LinkableDepType style : Linker.LinkableDepType.values()) {
        for (Filter filter : Filter.values()) {
            macros.put(String.format("ldflags-%s%s", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, style.toString()), filter == Filter.PARAM ? "-filter" : ""), new ParseTimeDepsExpander(filter));
        }
    }
    return new MacroHandler(macros.build());
}
Also used : ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) AbstractMacroExpander(com.facebook.buck.rules.macros.AbstractMacroExpander) MacroExpander(com.facebook.buck.rules.macros.MacroExpander) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) ImmutableMap(com.google.common.collect.ImmutableMap) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) StringExpander(com.facebook.buck.rules.macros.StringExpander)

Example 2 with LocationMacroExpander

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

the class CxxGenruleDescription method getMacroHandler.

@Override
protected <A extends Arg> MacroHandler getMacroHandler(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, TargetGraph targetGraph, A args) {
    CxxPlatform cxxPlatform = cxxPlatforms.getRequiredValue(buildTarget);
    ImmutableMap.Builder<String, MacroExpander> macros = ImmutableMap.builder();
    macros.put("exe", new ExecutableMacroExpander());
    macros.put("location", new CxxLocationMacroExpander(cxxPlatform));
    macros.put("platform-name", new StringExpander(cxxPlatform.getFlavor().toString()));
    macros.put("location-platform", new LocationMacroExpander() {

        @Override
        protected BuildRule resolve(BuildRuleResolver resolver, LocationMacro input) throws MacroException {
            try {
                return resolver.requireRule(input.getTarget().withAppendedFlavors(cxxPlatform.getFlavor()));
            } catch (NoSuchBuildTargetException e) {
                throw new MacroException(e.getHumanReadableErrorMessage());
            }
        }
    });
    macros.put("cc", new ToolExpander(cxxPlatform.getCc().resolve(resolver)));
    macros.put("cxx", new ToolExpander(cxxPlatform.getCxx().resolve(resolver)));
    ImmutableList<String> asflags = cxxPlatform.getAsflags();
    ImmutableList<String> cflags = cxxPlatform.getCflags();
    ImmutableList<String> cxxflags = cxxPlatform.getCxxflags();
    macros.put("cflags", new StringExpander(shquoteJoin(Iterables.concat(cflags, asflags))));
    macros.put("cxxflags", new StringExpander(shquoteJoin(Iterables.concat(cxxflags, asflags))));
    macros.put("cppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.C));
    macros.put("cxxppflags", new CxxPreprocessorFlagsExpander(cxxPlatform, CxxSource.Type.CXX));
    macros.put("ld", new ToolExpander(cxxPlatform.getLd().resolve(resolver)));
    for (Linker.LinkableDepType depType : Linker.LinkableDepType.values()) {
        for (Filter filter : Filter.values()) {
            macros.put(String.format("ldflags-%s%s", depType.toString().toLowerCase().replace('_', '-'), filter == Filter.PARAM ? "-filter" : ""), new CxxLinkerFlagsExpander(buildTarget, filesystem, cxxPlatform, depType, args.out, filter));
        }
    }
    return new MacroHandler(macros.build());
}
Also used : ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) AbstractMacroExpander(com.facebook.buck.rules.macros.AbstractMacroExpander) MacroExpander(com.facebook.buck.rules.macros.MacroExpander) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StringExpander(com.facebook.buck.rules.macros.StringExpander) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) LocationMacro(com.facebook.buck.rules.macros.LocationMacro) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException)

Example 3 with LocationMacroExpander

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

Aggregations

LocationMacroExpander (com.facebook.buck.rules.macros.LocationMacroExpander)3 MacroHandler (com.facebook.buck.rules.macros.MacroHandler)3 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)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 StringExpander (com.facebook.buck.rules.macros.StringExpander)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 MacroException (com.facebook.buck.model.MacroException)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 BuildRule (com.facebook.buck.rules.BuildRule)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 LocationMacro (com.facebook.buck.rules.macros.LocationMacro)1 Genrule (com.facebook.buck.shell.Genrule)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 Test (org.junit.Test)1