use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class J2ObjcAspect method createJ2ObjcTranspilationAction.
private static J2ObjcMappingFileProvider createJ2ObjcTranspilationAction(RuleContext ruleContext, Iterable<Artifact> sources, Iterable<Artifact> sourceJars, J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider, JavaCompilationArgsProvider compArgsProvider, J2ObjcSource j2ObjcSource) {
CustomCommandLine.Builder argBuilder = CustomCommandLine.builder();
PathFragment javaExecutable = ruleContext.getFragment(Jvm.class, HOST).getJavaExecutable();
argBuilder.add("--java").add(javaExecutable.getPathString());
Artifact j2ObjcDeployJar = ruleContext.getPrerequisiteArtifact("$j2objc", Mode.HOST);
argBuilder.addExecPath("--j2objc", j2ObjcDeployJar);
argBuilder.add("--main_class").add("com.google.devtools.j2objc.J2ObjC");
argBuilder.add("--objc_file_path").addPath(j2ObjcSource.getObjcFilePath());
Artifact outputDependencyMappingFile = j2ObjcOutputDependencyMappingFile(ruleContext);
argBuilder.addExecPath("--output_dependency_mapping_file", outputDependencyMappingFile);
ImmutableList.Builder<Artifact> sourceJarOutputFiles = ImmutableList.builder();
if (!Iterables.isEmpty(sourceJars)) {
sourceJarOutputFiles.addAll(sourceJarOutputs(ruleContext));
argBuilder.addJoinExecPaths("--src_jars", ",", sourceJars);
argBuilder.add(sourceJarFlags(ruleContext));
}
Iterable<String> translationFlags = ruleContext.getFragment(J2ObjcConfiguration.class).getTranslationFlags();
argBuilder.add(translationFlags);
NestedSet<Artifact> depsHeaderMappingFiles = depJ2ObjcMappingFileProvider.getHeaderMappingFiles();
if (!depsHeaderMappingFiles.isEmpty()) {
argBuilder.addJoinExecPaths("--header-mapping", ",", depsHeaderMappingFiles);
}
Artifact outputHeaderMappingFile = j2ObjcOutputHeaderMappingFile(ruleContext);
argBuilder.addExecPath("--output-header-mapping", outputHeaderMappingFile);
NestedSet<Artifact> depsClassMappingFiles = depJ2ObjcMappingFileProvider.getClassMappingFiles();
if (!depsClassMappingFiles.isEmpty()) {
argBuilder.addJoinExecPaths("--mapping", ",", depsClassMappingFiles);
}
Artifact archiveSourceMappingFile = j2ObjcOutputArchiveSourceMappingFile(ruleContext);
argBuilder.addExecPath("--output_archive_source_mapping_file", archiveSourceMappingFile);
Artifact compiledLibrary = ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext).archive();
argBuilder.addExecPath("--compiled_archive_file_path", compiledLibrary);
Artifact bootclasspathJar = ruleContext.getPrerequisiteArtifact("$jre_emul_jar", Mode.HOST);
argBuilder.add("-Xbootclasspath:" + bootclasspathJar.getExecPathString());
argBuilder.add("-d").addPath(j2ObjcSource.getObjcFilePath());
NestedSet<Artifact> compileTimeJars = compArgsProvider.getRecursiveJavaCompilationArgs().getCompileTimeJars();
if (!compileTimeJars.isEmpty()) {
argBuilder.addJoinExecPaths("-classpath", ":", compileTimeJars);
}
argBuilder.addExecPaths(sources);
Artifact paramFile = j2ObjcOutputParamFile(ruleContext);
ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, argBuilder.build(), ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
SpawnAction.Builder builder = new SpawnAction.Builder().setMnemonic("TranspilingJ2objc").setExecutable(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST)).addInput(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST)).addInput(j2ObjcDeployJar).addInput(bootclasspathJar).addInputs(sources).addInputs(sourceJars).addTransitiveInputs(compileTimeJars).addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext)).addTransitiveInputs(depsHeaderMappingFiles).addTransitiveInputs(depsClassMappingFiles).addInput(paramFile).setCommandLine(CustomCommandLine.builder().addPaths("@%s", paramFile.getExecPath()).build()).addOutputs(j2ObjcSource.getObjcSrcs()).addOutputs(j2ObjcSource.getObjcHdrs()).addOutput(outputHeaderMappingFile).addOutput(outputDependencyMappingFile).addOutput(archiveSourceMappingFile);
ruleContext.registerAction(builder.build(ruleContext));
return new J2ObjcMappingFileProvider(NestedSetBuilder.<Artifact>stableOrder().add(outputHeaderMappingFile).build(), NestedSetBuilder.<Artifact>stableOrder().build(), NestedSetBuilder.<Artifact>stableOrder().add(outputDependencyMappingFile).build(), NestedSetBuilder.<Artifact>stableOrder().add(archiveSourceMappingFile).build());
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class J2ObjcSource method toPrunedSource.
/**
* Returns a corresponding {@link J2ObjcSource} with source artifacts replaced by the outputs of
* the J2objC dead code removal script, for use after that action has processed the originals.
*
* <p>The script in question builds a dependency graph with entry classes specified
* transitively on j2objc_library rules as roots. Translated files from this (original)
* {@link J2ObjcSource} which are reachable in the graph from the roots will be copied over to the
* source file paths in the returned pruned {@link J2ObjcSource} with full original contents.
* Unreachable files will not be copied over and the artifacts pointed to by the returned pruned
* {@link J2ObjcSource} will only contain empty files.
*
* @param ruleContext the {@link RuleContext} of the current rule
*/
public J2ObjcSource toPrunedSource(RuleContext ruleContext) {
ImmutableList.Builder<Artifact> prunedSourceArtifacts = ImmutableList.builder();
for (Artifact sourceArtifact : getObjcSrcs()) {
PathFragment prunedSourceArtifactPath = FileSystemUtils.appendWithoutExtension(sourceArtifact.getRootRelativePath(), "_pruned");
Artifact prunedArtifact = ruleContext.getUniqueDirectoryArtifact("_j2objc_pruned", prunedSourceArtifactPath, ruleContext.getBinOrGenfilesDirectory());
prunedSourceArtifacts.add(prunedArtifact);
}
return new J2ObjcSource(getTargetLabel(), prunedSourceArtifacts.build(), getObjcHdrs(), getObjcFilePath(), getSourceType(), getHeaderSearchPaths());
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class LegacyCompilationSupport method linkCommandLine.
private CommandLine linkCommandLine(ExtraLinkArgs extraLinkArgs, ObjcProvider objcProvider, Artifact linkedBinary, Optional<Artifact> dsymBundleZip, Iterable<Artifact> ccLibraries, Iterable<Artifact> bazelBuiltLibraries, Optional<Artifact> linkmap, Optional<Artifact> bitcodeSymbolMap) {
Iterable<String> libraryNames = libraryNames(objcProvider);
CustomCommandLine.Builder commandLine = CustomCommandLine.builder().addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath());
if (objcProvider.is(USES_CPP)) {
commandLine.add(CLANG_PLUSPLUS).add("-stdlib=libc++").add("-std=gnu++11");
} else {
commandLine.add(CLANG);
}
// Do not perform code stripping on tests because XCTest binary is linked not as an executable
// but as a bundle without any entry point.
boolean isTestTarget = TargetUtils.isTestRule(ruleContext.getRule());
if (objcConfiguration.shouldStripBinary() && !isTestTarget) {
commandLine.add("-dead_strip").add("-no_dead_strip_inits_and_terms");
}
Iterable<Artifact> ccLibrariesToForceLoad = Iterables.filter(ccLibraries, ALWAYS_LINKED_CC_LIBRARY);
ImmutableSet<Artifact> forceLinkArtifacts = ImmutableSet.<Artifact>builder().addAll(objcProvider.get(FORCE_LOAD_LIBRARY)).addAll(ccLibrariesToForceLoad).build();
Artifact inputFileList = intermediateArtifacts.linkerObjList();
Iterable<Artifact> objFiles = Iterables.concat(bazelBuiltLibraries, objcProvider.get(IMPORTED_LIBRARY), ccLibraries);
// Clang loads archives specified in filelists and also specified as -force_load twice,
// resulting in duplicate symbol errors unless they are deduped.
objFiles = Iterables.filter(objFiles, Predicates.not(Predicates.in(forceLinkArtifacts)));
registerObjFilelistAction(objFiles, inputFileList);
if (objcConfiguration.shouldPrioritizeStaticLibs()) {
commandLine.add("-filelist").add(inputFileList.getExecPathString());
}
AppleBitcodeMode bitcodeMode = appleConfiguration.getBitcodeMode();
commandLine.add(bitcodeMode.getCompileAndLinkFlags());
if (bitcodeMode == AppleBitcodeMode.EMBEDDED) {
commandLine.add("-Xlinker").add("-bitcode_verify");
commandLine.add("-Xlinker").add("-bitcode_hide_symbols");
commandLine.add("-Xlinker").add("-bitcode_symbol_map").add("-Xlinker").add(bitcodeSymbolMap.get().getExecPathString());
}
commandLine.add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration)).add("-Xlinker").add("-objc_abi_version").add("-Xlinker").add("2").add("-Xlinker").add("-rpath").add("-Xlinker").add("@executable_path/Frameworks").add("-fobjc-link-runtime").add(DEFAULT_LINKER_FLAGS).addBeforeEach("-framework", frameworkNames(objcProvider)).addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK))).addFormatEach("-l%s", libraryNames);
if (!objcConfiguration.shouldPrioritizeStaticLibs()) {
commandLine.add("-filelist").add(inputFileList.getExecPathString());
}
commandLine.addExecPath("-o", linkedBinary).addBeforeEachExecPath("-force_load", forceLinkArtifacts).add(extraLinkArgs).add(objcProvider.get(ObjcProvider.LINKOPT));
if (buildConfiguration.isCodeCoverageEnabled()) {
if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) {
commandLine.add(LINKER_LLVM_COVERAGE_FLAGS);
} else {
commandLine.add(LINKER_COVERAGE_FLAGS);
}
}
for (String linkopt : attributes.linkopts()) {
commandLine.add("-Wl," + linkopt);
}
if (linkmap.isPresent()) {
commandLine.add("-Xlinker -map").add("-Xlinker " + linkmap.get().getExecPath());
}
// absolute paths to archive files, which are only valid in the link action.
if (dsymBundleZip.isPresent()) {
PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundleZip.get().getExecPath());
commandLine.add("&&").addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()).add(DSYMUTIL).add(linkedBinary.getExecPathString()).add("-o " + dsymPath).add("&& zipped_bundle=${PWD}/" + dsymBundleZip.get().getShellEscapedExecPathString()).add("&& cd " + dsymPath).add("&& /usr/bin/zip -q -r \"${zipped_bundle}\" .");
}
return commandLine.build();
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class CompilationAttributes method headerSearchPaths.
/**
* Returns the exec paths of all header search paths that should be added to this target and
* dependers on this target, obtained from the {@code includes} attribute.
*/
public NestedSet<PathFragment> headerSearchPaths(PathFragment genfilesFragment) {
NestedSetBuilder<PathFragment> paths = NestedSetBuilder.stableOrder();
if (packageFragment.isPresent()) {
List<PathFragment> rootFragments = ImmutableList.of(packageFragment.get(), genfilesFragment.getRelative(packageFragment.get()));
Iterable<PathFragment> relativeIncludes = Iterables.filter(includes(), Predicates.not(PathFragment.IS_ABSOLUTE));
for (PathFragment include : relativeIncludes) {
for (PathFragment rootFragment : rootFragments) {
paths.add(rootFragment.getRelative(include).normalize());
}
}
}
return paths.build();
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class CompilationSupport method registerJ2ObjcDeadCodeRemovalActions.
/**
* Registers actions to perform J2Objc dead code removal.
*/
protected void registerJ2ObjcDeadCodeRemovalActions(ObjcProvider objcProvider, J2ObjcMappingFileProvider j2ObjcMappingFileProvider, J2ObjcEntryClassProvider j2ObjcEntryClassProvider) {
NestedSet<String> entryClasses = j2ObjcEntryClassProvider.getEntryClasses();
Artifact pruner = ruleContext.getPrerequisiteArtifact("$j2objc_dead_code_pruner", Mode.HOST);
NestedSet<Artifact> j2ObjcDependencyMappingFiles = j2ObjcMappingFileProvider.getDependencyMappingFiles();
NestedSet<Artifact> j2ObjcHeaderMappingFiles = j2ObjcMappingFileProvider.getHeaderMappingFiles();
NestedSet<Artifact> j2ObjcArchiveSourceMappingFiles = j2ObjcMappingFileProvider.getArchiveSourceMappingFiles();
for (Artifact j2objcArchive : objcProvider.get(ObjcProvider.J2OBJC_LIBRARY)) {
PathFragment paramFilePath = FileSystemUtils.replaceExtension(j2objcArchive.getOwner().toPathFragment(), ".param.j2objc");
Artifact paramFile = ruleContext.getUniqueDirectoryArtifact("_j2objc_pruned", paramFilePath, buildConfiguration.getBinDirectory(ruleContext.getRule().getRepository()));
Artifact prunedJ2ObjcArchive = intermediateArtifacts.j2objcPrunedArchive(j2objcArchive);
Artifact dummyArchive = Iterables.getOnlyElement(ruleContext.getPrerequisite("$dummy_lib", Mode.TARGET, ObjcProvider.class).get(LIBRARY));
CustomCommandLine commandLine = CustomCommandLine.builder().addExecPath("--input_archive", j2objcArchive).addExecPath("--output_archive", prunedJ2ObjcArchive).addExecPath("--dummy_archive", dummyArchive).addExecPath("--xcrunwrapper", xcrunwrapper(ruleContext).getExecutable()).addJoinExecPaths("--dependency_mapping_files", ",", j2ObjcDependencyMappingFiles).addJoinExecPaths("--header_mapping_files", ",", j2ObjcHeaderMappingFiles).addJoinExecPaths("--archive_source_mapping_files", ",", j2ObjcArchiveSourceMappingFiles).add("--entry_classes").add(Joiner.on(",").join(entryClasses)).build();
ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, commandLine, ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(appleConfiguration, appleConfiguration.getSingleArchPlatform()).setMnemonic("DummyPruner").setExecutable(pruner).addInput(dummyArchive).addInput(pruner).addInput(paramFile).addInput(j2objcArchive).addInput(xcrunwrapper(ruleContext).getExecutable()).addTransitiveInputs(j2ObjcDependencyMappingFiles).addTransitiveInputs(j2ObjcHeaderMappingFiles).addTransitiveInputs(j2ObjcArchiveSourceMappingFiles).setCommandLine(CustomCommandLine.builder().addPaths("@%s", paramFile.getExecPath()).build()).addOutput(prunedJ2ObjcArchive).build(ruleContext));
}
}
Aggregations