Search in sources :

Example 16 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.

the class GoBinary method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    // There is no way to specify real-ld environment variables to the go linker - just hope
    // that the two sets don't collide.
    ImmutableList<String> cxxLinkerCommand = ImmutableList.of();
    ImmutableMap.Builder<String, String> environment = ImmutableMap.builder();
    if (cxxLinker.isPresent()) {
        environment.putAll(cxxLinker.get().getEnvironment(context.getSourcePathResolver()));
        cxxLinkerCommand = cxxLinker.get().getCommandPrefix(context.getSourcePathResolver());
    }
    environment.putAll(linker.getEnvironment(context.getSourcePathResolver()));
    return ImmutableList.of(new MkdirStep(getProjectFilesystem(), output.getParent()), new GoLinkStep(getProjectFilesystem().getRootPath(), environment.build(), cxxLinkerCommand, linker.getCommandPrefix(context.getSourcePathResolver()), linkerFlags, ImmutableList.of(linkTree.getRoot()), platform, context.getSourcePathResolver().getRelativePath(mainObject.getSourcePathToOutput()), GoLinkStep.LinkMode.EXECUTABLE, output));
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 17 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.

the class GoCompile method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Path> compileSrcListBuilder = ImmutableList.builder();
    ImmutableList.Builder<Path> headerSrcListBuilder = ImmutableList.builder();
    ImmutableList.Builder<Path> asmSrcListBuilder = ImmutableList.builder();
    for (SourcePath path : srcs) {
        Path srcPath = context.getSourcePathResolver().getAbsolutePath(path);
        String extension = MorePaths.getFileExtension(srcPath).toLowerCase();
        if (extension.equals("s")) {
            asmSrcListBuilder.add(srcPath);
        } else if (extension.equals("go")) {
            compileSrcListBuilder.add(srcPath);
        } else {
            headerSrcListBuilder.add(srcPath);
        }
    }
    ImmutableList<Path> compileSrcs = compileSrcListBuilder.build();
    ImmutableList<Path> headerSrcs = headerSrcListBuilder.build();
    ImmutableList<Path> asmSrcs = asmSrcListBuilder.build();
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    Optional<Path> asmHeaderPath;
    if (!asmSrcs.isEmpty()) {
        asmHeaderPath = Optional.of(BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_hdr").resolve("go_asm.h"));
        steps.add(new MkdirStep(getProjectFilesystem(), asmHeaderPath.get().getParent()));
    } else {
        asmHeaderPath = Optional.empty();
    }
    boolean allowExternalReferences = !asmSrcs.isEmpty();
    if (compileSrcs.isEmpty()) {
        steps.add(new TouchStep(getProjectFilesystem(), output));
    } else {
        steps.add(new GoCompileStep(getProjectFilesystem().getRootPath(), compiler.getEnvironment(context.getSourcePathResolver()), compiler.getCommandPrefix(context.getSourcePathResolver()), compilerFlags, packageName, compileSrcs, importPathMap, ImmutableList.of(symlinkTree.getRoot()), asmHeaderPath, allowExternalReferences, platform, output));
    }
    if (!asmSrcs.isEmpty()) {
        Path asmIncludeDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_includes");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmIncludeDir));
        if (!headerSrcs.isEmpty()) {
            // TODO(mikekap): Allow header-map style input.
            for (Path header : FluentIterable.from(headerSrcs).append(asmSrcs)) {
                steps.add(new SymlinkFileStep(getProjectFilesystem(), header, asmIncludeDir.resolve(header.getFileName()), /* useAbsolutePaths */
                true));
            }
        }
        Path asmOutputDir = BuildTargets.getScratchPath(getProjectFilesystem(), getBuildTarget(), "%s/" + getBuildTarget().getShortName() + "__asm_compile");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), asmOutputDir));
        ImmutableList.Builder<Path> asmOutputs = ImmutableList.builder();
        for (Path asmSrc : asmSrcs) {
            Path outputPath = asmOutputDir.resolve(asmSrc.getFileName().toString().replaceAll("\\.[sS]$", ".o"));
            steps.add(new GoAssembleStep(getProjectFilesystem().getRootPath(), assembler.getEnvironment(context.getSourcePathResolver()), assembler.getCommandPrefix(context.getSourcePathResolver()), assemblerFlags, asmSrc, ImmutableList.<Path>builder().addAll(assemblerIncludeDirs).add(asmHeaderPath.get().getParent()).add(asmIncludeDir).build(), platform, outputPath));
            asmOutputs.add(outputPath);
        }
        steps.add(new GoPackStep(getProjectFilesystem().getRootPath(), packer.getEnvironment(context.getSourcePathResolver()), packer.getCommandPrefix(context.getSourcePathResolver()), GoPackStep.Operation.APPEND, asmOutputs.build(), output));
    }
    return steps.build();
}
Also used : ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SymlinkFileStep(com.facebook.buck.step.fs.SymlinkFileStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) SymlinkFileStep(com.facebook.buck.step.fs.SymlinkFileStep) TouchStep(com.facebook.buck.step.fs.TouchStep) TouchStep(com.facebook.buck.step.fs.TouchStep) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Example 18 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.

the class DefaultJavaLibrary method getBuildSteps.

/**
   * Building a java_library() rule entails compiling the .java files specified in the srcs
   * attribute. They are compiled into a directory under {@link BuckPaths#getScratchDir()}.
   */
@Override
public final ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    FluentIterable<JavaLibrary> declaredClasspathDeps = JavaLibraryClasspathProvider.getJavaLibraryDeps(getDepsForTransitiveClasspathEntries());
    // Always create the output directory, even if there are no .java files to compile because there
    // might be resources that need to be copied there.
    BuildTarget target = getBuildTarget();
    Path outputDirectory = getClassesDir(target, getProjectFilesystem());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory));
    SuggestBuildRules suggestBuildRule = DefaultSuggestBuildRules.createSuggestBuildFunction(JAR_RESOLVER, context.getSourcePathResolver(), declaredClasspathDeps.toSet(), ImmutableSet.<JavaLibrary>builder().addAll(getTransitiveClasspathDeps()).add(this).build(), context.getActionGraph().getNodes());
    // We don't want to add these to the declared or transitive deps, since they're only used at
    // compile time.
    Collection<Path> provided = JavaLibraryClasspathProvider.getJavaLibraryDeps(providedDeps).transformAndConcat(JavaLibrary::getOutputClasspaths).filter(Objects::nonNull).transform(context.getSourcePathResolver()::getAbsolutePath).toSet();
    Iterable<Path> declaredClasspaths = declaredClasspathDeps.transformAndConcat(JavaLibrary::getOutputClasspaths).transform(context.getSourcePathResolver()::getAbsolutePath);
    // Only override the bootclasspath if this rule is supposed to compile Android code.
    ImmutableSortedSet<Path> declared = ImmutableSortedSet.<Path>naturalOrder().addAll(declaredClasspaths).addAll(additionalClasspathEntries.stream().map(e -> e.isLeft() ? context.getSourcePathResolver().getAbsolutePath(e.getLeft()) : checkIsAbsolute(e.getRight())).collect(MoreCollectors.toImmutableSet())).addAll(provided).build();
    // Make sure that this directory exists because ABI information will be written here.
    Step mkdir = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToAbiOutputDir());
    steps.add(mkdir);
    // If there are resources, then link them to the appropriate place in the classes directory.
    JavaPackageFinder finder = context.getJavaPackageFinder();
    if (resourcesRoot.isPresent()) {
        finder = new ResourcesRootPackageFinder(resourcesRoot.get(), finder);
    }
    steps.add(new CopyResourcesStep(getProjectFilesystem(), context.getSourcePathResolver(), ruleFinder, target, resources, outputDirectory, finder));
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), getOutputJarDirPath(target, getProjectFilesystem())));
    // into the built jar.
    if (!getJavaSrcs().isEmpty()) {
        ClassUsageFileWriter usedClassesFileWriter;
        if (trackClassUsage) {
            final Path usedClassesFilePath = getUsedClassesFilePath(getBuildTarget(), getProjectFilesystem());
            depFileOutputPath = getProjectFilesystem().getPathForRelativePath(usedClassesFilePath);
            usedClassesFileWriter = new DefaultClassUsageFileWriter(usedClassesFilePath);
            buildableContext.recordArtifact(usedClassesFilePath);
        } else {
            usedClassesFileWriter = NoOpClassUsageFileWriter.instance();
        }
        // This adds the javac command, along with any supporting commands.
        Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
        steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
        Path scratchDir = BuildTargets.getGenPath(getProjectFilesystem(), target, "lib__%s____working_directory");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
        Optional<Path> workingDirectory = Optional.of(scratchDir);
        ImmutableSortedSet<Path> javaSrcs = getJavaSrcs().stream().map(context.getSourcePathResolver()::getRelativePath).collect(MoreCollectors.toImmutableSortedSet());
        compileStepFactory.createCompileToJarStep(context, javaSrcs, target, context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), declared, outputDirectory, workingDirectory, pathToSrcsList, Optional.of(suggestBuildRule), postprocessClassesCommands, ImmutableSortedSet.of(outputDirectory), /* mainClass */
        Optional.empty(), manifestFile.map(context.getSourcePathResolver()::getAbsolutePath), outputJar.get(), usedClassesFileWriter, /* output params */
        steps, buildableContext, classesToRemoveFromJar);
    }
    if (outputJar.isPresent()) {
        Path output = outputJar.get();
        // No source files, only resources
        if (getJavaSrcs().isEmpty()) {
            steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(outputDirectory), /* mainClass */
            null, manifestFile.map(context.getSourcePathResolver()::getAbsolutePath).orElse(null), true, classesToRemoveFromJar));
        }
        buildableContext.recordArtifact(output);
    }
    JavaLibraryRules.addAccumulateClassNamesStep(this, buildableContext, context.getSourcePathResolver(), steps);
    return steps.build();
}
Also used : ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) ClassPath(com.google.common.reflect.ClassPath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) BuildTarget(com.facebook.buck.model.BuildTarget) Objects(java.util.Objects) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SuggestBuildRules(com.facebook.buck.jvm.core.SuggestBuildRules)

Example 19 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep in project buck by facebook.

the class JsonConcatenate method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    return ImmutableList.<Step>builder().add(new MkdirStep(projectFilesystem, outputDirectory)).add(new JsonConcatenateStep(projectFilesystem, inputs, output, stepShortName, stepDescription)).build();
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 20 with MkdirStep

use of com.facebook.buck.step.fs.MkdirStep 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)

Aggregations

MkdirStep (com.facebook.buck.step.fs.MkdirStep)61 Path (java.nio.file.Path)44 SourcePath (com.facebook.buck.rules.SourcePath)43 Step (com.facebook.buck.step.Step)41 ImmutableList (com.google.common.collect.ImmutableList)38 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)34 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)27 RmStep (com.facebook.buck.step.fs.RmStep)20 CopyStep (com.facebook.buck.step.fs.CopyStep)14 ExecutionContext (com.facebook.buck.step.ExecutionContext)13 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)12 WriteFileStep (com.facebook.buck.step.fs.WriteFileStep)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 IOException (java.io.IOException)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)6 BuildTarget (com.facebook.buck.model.BuildTarget)5 AbstractBuildRule (com.facebook.buck.rules.AbstractBuildRule)5 PathSourcePath (com.facebook.buck.rules.PathSourcePath)5