use of com.facebook.buck.rules.macros.MacroHandler 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());
}
use of com.facebook.buck.rules.macros.MacroHandler 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());
}
use of com.facebook.buck.rules.macros.MacroHandler in project buck by facebook.
the class PrebuiltCxxLibraryDescription method getApplicableSourcePath.
private static SourcePath getApplicableSourcePath(final BuildTarget target, final CellPathResolver cellRoots, final ProjectFilesystem filesystem, final BuildRuleResolver ruleResolver, final CxxPlatform cxxPlatform, Optional<String> versionSubDir, final String basePathString, final Optional<String> addedPathString) {
ImmutableList<BuildRule> deps;
MacroHandler handler = getMacroHandler(Optional.of(cxxPlatform));
try {
deps = handler.extractBuildTimeDeps(target, cellRoots, ruleResolver, basePathString);
} catch (MacroException e) {
deps = ImmutableList.of();
}
Path libDirPath = filesystem.getPath(expandMacros(handler, target, cellRoots, ruleResolver, basePathString));
if (versionSubDir.isPresent()) {
libDirPath = filesystem.getPath(versionSubDir.get()).resolve(libDirPath);
}
// So just expand the macros and return a PathSourcePath
if (deps.isEmpty()) {
Path resultPath = libDirPath;
if (addedPathString.isPresent()) {
resultPath = libDirPath.resolve(expandMacros(handler, target, cellRoots, ruleResolver, addedPathString.get()));
}
resultPath = target.getBasePath().resolve(resultPath);
return new PathSourcePath(filesystem, resultPath);
}
// If we get here then this is referencing the output from a build rule.
// This always return a ExplicitBuildTargetSourcePath
Path p = filesystem.resolve(libDirPath);
if (addedPathString.isPresent()) {
p = p.resolve(addedPathString.get());
}
p = filesystem.relativize(p);
return new ExplicitBuildTargetSourcePath(deps.iterator().next().getBuildTarget(), p);
}
use of com.facebook.buck.rules.macros.MacroHandler in project buck by facebook.
the class PrebuiltCxxLibraryDescription method addDepsFromParam.
private void addDepsFromParam(BuildTarget target, CellPathResolver cellNames, String paramValue, ImmutableSet.Builder<BuildTarget> targets) {
try {
// doesn't matter that the platform expander doesn't do anything.
MacroHandler macroHandler = getMacroHandler(Optional.empty());
// Then get the parse time deps.
targets.addAll(macroHandler.extractParseTimeDeps(target, cellNames, paramValue));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s : %s in \"%s\"", target, e.getMessage(), paramValue);
}
}
use of com.facebook.buck.rules.macros.MacroHandler 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"));
}
}
Aggregations