Search in sources :

Example 6 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class OcamlBuildRulesGenerator method generateBytecodeLinking.

/**
   * Links the .cmo files generated by the bytecode compilation
   */
private BuildRule generateBytecodeLinking(ImmutableList<SourcePath> allInputs) {
    BuildRuleParams linkParams = params.withBuildTarget(addBytecodeFlavor(params.getBuildTarget())).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getBytecodeLinkDeps()).addAll(Stream.concat(ocamlContext.getBytecodeLinkableInput().getArgs().stream(), ocamlContext.getCLinkableInput().getArgs().stream()).flatMap(arg -> arg.getDeps(ruleFinder).stream()).filter(rule -> !(rule instanceof OcamlBuild)).iterator()).addAll(cxxCompiler.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
    ImmutableList.Builder<Arg> flags = ImmutableList.builder();
    flags.addAll(ocamlContext.getFlags());
    flags.addAll(StringArg.from(ocamlContext.getCommonCLinkerFlags()));
    OcamlLink link = new OcamlLink(linkParams, allInputs, cxxCompiler.getEnvironment(pathResolver), cxxCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlBytecodeCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getBytecodeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getBytecodeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
    true, /* buildNativePlugin */
    false);
    resolver.addToIndex(link);
    return link;
}
Also used : Iterables(com.google.common.collect.Iterables) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) BuildRule(com.facebook.buck.rules.BuildRule) Compiler(com.facebook.buck.cxx.Compiler) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableMap(com.google.common.collect.ImmutableMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) Arg(com.facebook.buck.rules.args.Arg) Stream(java.util.stream.Stream) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Joiner(com.google.common.base.Joiner) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ImmutableList(com.google.common.collect.ImmutableList) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg)

Example 7 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class OcamlBuildStep method executeMLNativeCompilation.

private StepExecutionResult executeMLNativeCompilation(ExecutionContext context, Path workingDirectory, ImmutableList<Path> sortedInput, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
    MakeCleanDirectoryStep mkDir = new MakeCleanDirectoryStep(filesystem, ocamlContext.getCompileNativeOutputDir());
    StepExecutionResult mkDirExecutionResult = mkDir.execute(context);
    if (!mkDirExecutionResult.isSuccess()) {
        return mkDirExecutionResult;
    }
    for (Path inputOutput : sortedInput) {
        String inputFileName = inputOutput.getFileName().toString();
        String outputFileName = inputFileName.replaceFirst(OcamlCompilables.OCAML_ML_REGEX, OcamlCompilables.OCAML_CMX).replaceFirst(OcamlCompilables.OCAML_RE_REGEX, OcamlCompilables.OCAML_CMX).replaceFirst(OcamlCompilables.OCAML_MLI_REGEX, OcamlCompilables.OCAML_CMI).replaceFirst(OcamlCompilables.OCAML_REI_REGEX, OcamlCompilables.OCAML_CMI);
        Path outputPath = ocamlContext.getCompileNativeOutputDir().resolve(outputFileName);
        if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
            linkerInputs.add(outputPath);
        }
        final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
        false, /* excludeDeps */
        false);
        Step compileStep = new OcamlMLCompileStep(workingDirectory, resolver, new OcamlMLCompileStep.Args(filesystem::resolve, cCompilerEnvironment, cCompiler, ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, inputOutput, compileFlags));
        StepExecutionResult compileExecutionResult = compileStep.execute(context);
        if (!compileExecutionResult.isSuccess()) {
            return compileExecutionResult;
        }
    }
    return StepExecutionResult.SUCCESS;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 8 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class Genrule method isWorkerGenrule.

@VisibleForTesting
public boolean isWorkerGenrule() {
    Arg cmdArg = cmd.orElse(null);
    Arg bashArg = bash.orElse(null);
    Arg cmdExeArg = cmdExe.orElse(null);
    if ((cmdArg instanceof WorkerMacroArg) || (bashArg instanceof WorkerMacroArg) || (cmdExeArg instanceof WorkerMacroArg)) {
        if ((cmdArg != null && !(cmdArg instanceof WorkerMacroArg)) || (bashArg != null && !(bashArg instanceof WorkerMacroArg)) || (cmdExeArg != null && !(cmdExeArg instanceof WorkerMacroArg))) {
            throw new HumanReadableException("You cannot use a worker macro in one of the cmd, bash, " + "or cmd_exe properties and not in the others for genrule %s.", getBuildTarget().getFullyQualifiedName());
        }
        return true;
    }
    return false;
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) WorkerMacroArg(com.facebook.buck.rules.args.WorkerMacroArg) Arg(com.facebook.buck.rules.args.Arg) WorkerMacroArg(com.facebook.buck.rules.args.WorkerMacroArg) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class NativeRelinker method makeRelinkerRule.

private RelinkerRule makeRelinkerRule(TargetCpuType cpuType, SourcePath source, ImmutableList<RelinkerRule> relinkerDeps) {
    Function<RelinkerRule, SourcePath> getSymbolsNeeded = RelinkerRule::getSymbolsNeededPath;
    String libname = resolver.getAbsolutePath(source).getFileName().toString();
    BuildRuleParams relinkerParams = buildRuleParams.withAppendedFlavor(InternalFlavor.of("xdso-dce")).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(cpuType.toString()))).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(libname))).copyAppendingExtraDeps(relinkerDeps);
    BuildRule baseRule = ruleFinder.getRule(source).orElse(null);
    ImmutableList<Arg> linkerArgs = ImmutableList.of();
    Linker linker = null;
    if (baseRule != null && baseRule instanceof CxxLink) {
        CxxLink link = (CxxLink) baseRule;
        linkerArgs = link.getArgs();
        linker = link.getLinker();
    }
    return new RelinkerRule(relinkerParams, resolver, ruleFinder, ImmutableSortedSet.copyOf(Lists.transform(relinkerDeps, getSymbolsNeeded)), cpuType, Preconditions.checkNotNull(nativePlatforms.get(cpuType)).getObjdump(), cxxBuckConfig, source, linker, linkerArgs);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule) CxxLink(com.facebook.buck.cxx.CxxLink) Linker(com.facebook.buck.cxx.Linker)

Example 10 with Arg

use of com.facebook.buck.rules.args.Arg in project buck by facebook.

the class Omnibus method createRoot.

// Create a build rule which links the given root node against the merged omnibus library
// described by the given spec file.
protected static OmnibusRoot createRoot(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, ImmutableList<? extends Arg> extraLdflags, OmnibusSpec spec, SourcePath omnibus, NativeLinkTarget root, BuildTarget rootTargetBase, Optional<Path> output) throws NoSuchBuildTargetException {
    ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();
    // Add any extra flags to the link.
    argsBuilder.addAll(extraLdflags);
    // Since the dummy omnibus library doesn't actually contain any symbols, make sure the linker
    // won't drop its runtime reference to it.
    argsBuilder.addAll(StringArg.from(cxxPlatform.getLd().resolve(ruleResolver).getNoAsNeededSharedLibsFlags()));
    // Since we're linking against a dummy libomnibus, ignore undefined symbols.
    argsBuilder.addAll(StringArg.from(cxxPlatform.getLd().resolve(ruleResolver).getIgnoreUndefinedSymbolsFlags()));
    // Add the args for the root link target first.
    NativeLinkableInput input = root.getNativeLinkTargetInput(cxxPlatform);
    argsBuilder.addAll(input.getArgs());
    // Grab a topologically sorted mapping of all the root's deps.
    ImmutableMap<BuildTarget, NativeLinkable> deps = NativeLinkables.getNativeLinkables(cxxPlatform, root.getNativeLinkTargetDeps(cxxPlatform), Linker.LinkableDepType.SHARED);
    // Now process the dependencies in topological order, to assemble the link line.
    boolean alreadyAddedOmnibusToArgs = false;
    for (Map.Entry<BuildTarget, NativeLinkable> entry : deps.entrySet()) {
        BuildTarget target = entry.getKey();
        NativeLinkable nativeLinkable = entry.getValue();
        Linker.LinkableDepType linkStyle = NativeLinkables.getLinkStyle(nativeLinkable.getPreferredLinkage(cxxPlatform), Linker.LinkableDepType.SHARED);
        // If this dep needs to be linked statically, then we always link it directly.
        if (linkStyle != Linker.LinkableDepType.SHARED) {
            Preconditions.checkState(linkStyle == Linker.LinkableDepType.STATIC_PIC);
            argsBuilder.addAll(nativeLinkable.getNativeLinkableInput(cxxPlatform, linkStyle).getArgs());
            continue;
        }
        // If this dep is another root node, substitute in the custom linked library we built for it.
        if (spec.getRoots().containsKey(target)) {
            argsBuilder.add(SourcePathArg.of(new DefaultBuildTargetSourcePath(getRootTarget(params.getBuildTarget(), target))));
            continue;
        }
        // libomnibus instead.
        if (spec.getBody().containsKey(target)) {
            // && linkStyle == Linker.LinkableDepType.SHARED) {
            if (!alreadyAddedOmnibusToArgs) {
                argsBuilder.add(SourcePathArg.of(omnibus));
                alreadyAddedOmnibusToArgs = true;
            }
            continue;
        }
        // Otherwise, this is either an explicitly statically linked or excluded node, so link it
        // normally.
        Preconditions.checkState(spec.getExcluded().containsKey(target));
        argsBuilder.addAll(nativeLinkable.getNativeLinkableInput(cxxPlatform, linkStyle).getArgs());
    }
    // Create the root library rule using the arguments assembled above.
    BuildTarget rootTarget = getRootTarget(params.getBuildTarget(), rootTargetBase);
    NativeLinkTargetMode rootTargetMode = root.getNativeLinkTargetMode(cxxPlatform);
    CxxLink rootLinkRule;
    switch(rootTargetMode.getType()) {
        // Link the root as a shared library.
        case SHARED:
            {
                Optional<String> rootSoname = rootTargetMode.getLibraryName();
                rootLinkRule = CxxLinkableEnhancer.createCxxLinkableSharedBuildRule(cxxBuckConfig, cxxPlatform, params, ruleResolver, ruleFinder, rootTarget, output.orElse(BuildTargets.getGenPath(params.getProjectFilesystem(), rootTarget, "%s").resolve(rootSoname.orElse(String.format("%s.%s", rootTarget.getShortName(), cxxPlatform.getSharedLibraryExtension())))), rootSoname, argsBuilder.build());
                break;
            }
        // Link the root as an executable.
        case EXECUTABLE:
            {
                rootLinkRule = CxxLinkableEnhancer.createCxxLinkableBuildRule(cxxBuckConfig, cxxPlatform, params, ruleResolver, ruleFinder, rootTarget, output.orElse(BuildTargets.getGenPath(params.getProjectFilesystem(), rootTarget, "%s").resolve(rootTarget.getShortName())), argsBuilder.build(), Linker.LinkableDepType.SHARED, Optional.empty());
                break;
            }
        // $CASES-OMITTED$
        default:
            throw new IllegalStateException(String.format("%s: unexpected omnibus root type: %s %s", params.getBuildTarget(), root.getBuildTarget(), rootTargetMode.getType()));
    }
    CxxLink rootRule = ruleResolver.addToIndex(rootLinkRule);
    return OmnibusRoot.of(rootRule.getSourcePathToOutput());
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Arg (com.facebook.buck.rules.args.Arg)28 StringArg (com.facebook.buck.rules.args.StringArg)21 BuildTarget (com.facebook.buck.model.BuildTarget)14 ImmutableList (com.google.common.collect.ImmutableList)14 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 SourcePath (com.facebook.buck.rules.SourcePath)13 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)13 BuildRule (com.facebook.buck.rules.BuildRule)12 SourcePathArg (com.facebook.buck.rules.args.SourcePathArg)12 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)11 Path (java.nio.file.Path)11 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)10 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)10 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 Test (org.junit.Test)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)7 Linker (com.facebook.buck.cxx.Linker)6 InternalFlavor (com.facebook.buck.model.InternalFlavor)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)5