Search in sources :

Example 1 with MacroException

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

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

the class QueryMacroExpander method resolveQuery.

Stream<QueryTarget> resolveQuery(BuildTarget target, CellPathResolver cellNames, final BuildRuleResolver resolver, String queryExpression) throws MacroException {
    GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.of(resolver), targetGraph, cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), ImmutableSet.of());
    try {
        QueryExpression parsedExp = QueryExpression.parse(queryExpression, env);
        Set<QueryTarget> queryTargets = parsedExp.eval(env, executorService);
        return queryTargets.stream();
    } catch (QueryException e) {
        throw new MacroException("Error parsing/executing query from macro", e);
    } catch (InterruptedException e) {
        throw new MacroException("Error executing query", e);
    }
}
Also used : QueryTarget(com.facebook.buck.query.QueryTarget) GraphEnhancementQueryEnvironment(com.facebook.buck.rules.query.GraphEnhancementQueryEnvironment) QueryException(com.facebook.buck.query.QueryException) QueryExpression(com.facebook.buck.query.QueryExpression) MacroException(com.facebook.buck.model.MacroException)

Example 3 with MacroException

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

the class MacroArg method getInputs.

@Override
public ImmutableCollection<SourcePath> getInputs() {
    ImmutableCollection<BuildRule> rules;
    try {
        rules = expander.extractBuildTimeDeps(target, cellNames, resolver, unexpanded);
    } catch (MacroException e) {
        throw new HumanReadableException(e, "%s: %s", target, e.getMessage());
    }
    ImmutableList.Builder<SourcePath> paths = ImmutableList.builder();
    for (BuildRule rule : rules) {
        paths.add(Preconditions.checkNotNull(rule.getSourcePathToOutput()));
    }
    return paths.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) ImmutableList(com.google.common.collect.ImmutableList) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException)

Example 4 with MacroException

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

the class ApplePackageDescription method addDepsFromParam.

/**
   * Retrieve deps from macros in externally configured rules.
   *
   * This is used for ImplicitDepsInferringDescription, so it is flavor agnostic.
   */
private void addDepsFromParam(ImmutableSet.Builder<BuildTarget> builder, BuildTarget target, CellPathResolver cellNames) {
    // Add all macro expanded dependencies for these platforms.
    for (Flavor flavor : appleCxxPlatformFlavorDomain.getFlavors()) {
        AppleCxxPlatform platform = appleCxxPlatformFlavorDomain.getValue(flavor);
        Optional<ApplePackageConfig> packageConfig = config.getPackageConfigForPlatform(platform.getAppleSdk().getApplePlatform());
        if (packageConfig.isPresent()) {
            try {
                builder.addAll(AbstractGenruleDescription.PARSE_TIME_MACRO_HANDLER.extractParseTimeDeps(target, cellNames, packageConfig.get().getCommand()));
            } catch (MacroException e) {
                throw new HumanReadableException(e, "%s (for platform %s): %s", target, platform.getAppleSdk().getApplePlatform().getName(), e.getMessage());
            }
        }
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException) Flavor(com.facebook.buck.model.Flavor)

Example 5 with MacroException

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

the class CxxTestDescription method findDepsForTargetFromConstructorArgs.

@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, Arg constructorArg) {
    ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
    // Get any parse time deps from the C/C++ platforms.
    deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValue(buildTarget.getFlavors()).orElse(defaultCxxPlatform)));
    // Extract parse time deps from flags, args, and environment parameters.
    Iterable<Iterable<String>> macroStrings = ImmutableList.<Iterable<String>>builder().add(constructorArg.args).add(constructorArg.env.values()).build();
    for (String macroString : Iterables.concat(macroStrings)) {
        try {
            deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractParseTimeDeps(buildTarget, cellRoots, macroString));
        } catch (MacroException e) {
            throw new HumanReadableException(e, "%s: %s", buildTarget, e.getMessage());
        }
    }
    CxxTestType type = constructorArg.framework.orElse(getDefaultTestType());
    switch(type) {
        case GTEST:
            {
                cxxBuckConfig.getGtestDep().ifPresent(deps::add);
                if (constructorArg.useDefaultTestMain.orElse(true)) {
                    cxxBuckConfig.getGtestDefaultTestMainDep().ifPresent(deps::add);
                }
                break;
            }
        case BOOST:
            {
                cxxBuckConfig.getBoostTestDep().ifPresent(deps::add);
                break;
            }
        default:
            {
                break;
            }
    }
    constructorArg.depsQuery.ifPresent(depsQuery -> QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery).forEach(deps::add));
    return deps.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FluentIterable(com.google.common.collect.FluentIterable) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

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