use of com.facebook.buck.step.fs.SymlinkFileStep 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();
}
use of com.facebook.buck.step.fs.SymlinkFileStep in project buck by facebook.
the class JarFattener method getBuildSteps.
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
ImmutableList.Builder<Step> steps = ImmutableList.builder();
Path outputDir = getOutputDirectory();
Path fatJarDir = outputDir.resolve("fat-jar-directory");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDir));
// Map of the system-specific shared library name to it's resource name as a string.
ImmutableMap.Builder<String, String> sonameToResourceMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, SourcePath> entry : nativeLibraries.entrySet()) {
String resource = FAT_JAR_NATIVE_LIBRARY_RESOURCE_ROOT + "/" + entry.getKey();
sonameToResourceMapBuilder.put(entry.getKey(), resource);
steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(resource).getParent()));
steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(entry.getValue()), fatJarDir.resolve(resource), /* useAbsolutePaths */
true));
}
ImmutableMap<String, String> sonameToResourceMap = sonameToResourceMapBuilder.build();
// Grab the source path representing the fat jar info resource.
Path fatJarInfo = fatJarDir.resolve(FatJar.FAT_JAR_INFO_RESOURCE);
steps.add(writeFatJarInfo(fatJarInfo, sonameToResourceMap));
// Build up the resource and src collections.
Set<Path> javaSourceFilePaths = Sets.newHashSet();
for (String srcResource : FAT_JAR_SRC_RESOURCES) {
Path fatJarSource = outputDir.resolve(Paths.get(srcResource).getFileName());
javaSourceFilePaths.add(fatJarSource);
steps.add(writeFromResource(fatJarSource, srcResource));
}
Path fatJarMainSource = outputDir.resolve(Paths.get(FAT_JAR_MAIN_SRC_RESOURCE).getFileName());
javaSourceFilePaths.add(fatJarMainSource);
steps.add(writeFromResource(fatJarMainSource, FAT_JAR_MAIN_SRC_RESOURCE));
// Symlink the inner JAR into it's place in the fat JAR.
steps.add(new MkdirStep(getProjectFilesystem(), fatJarDir.resolve(FAT_JAR_INNER_JAR).getParent()));
steps.add(new SymlinkFileStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(innerJar), fatJarDir.resolve(FAT_JAR_INNER_JAR), /* useAbsolutePaths */
true));
// Build the final fat JAR from the structure we've layed out above. We first package the
// fat jar resources (e.g. native libs) using the "stored" compression level, to avoid
// expensive compression on builds and decompression on startup.
Path zipped = outputDir.resolve("contents.zip");
Step zipStep = new ZipStep(getProjectFilesystem(), zipped, ImmutableSet.of(), false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, fatJarDir);
Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));
CompileToJarStepFactory compileStepFactory = new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY);
compileStepFactory.createCompileStep(context, ImmutableSortedSet.copyOf(javaSourceFilePaths), getBuildTarget(), context.getSourcePathResolver(), ruleFinder, getProjectFilesystem(), /* classpathEntries */
ImmutableSortedSet.of(), fatJarDir, /* workingDir */
Optional.empty(), pathToSrcsList, /* suggestBuildRule */
Optional.empty(), NoOpClassUsageFileWriter.instance(), steps, buildableContext);
steps.add(zipStep);
steps.add(new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(zipped), /* mainClass */
FatJarMain.class.getName(), /* manifestFile */
null));
return steps.build();
}
Aggregations