Search in sources :

Example 1 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class DexArchiveAspect method createDesugarAction.

private static Artifact createDesugarAction(RuleContext ruleContext, String desugarPrereqName, Artifact jar, ImmutableList<Artifact> bootclasspath, NestedSet<Artifact> classpath, Artifact result) {
    CustomCommandLine args = new CustomCommandLine.Builder().addExecPath("--input", jar).addExecPath("--output", result).addBeforeEachExecPath("--classpath_entry", classpath).addBeforeEachExecPath("--bootclasspath_entry", bootclasspath).build();
    // Just use params file, since classpaths can get long
    Artifact paramFile = ruleContext.getDerivedArtifact(ParameterFile.derivePath(result.getRootRelativePath()), result.getRoot());
    ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, args, ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
    ruleContext.registerAction(new SpawnAction.Builder().setExecutable(ruleContext.getExecutablePrerequisite(desugarPrereqName, Mode.HOST)).addArgument("@" + paramFile.getExecPathString()).addInput(jar).addInput(paramFile).addInputs(bootclasspath).addTransitiveInputs(classpath).addOutput(result).setMnemonic("Desugar").setProgressMessage("Desugaring " + jar.prettyPrint() + " for Android").build(ruleContext));
    return result;
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) ParameterFileWriteAction(com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 2 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class LegacyCompilationSupport method registerCompileActionTemplate.

/**
   * Registers a SpawnActionTemplate to compile the source file tree artifact, {@code sourceFiles},
   * which can contain multiple concrete source files unknown at analysis time. At execution time,
   * the SpawnActionTemplate will register one ObjcCompile action for each individual source file
   * under {@code sourceFiles}.
   *
   * <p>Note that this method currently does not support code coverage and sources other than ObjC
   * sources.
   *
   * @param sourceFiles tree artifact containing source files to compile
   * @param objFiles tree artifact containing object files compiled from {@code sourceFiles}
   * @param objcProvider ObjcProvider instance for this invocation
   * @param priorityHeaders priority headers to be included before the dependency headers
   * @param moduleMap the module map generated from the associated headers
   * @param compilationArtifacts the CompilationArtifacts instance for this invocation
   * @param otherFlags extra compilation flags to add to the compile action command line
   */
private void registerCompileActionTemplate(Artifact sourceFiles, Artifact objFiles, ObjcProvider objcProvider, Iterable<PathFragment> priorityHeaders, Optional<CppModuleMap> moduleMap, CompilationArtifacts compilationArtifacts, Iterable<String> otherFlags) {
    CustomCommandLine commandLine = compileActionCommandLine(sourceFiles, objFiles, objcProvider, priorityHeaders, moduleMap, compilationArtifacts.getPchFile(), Optional.<Artifact>absent(), otherFlags, /* runCodeCoverage=*/
    false, /* isCPlusPlusSource=*/
    false);
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    Platform platform = appleConfiguration.getSingleArchPlatform();
    NestedSet<Artifact> moduleMapInputs = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
    if (objcConfiguration.moduleMapsEnabled()) {
        moduleMapInputs = objcProvider.get(MODULE_MAP);
    }
    ruleContext.registerAction(new SpawnActionTemplate.Builder(sourceFiles, objFiles).setMnemonics("ObjcCompileActionTemplate", "ObjcCompile").setExecutable(xcrunwrapper(ruleContext)).setCommandLineTemplate(commandLine).setEnvironment(ObjcRuleClasses.appleToolchainEnvironment(appleConfiguration, platform)).setExecutionInfo(ObjcRuleClasses.darwinActionExecutionRequirement()).setOutputPathMapper(COMPILE_ACTION_TEMPLATE_OUTPUT_PATH_MAPPER).addCommonTransitiveInputs(objcProvider.get(HEADER)).addCommonTransitiveInputs(moduleMapInputs).addCommonInputs(compilationArtifacts.getPrivateHdrs()).addCommonTransitiveInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addCommonTransitiveInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).addCommonInputs(compilationArtifacts.getPchFile().asSet()).build(ruleContext.getActionOwner()));
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) Platform(com.google.devtools.build.lib.rules.apple.Platform) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) AppleConfiguration(com.google.devtools.build.lib.rules.apple.AppleConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 3 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine 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));
    }
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) ParameterFileWriteAction(com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 4 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class CustomCommandLineTest method testArtifactExecPathArgs.

@Test
public void testArtifactExecPathArgs() {
    CustomCommandLine cl = CustomCommandLine.builder().addExecPath("--path", artifact1).build();
    assertEquals(ImmutableList.of("--path", "dir/file1.txt"), cl.arguments());
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) Test(org.junit.Test)

Example 5 with CustomCommandLine

use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.

the class CustomCommandLineTest method testTreeFileArtifactArgThrowWithoutSubstitution.

@Test
public void testTreeFileArtifactArgThrowWithoutSubstitution() {
    Artifact treeArtifactOne = createTreeArtifact("myArtifact/treeArtifact1");
    Artifact treeArtifactTwo = createTreeArtifact("myArtifact/treeArtifact2");
    CustomCommandLine commandLineTemplate = CustomCommandLine.builder().addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne).addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo).build();
    try {
        commandLineTemplate.arguments();
        fail("No substitution map provided, expected NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)28 Test (org.junit.Test)22 Artifact (com.google.devtools.build.lib.actions.Artifact)6 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)5 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)3 ParameterFileWriteAction (com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction)3 ToolchainInvocation (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation)3 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)2 LazyString (com.google.devtools.build.lib.util.LazyString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 CustomArgv (com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomArgv)1 CustomMultiArgv (com.google.devtools.build.lib.analysis.actions.CustomCommandLine.CustomMultiArgv)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 AppleConfiguration (com.google.devtools.build.lib.rules.apple.AppleConfiguration)1 Platform (com.google.devtools.build.lib.rules.apple.Platform)1 DotdFile (com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 HashSet (java.util.HashSet)1