use of com.facebook.buck.model.MacroException in project buck by facebook.
the class MavenCoordinatesMacroExpanderTest method testHasMavenCoordinatesBuildRule.
@Test
public void testHasMavenCoordinatesBuildRule() throws Exception {
String mavenCoords = "org.foo:bar:1.0";
BuildRule rule = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//test:java")).setMavenCoords(mavenCoords).build(resolver);
try {
String actualCoords = expander.getMavenCoordinates(rule);
assertEquals("Return maven coordinates do not match provides ones", mavenCoords, actualCoords);
} catch (MacroException e) {
fail(String.format("Unexpected MacroException: %s", e.getMessage()));
}
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class MavenCoordinatesMacroExpanderTest method testExpansionOfMavenCoordinates.
@Test
public void testExpansionOfMavenCoordinates() throws NoSuchBuildTargetException {
String mavenCoords = "org.foo:bar:1.0";
BuildTarget target = BuildTargetFactory.newInstance("//:java");
JavaLibraryBuilder.createBuilder(target).setMavenCoords(mavenCoords).build(resolver);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("maven_coords", expander));
try {
String expansion = macroHandler.expand(target, createCellRoots(filesystem), resolver, "$(maven_coords //:java)");
assertEquals("Return maven coordinates do not match provides ones", mavenCoords, expansion);
} catch (MacroException e) {
fail(String.format("Unexpected MacroException: %s", e.getMessage()));
}
}
use of com.facebook.buck.model.MacroException 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"));
}
}
use of com.facebook.buck.model.MacroException 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"));
}
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class CxxTestDescription method createBuildRule.
@SuppressWarnings("PMD.PrematureDeclaration")
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams inputParams, final BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(inputParams.getBuildTarget());
inputParams = CxxStrip.removeStripStyleFlavorInParams(inputParams, flavoredStripStyle);
inputParams = LinkerMapMode.removeLinkerMapModeFlavorInParams(inputParams, flavoredLinkerMapMode);
final BuildRuleParams params = inputParams;
Optional<CxxPlatform> platform = cxxPlatforms.getValue(params.getBuildTarget());
CxxPlatform cxxPlatform = platform.orElse(defaultCxxPlatform);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
BuildRuleParams paramsWithoutFlavor = params.withoutFlavor(CxxCompilationDatabase.COMPILATION_DATABASE);
CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, paramsWithoutFlavor, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
return CxxCompilationDatabase.createCompilationDatabase(params, cxxLinkAndCompileRules.compileRules);
}
if (params.getBuildTarget().getFlavors().contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
return CxxDescriptionEnhancer.createUberCompilationDatabase(platform.isPresent() ? params : params.withAppendedFlavor(cxxPlatform.getFlavor()), resolver);
}
if (params.getBuildTarget().getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, cxxPlatform, params);
}
// Generate the link rule that builds the test binary.
final CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinaryDescriptionArg(targetGraph, params, resolver, cxxBuckConfig, cxxPlatform, args, flavoredStripStyle, flavoredLinkerMapMode);
// Construct the actual build params we'll use, notably with an added dependency on the
// CxxLink rule above which builds the test binary.
BuildRuleParams testParams = params.copyReplacingDeclaredAndExtraDeps(() -> cxxLinkAndCompileRules.deps, params.getExtraDeps()).copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder));
testParams = CxxStrip.restoreStripStyleFlavorInParams(testParams, flavoredStripStyle);
testParams = LinkerMapMode.restoreLinkerMapModeFlavorInParams(testParams, flavoredLinkerMapMode);
// Supplier which expands macros in the passed in test environment.
ImmutableMap<String, String> testEnv = ImmutableMap.copyOf(Maps.transformValues(args.env, CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
// Supplier which expands macros in the passed in test arguments.
Supplier<ImmutableList<String>> testArgs = () -> args.args.stream().map(CxxDescriptionEnhancer.MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList());
Supplier<ImmutableSortedSet<BuildRule>> additionalDeps = () -> {
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
// It's not uncommon for users to add dependencies onto other binaries that they run
// during the test, so make sure to add them as runtime deps.
deps.addAll(Sets.difference(params.getDeps(), cxxLinkAndCompileRules.getBinaryRule().getDeps()));
// Add any build-time from any macros embedded in the `env` or `args` parameter.
for (String part : Iterables.concat(args.args, args.env.values())) {
try {
deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractBuildTimeDeps(params.getBuildTarget(), params.getCellRoots(), resolver, part));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
}
}
return deps.build();
};
CxxTest test;
CxxTestType type = args.framework.orElse(getDefaultTestType());
switch(type) {
case GTEST:
{
test = new CxxGtestTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), cxxBuckConfig.getMaximumTestOutputSize());
break;
}
case BOOST:
{
test = new CxxBoostTest(testParams, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, testEnv, testArgs, FluentIterable.from(args.resources).transform(p -> new PathSourcePath(params.getProjectFilesystem(), p)).toSortedSet(Ordering.natural()), additionalDeps, args.labels, args.contacts, args.runTestSeparately.orElse(false), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs));
break;
}
default:
{
Preconditions.checkState(false, "Unhandled C++ test type: %s", type);
throw new RuntimeException();
}
}
return test;
}
Aggregations