Search in sources :

Example 71 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class OcamlBuildStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
    if (hasGeneratedSources) {
        StepExecutionResult genExecutionResult = generateSources(context, filesystem.getRootPath());
        if (!genExecutionResult.isSuccess()) {
            return genExecutionResult;
        }
    }
    StepExecutionResult depToolExecutionResult = depToolStep.execute(context);
    if (!depToolExecutionResult.isSuccess()) {
        return depToolExecutionResult;
    }
    // OCaml requires module A to be present in command line to ocamlopt or ocamlc before
    // module B if B depends on A. In OCaml circular dependencies are prohibited, so all
    // dependency relations among modules form DAG. Topologically sorting this graph satisfies the
    // requirement.
    //
    // To get the DAG we launch ocamldep tool which provides the direct dependency information, like
    // module A depends on modules B, C, D.
    ImmutableList<Path> sortedInput = sortDependency(depToolStep.getStdout(), ocamlContext.getSourcePathResolver().getAllAbsolutePaths(ocamlContext.getMLInput()));
    ImmutableList.Builder<Path> nativeLinkerInputs = ImmutableList.builder();
    if (!bytecodeOnly) {
        StepExecutionResult mlCompileNativeExecutionResult = executeMLNativeCompilation(context, filesystem.getRootPath(), sortedInput, nativeLinkerInputs);
        if (!mlCompileNativeExecutionResult.isSuccess()) {
            return mlCompileNativeExecutionResult;
        }
    }
    ImmutableList.Builder<Path> bytecodeLinkerInputs = ImmutableList.builder();
    StepExecutionResult mlCompileBytecodeExecutionResult = executeMLBytecodeCompilation(context, filesystem.getRootPath(), sortedInput, bytecodeLinkerInputs);
    if (!mlCompileBytecodeExecutionResult.isSuccess()) {
        return mlCompileBytecodeExecutionResult;
    }
    ImmutableList.Builder<Path> cLinkerInputs = ImmutableList.builder();
    StepExecutionResult cCompileExecutionResult = executeCCompilation(context, cLinkerInputs);
    if (!cCompileExecutionResult.isSuccess()) {
        return cCompileExecutionResult;
    }
    ImmutableList<Path> cObjects = cLinkerInputs.build();
    if (!bytecodeOnly) {
        nativeLinkerInputs.addAll(cObjects);
        StepExecutionResult nativeLinkExecutionResult = executeNativeLinking(context, nativeLinkerInputs.build());
        if (!nativeLinkExecutionResult.isSuccess()) {
            return nativeLinkExecutionResult;
        }
    }
    bytecodeLinkerInputs.addAll(cObjects);
    StepExecutionResult bytecodeLinkExecutionResult = executeBytecodeLinking(context, bytecodeLinkerInputs.build());
    if (!bytecodeLinkExecutionResult.isSuccess()) {
        return bytecodeLinkExecutionResult;
    }
    if (!ocamlContext.isLibrary()) {
        Step debugLauncher = new OcamlDebugLauncherStep(filesystem, resolver, new OcamlDebugLauncherStep.Args(ocamlContext.getOcamlDebug().get(), ocamlContext.getBytecodeOutput(), ocamlContext.getOcamlInput(), ocamlContext.getBytecodeIncludeFlags()));
        return debugLauncher.execute(context);
    } else {
        return StepExecutionResult.SUCCESS;
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) StepExecutionResult(com.facebook.buck.step.StepExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 72 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class LuaStandaloneBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    buildableContext.recordArtifact(output);
    // Make sure the parent directory exists.
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    // Delete any other pex that was there (when switching between pex styles).
    steps.add(new RmStep(getProjectFilesystem(), output, RmStep.Mode.RECURSIVE));
    SourcePathResolver resolver = context.getSourcePathResolver();
    steps.add(new ShellStep(getProjectFilesystem().getRootPath()) {

        @Override
        protected Optional<String> getStdin(ExecutionContext context) {
            try {
                return Optional.of(context.getObjectMapper().writeValueAsString(ImmutableMap.of("modules", Maps.transformValues(components.getModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "pythonModules", Maps.transformValues(components.getPythonModules(), Functions.compose(Object::toString, resolver::getAbsolutePath)), "nativeLibraries", Maps.transformValues(components.getNativeLibraries(), Functions.compose(Object::toString, resolver::getAbsolutePath)))));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            ImmutableList.Builder<String> command = ImmutableList.builder();
            command.addAll(builder.getCommandPrefix(resolver));
            command.addAll(builderArgs);
            command.add("--entry-point", mainModule);
            command.add("--interpreter");
            if (starter.isPresent()) {
                command.add(resolver.getAbsolutePath(starter.get()).toString());
            } else {
                command.add(lua.getCommandPrefix(resolver).get(0));
            }
            command.add(getProjectFilesystem().resolve(output).toString());
            return command.build();
        }

        @Override
        public String getShortName() {
            return "lua_package";
        }
    });
    return steps.build();
}
Also used : Optional(java.util.Optional) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ShellStep(com.facebook.buck.shell.ShellStep) IOException(java.io.IOException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ShellStep(com.facebook.buck.shell.ShellStep)

Example 73 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class ExportFile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    SourcePathResolver resolver = context.getSourcePathResolver();
    // This file is copied rather than symlinked so that when it is included in an archive zip and
    // unpacked on another machine, it is an ordinary file in both scenarios.
    ImmutableList.Builder<Step> builder = ImmutableList.builder();
    if (mode == ExportFileDescription.Mode.COPY) {
        Path out = getCopiedPath();
        builder.add(new MkdirStep(getProjectFilesystem(), out.getParent()));
        builder.add(new RmStep(getProjectFilesystem(), out, RmStep.Mode.RECURSIVE));
        if (resolver.getFilesystem(src).isDirectory(resolver.getRelativePath(src))) {
            builder.add(CopyStep.forDirectory(getProjectFilesystem(), resolver.getAbsolutePath(src), out, CopyStep.DirectoryMode.CONTENTS_ONLY));
        } else {
            builder.add(CopyStep.forFile(getProjectFilesystem(), resolver.getAbsolutePath(src), out));
        }
        buildableContext.recordArtifact(out);
    }
    return builder.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) RmStep(com.facebook.buck.step.fs.RmStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) CopyStep(com.facebook.buck.step.fs.CopyStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 74 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class Genrule method getBuildSteps.

@Override
@VisibleForTesting
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    // Make sure that the directory to contain the output file exists, deleting any pre-existing
    // ones. Rules get output to a directory named after the base path, so we don't want to nuke
    // the entire directory.
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToOutDirectory));
    // Delete the old temp directory
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToTmpDirectory));
    // Create a directory to hold all the source files.
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), pathToSrcDirectory));
    addSymlinkCommands(context, commands);
    // Create a shell command that corresponds to this.cmd.
    if (this.isWorkerGenrule) {
        commands.add(createWorkerShellStep(context));
    } else {
        commands.add(createGenruleStep(context));
    }
    if (MorePaths.getFileExtension(pathToOutFile).equals("zip")) {
        commands.add(new ZipScrubberStep(getProjectFilesystem(), pathToOutFile));
    }
    buildableContext.recordArtifact(pathToOutFile);
    return commands.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Step(com.facebook.buck.step.Step) MkdirAndSymlinkFileStep(com.facebook.buck.step.fs.MkdirAndSymlinkFileStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) ZipScrubberStep(com.facebook.buck.zip.ZipScrubberStep) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 75 with ImmutableList

use of org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableList in project buck by facebook.

the class RustCompileRule method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext buildContext, BuildableContext buildableContext) {
    Path output = getOutput();
    buildableContext.recordArtifact(output);
    SourcePathResolver resolver = buildContext.getSourcePathResolver();
    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir), new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), srcs.stream().map(resolver::getRelativePath).collect(MoreCollectors.toImmutableList()), scratchDir), new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputDir(getBuildTarget(), getProjectFilesystem())), new ShellStep(getProjectFilesystem().getRootPath()) {

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext executionContext) {
            ImmutableList<String> linkerCmd = linker.getCommandPrefix(resolver);
            ImmutableList.Builder<String> cmd = ImmutableList.builder();
            Path src = scratchDir.resolve(resolver.getRelativePath(rootModule));
            cmd.addAll(compiler.getCommandPrefix(resolver)).addAll(executionContext.getAnsi().isAnsiTerminal() ? ImmutableList.of("--color=always") : ImmutableList.of()).add(String.format("-Clinker=%s", linkerCmd.get(0))).addAll(processLinkerArgs(linkerCmd.subList(1, linkerCmd.size()))).addAll(processLinkerArgs(Arg.stringify(linkerArgs, buildContext.getSourcePathResolver()))).addAll(Arg.stringify(args, buildContext.getSourcePathResolver())).add("-o", output.toString()).add(src.toString());
            return cmd.build();
        }

        /*
           * Make sure all stderr output from rustc is emitted, since its either a warning or an
           * error. In general Rust code should have zero warnings, or all warnings as errors.
           * Regardless, respect requests for silence.
           */
        @Override
        protected boolean shouldPrintStderr(Verbosity verbosity) {
            return !verbosity.isSilent();
        }

        @Override
        public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
            return compiler.getEnvironment(buildContext.getSourcePathResolver());
        }

        @Override
        public String getShortName() {
            return "rust-build";
        }
    });
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Verbosity(com.facebook.buck.util.Verbosity) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1042 List (java.util.List)287 ArrayList (java.util.ArrayList)160 Test (org.junit.Test)155 Path (java.nio.file.Path)149 Map (java.util.Map)142 ImmutableMap (com.google.common.collect.ImmutableMap)122 IOException (java.io.IOException)110 Set (java.util.Set)97 ImmutableSet (com.google.common.collect.ImmutableSet)96 SourcePath (com.facebook.buck.rules.SourcePath)91 Optional (java.util.Optional)87 HashMap (java.util.HashMap)80 Step (com.facebook.buck.step.Step)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)66 Collectors (java.util.stream.Collectors)60 File (java.io.File)57 HashSet (java.util.HashSet)55 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52