Search in sources :

Example 1 with WorkerTool

use of com.facebook.buck.shell.WorkerTool in project buck by facebook.

the class JsLibraryDescription method createDevFileRule.

private static <A extends Arg> BuildRule createDevFileRule(BuildRuleParams params, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, A args, Either<SourcePath, Pair<SourcePath, String>> source, WorkerTool worker) {
    final SourcePath sourcePath = source.transform(x -> x, Pair::getFirst);
    final Optional<String> subPath = Optional.ofNullable(source.transform(x -> null, Pair::getSecond));
    final Optional<Path> virtualPath = args.basePath.map(basePath -> changePathPrefix(sourcePath, basePath, params, sourcePathResolver, params.getBuildTarget().getUnflavoredBuildTarget()).resolve(subPath.orElse("")));
    return new JsFile.JsFileDev(ruleFinder.getRule(sourcePath).map(params::copyAppendingExtraDeps).orElse(params), sourcePath, subPath, virtualPath, args.extraArgs, worker);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Iterables(com.google.common.collect.Iterables) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) Flavored(com.facebook.buck.model.Flavored) Function(java.util.function.Function) BuildRule(com.facebook.buck.rules.BuildRule) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Pair(com.facebook.buck.model.Pair) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) MorePaths(com.facebook.buck.io.MorePaths) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Paths(java.nio.file.Paths) Hint(com.facebook.buck.rules.Hint) WorkerTool(com.facebook.buck.shell.WorkerTool) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Pair(com.facebook.buck.model.Pair)

Example 2 with WorkerTool

use of com.facebook.buck.shell.WorkerTool in project buck by facebook.

the class JsLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    params.getBuildTarget().getBasePath();
    // this params object is used as base for the JsLibrary build rule, but also for all dynamically
    // created JsFile rules.
    // For the JsLibrary case, we want to propagate flavors to library dependencies
    // For the JsFile case, we only want to depend on the worker, not on any libraries
    params = JsUtil.withWorkerDependencyOnly(params, resolver, args.worker);
    final WorkerTool worker = resolver.getRuleWithType(args.worker, WorkerTool.class);
    final SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    final SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    final ImmutableBiMap<Either<SourcePath, Pair<SourcePath, String>>, Flavor> sourcesToFlavors = mapSourcesToFlavors(sourcePathResolver, args.srcs);
    final Optional<Either<SourcePath, Pair<SourcePath, String>>> file = JsFlavors.extractSourcePath(sourcesToFlavors.inverse(), params.getBuildTarget().getFlavors().stream());
    if (file.isPresent()) {
        return params.getBuildTarget().getFlavors().contains(JsFlavors.RELEASE) ? createReleaseFileRule(params, resolver, args, worker) : createDevFileRule(params, ruleFinder, sourcePathResolver, args, file.get(), worker);
    } else {
        return new LibraryBuilder(targetGraph, resolver, params, sourcesToFlavors).setSources(args.srcs).setLibraryDependencies(args.libs).build(worker);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) WorkerTool(com.facebook.buck.shell.WorkerTool) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Flavor(com.facebook.buck.model.Flavor)

Example 3 with WorkerTool

use of com.facebook.buck.shell.WorkerTool in project buck by facebook.

the class JsUtil method workerShellStep.

static WorkerShellStep workerShellStep(WorkerTool worker, String jobArgs, BuildTarget buildTarget, SourcePathResolver sourcePathResolver, ProjectFilesystem projectFilesystem) {
    final Tool tool = worker.getTool();
    final WorkerJobParams params = WorkerJobParams.of(worker.getTempDir(), tool.getCommandPrefix(sourcePathResolver), worker.getArgs(sourcePathResolver), tool.getEnvironment(sourcePathResolver), jobArgs, worker.getMaxWorkers(), worker.isPersistent() ? Optional.of(buildTarget.getCellPath().toString() + buildTarget.toString()) : Optional.empty(), Optional.of(worker.getInstanceKey()));
    return new WorkerShellStep(Optional.of(params), Optional.empty(), Optional.empty(), new WorkerProcessPoolFactory(projectFilesystem));
}
Also used : WorkerJobParams(com.facebook.buck.shell.WorkerJobParams) WorkerProcessPoolFactory(com.facebook.buck.shell.WorkerProcessPoolFactory) WorkerShellStep(com.facebook.buck.shell.WorkerShellStep) Tool(com.facebook.buck.rules.Tool) WorkerTool(com.facebook.buck.shell.WorkerTool)

Aggregations

WorkerTool (com.facebook.buck.shell.WorkerTool)3 Either (com.facebook.buck.model.Either)2 Flavor (com.facebook.buck.model.Flavor)2 SourcePath (com.facebook.buck.rules.SourcePath)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 MorePaths (com.facebook.buck.io.MorePaths)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 Flavored (com.facebook.buck.model.Flavored)1 Pair (com.facebook.buck.model.Pair)1 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 AbstractDescriptionArg (com.facebook.buck.rules.AbstractDescriptionArg)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 Description (com.facebook.buck.rules.Description)1 Hint (com.facebook.buck.rules.Hint)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 Tool (com.facebook.buck.rules.Tool)1