Search in sources :

Example 31 with NoSuchBuildTargetException

use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.

the class RustTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    BuildTarget exeTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("unittest"));
    BinaryWrapperRule testExeBuild = resolver.addToIndex(RustCompileUtils.createBinaryBuildRule(params.withBuildTarget(exeTarget), resolver, rustBuckConfig, cxxPlatforms, defaultCxxPlatform, args.crate, args.features, Stream.of(args.framework ? Stream.of("--test") : Stream.<String>empty(), rustBuckConfig.getRustTestFlags().stream(), args.rustcFlags.stream()).flatMap(x -> x).iterator(), args.linkerFlags.iterator(), RustCompileUtils.getLinkStyle(params.getBuildTarget(), args.linkStyle), args.rpath, args.srcs, args.crateRoot, ImmutableSet.of("lib.rs", "main.rs")));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Tool testExe = testExeBuild.getExecutableCommand();
    BuildRuleParams testParams = params.copyAppendingExtraDeps(testExe.getDeps(ruleFinder));
    return new RustTest(testParams, ruleFinder, testExeBuild, args.labels, args.contacts);
}
Also used : Linker(com.facebook.buck.cxx.Linker) BinaryWrapperRule(com.facebook.buck.rules.BinaryWrapperRule) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ToolProvider(com.facebook.buck.rules.ToolProvider) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomain(com.facebook.buck.model.FlavorDomain) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) CxxPlatforms(com.facebook.buck.cxx.CxxPlatforms) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Stream(java.util.stream.Stream) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) VersionRoot(com.facebook.buck.versions.VersionRoot) Optional(java.util.Optional) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BinaryWrapperRule(com.facebook.buck.rules.BinaryWrapperRule) Tool(com.facebook.buck.rules.Tool)

Example 32 with NoSuchBuildTargetException

use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.

the class AbstractGenruleDescription method createBuildRule.

@Override
public <A extends T> BuildRule createBuildRule(final TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    java.util.function.Function<String, com.facebook.buck.rules.args.Arg> macroArgFunction = MacroArg.toMacroArgFunction(getMacroHandler(params.getBuildTarget(), params.getProjectFilesystem(), resolver, targetGraph, args), params.getBuildTarget(), params.getCellRoots(), resolver)::apply;
    final Optional<com.facebook.buck.rules.args.Arg> cmd = args.cmd.map(macroArgFunction);
    final Optional<com.facebook.buck.rules.args.Arg> bash = args.bash.map(macroArgFunction);
    final Optional<com.facebook.buck.rules.args.Arg> cmdExe = args.cmdExe.map(macroArgFunction);
    return createBuildRule(params.copyReplacingExtraDeps(Suppliers.ofInstance(Stream.concat(ruleFinder.filterBuildRuleInputs(args.srcs).stream(), Stream.of(cmd, bash, cmdExe).flatMap(Optionals::toStream).flatMap(input -> input.getDeps(ruleFinder).stream())).collect(MoreCollectors.toImmutableSortedSet(Comparator.<BuildRule>naturalOrder())))), resolver, args, cmd, bash, cmdExe);
}
Also used : CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) QueryTargetsMacroExpander(com.facebook.buck.rules.macros.QueryTargetsMacroExpander) HasTests(com.facebook.buck.model.HasTests) ClasspathMacroExpander(com.facebook.buck.rules.macros.ClasspathMacroExpander) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) Suppliers(com.google.common.base.Suppliers) QueryOutputsMacroExpander(com.facebook.buck.rules.macros.QueryOutputsMacroExpander) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) MoreCollectors(com.facebook.buck.util.MoreCollectors) MavenCoordinatesMacroExpander(com.facebook.buck.rules.macros.MavenCoordinatesMacroExpander) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) MacroArg(com.facebook.buck.rules.args.MacroArg) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) MacroException(com.facebook.buck.model.MacroException) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) MacroExpander(com.facebook.buck.rules.macros.MacroExpander) Stream(java.util.stream.Stream) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) Comparator(java.util.Comparator) Description(com.facebook.buck.rules.Description) Optionals(com.facebook.buck.util.Optionals) MacroArg(com.facebook.buck.rules.args.MacroArg) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder)

Example 33 with NoSuchBuildTargetException

use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.

the class WorkerToolDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    BuildRule rule = resolver.requireRule(args.exe);
    if (!(rule instanceof BinaryBuildRule)) {
        throw new HumanReadableException("The 'exe' argument of %s, %s, needs to correspond to a " + "binary rule, such as sh_binary().", params.getBuildTarget(), args.exe.getFullyQualifiedName());
    }
    Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
    final ImmutableList<com.facebook.buck.rules.args.Arg> workerToolArgs = args.getStartupArgs().stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
    ImmutableMap<String, String> expandedEnv = ImmutableMap.copyOf(FluentIterable.from(args.env.entrySet()).transform(input -> {
        try {
            return Maps.immutableEntry(input.getKey(), MACRO_HANDLER.expand(params.getBuildTarget(), params.getCellRoots(), resolver, input.getValue()));
        } catch (MacroException e) {
            throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
        }
    }));
    int maxWorkers;
    if (args.maxWorkers.isPresent()) {
        // negative or zero: unlimited number of worker processes
        maxWorkers = args.maxWorkers.get() < 1 ? Integer.MAX_VALUE : args.maxWorkers.get();
    } else {
        // default is 1 worker process (for backwards compatibility)
        maxWorkers = 1;
    }
    return new DefaultWorkerTool(params, (BinaryBuildRule) rule, workerToolArgs, expandedEnv, maxWorkers, args.persistent.orElse(buckConfig.getBooleanValue(CONFIG_SECTION, CONFIG_PERSISTENT_KEY, false)));
}
Also used : BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) CellPathResolver(com.facebook.buck.rules.CellPathResolver) Either(com.facebook.buck.model.Either) ClasspathMacroExpander(com.facebook.buck.rules.macros.ClasspathMacroExpander) BuildRule(com.facebook.buck.rules.BuildRule) BuckConfig(com.facebook.buck.cli.BuckConfig) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) Map(java.util.Map) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) MacroArg(com.facebook.buck.rules.args.MacroArg) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) MacroException(com.facebook.buck.model.MacroException) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Maps(com.google.common.collect.Maps) ExecutableMacroExpander(com.facebook.buck.rules.macros.ExecutableMacroExpander) MacroExpander(com.facebook.buck.rules.macros.MacroExpander) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Optional(java.util.Optional) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) Description(com.facebook.buck.rules.Description) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroArg(com.facebook.buck.rules.args.MacroArg) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) MacroException(com.facebook.buck.model.MacroException)

Example 34 with NoSuchBuildTargetException

use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.

the class OwnersReportTest method createTargetNode.

private TargetNode<?, ?> createTargetNode(BuildTarget buildTarget, ImmutableSet<Path> inputs) {
    Description<FakeRuleDescription.FakeArg> description = new FakeRuleDescription();
    FakeRuleDescription.FakeArg arg = description.createUnpopulatedConstructorArg();
    arg.inputs = inputs;
    try {
        return new TargetNodeFactory(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())).create(Hashing.sha1().hashString(buildTarget.getFullyQualifiedName(), UTF_8), description, arg, filesystem, buildTarget, ImmutableSet.of(), ImmutableSet.of(), createCellRoots(filesystem));
    } catch (NoSuchBuildTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)

Aggregations

NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)34 BuildTarget (com.facebook.buck.model.BuildTarget)26 BuildRule (com.facebook.buck.rules.BuildRule)25 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)22 SourcePath (com.facebook.buck.rules.SourcePath)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)20 ImmutableList (com.google.common.collect.ImmutableList)19 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)18 ImmutableSet (com.google.common.collect.ImmutableSet)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableMap (com.google.common.collect.ImmutableMap)14 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)14 Path (java.nio.file.Path)13 Optional (java.util.Optional)13 Flavor (com.facebook.buck.model.Flavor)11 TargetGraph (com.facebook.buck.rules.TargetGraph)11 Map (java.util.Map)11 MoreCollectors (com.facebook.buck.util.MoreCollectors)10 InternalFlavor (com.facebook.buck.model.InternalFlavor)9