Search in sources :

Example 6 with MacroException

use of com.facebook.buck.model.MacroException 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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath)

Example 7 with MacroException

use of com.facebook.buck.model.MacroException 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);
    }
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

Example 8 with MacroException

use of com.facebook.buck.model.MacroException 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 9 with MacroException

use of com.facebook.buck.model.MacroException in project buck by facebook.

the class LocationMacroExpanderTest method testShouldWarnUsersWhenThereIsNoOutputForARuleButLocationRequested.

@Test
public void testShouldWarnUsersWhenThereIsNoOutputForARuleButLocationRequested() throws NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//cheese:java")).build(resolver);
    BuildTarget target = BuildTargetFactory.newInstance("//cheese:cake");
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("location", new LocationMacroExpander()));
    try {
        macroHandler.expand(target, createCellRoots(filesystem), resolver, "$(location //cheese:java)");
        fail("Location was null. Expected HumanReadableException with helpful message.");
    } catch (MacroException e) {
        assertEquals("expanding $(location //cheese:java): //cheese:java used" + " in location macro does not produce output", e.getMessage());
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) MacroException(com.facebook.buck.model.MacroException) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 10 with MacroException

use of com.facebook.buck.model.MacroException in project buck by facebook.

the class MavenCoordinatesMacroExpanderTest method testNonHasMavenCoordinatesBuildRule.

@Test
public void testNonHasMavenCoordinatesBuildRule() throws Exception {
    assumeFalse("Assuming that FakeBuildRule does not have maven coordinates", FakeBuildRule.class.isAssignableFrom(HasMavenCoordinates.class));
    SourcePathResolver sourcePathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildRule rule = new FakeBuildRule("//test:foo", sourcePathResolver);
    try {
        expander.getMavenCoordinates(rule);
        fail("Expected MacroException; Rule does not contain maven coordinates");
    } catch (MacroException e) {
        assertTrue("Expected MacroException that indicates target does not have maven coordinates", e.getMessage().contains("does not correspond to a rule with maven coordinates"));
    }
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) HasMavenCoordinates(com.facebook.buck.jvm.java.HasMavenCoordinates) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Test(org.junit.Test)

Aggregations

MacroException (com.facebook.buck.model.MacroException)20 BuildRule (com.facebook.buck.rules.BuildRule)10 Test (org.junit.Test)9 MacroHandler (com.facebook.buck.rules.macros.MacroHandler)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)4 ImmutableList (com.google.common.collect.ImmutableList)4 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 WorkerMacroExpander (com.facebook.buck.rules.macros.WorkerMacroExpander)3 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)2 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 ExecutableMacroExpander (com.facebook.buck.rules.macros.ExecutableMacroExpander)2