diff options
author | 2015-09-04 16:15:19 +0000 | |
---|---|---|
committer | 2015-09-04 16:33:04 +0000 | |
commit | a708acd02baf3821c975801ae0e5cad6867a6735 (patch) | |
tree | 1be391b7c9fa3df12cdf29412b2abe71f250de95 /src | |
parent | d416ffeac5e81630688e31b7925e287354195b60 (diff) |
Teach Bazel to accept assembler-without-preprocessor source files.
Adding the accepted file extensions was a minor issue.
The bulk of this change was to weaken the assertion
that all cxx compiler actions produce a '.d' file.
RELNOTES[NEW]: a cc_binary rule may list '.s' and '.asm' files in the srcs
--
MOS_MIGRATED_REVID=102346882
Diffstat (limited to 'src')
7 files changed, 46 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java index 9e1b9e1995..5e4a7afa7a 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java @@ -27,6 +27,7 @@ import static com.google.devtools.build.lib.packages.Type.TRISTATE; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_LIBRARY; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_PIC_LIBRARY; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ARCHIVE; +import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ASSEMBLER; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.CPP_HEADER; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.CPP_SOURCE; @@ -78,6 +79,7 @@ public class BazelCppRuleClasses { C_SOURCE, CPP_HEADER, ASSEMBLER_WITH_C_PREPROCESSOR, + ASSEMBLER, ARCHIVE, PIC_ARCHIVE, ALWAYS_LINK_LIBRARY, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index aff5dd7143..8028abda49 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -63,6 +63,7 @@ public final class CcCommon { CppFileTypes.CPP_SOURCE, CppFileTypes.CPP_HEADER, CppFileTypes.C_SOURCE, + CppFileTypes.ASSEMBLER, CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR); /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index d2f2b6a630..dc79e25a9c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -133,8 +133,9 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable public static final String CPP_MODULE_COMPILE = "c++-module-compile"; /** - * A string constant for the preprocessing assembler action. + * A string constant for the assembler actions. */ + public static final String ASSEMBLE = "assemble"; public static final String PREPROCESS_ASSEMBLE = "preprocess-assemble"; @@ -227,7 +228,8 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable RuleContext ruleContext) { super(owner, createInputs(mandatoryInputs, context.getCompilationPrerequisites(), optionalSourceFile), - CollectionUtils.asListWithoutNulls(outputFile, dotdFile.artifact(), + CollectionUtils.asListWithoutNulls(outputFile, + (dotdFile == null ? null : dotdFile.artifact()), gcnoFile, dwoFile)); this.configuration = configuration; this.sourceLabel = sourceLabel; @@ -829,13 +831,14 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable private DependencySet processDepset(Path execRoot, CppCompileActionContext.Reply reply) throws IOException { + DotdFile dotdFile = getDotdFile(); + Preconditions.checkNotNull(dotdFile); DependencySet depSet = new DependencySet(execRoot); - - // artifact() is null if we are not using in-memory .d files. We also want to prepare for the + // artifact() is null if we are using in-memory .d files. We also want to prepare for the // case where we expected an in-memory .d file, but we did not get an appropriate response. // Perhaps we produced the file locally. - if (getDotdFile().artifact() != null || reply == null) { - return depSet.read(getDotdFile().getPath()); + if (dotdFile.artifact() != null || reply == null) { + return depSet.read(dotdFile.getPath()); } else { // This is an in-memory .d file. return depSet.process(reply.getContents()); @@ -854,14 +857,17 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable * * @param reply the reply from the compilation. * @param inputs the ordered collection of inputs to append to - * @throws ActionExecutionException iff the .d is missing, malformed or has - * unresolvable included artifacts. + * @throws ActionExecutionException iff the .d is missing (when required), + * malformed, or has unresolvable included artifacts. */ @ThreadCompatible private void populateActionInputs(Path execRoot, ArtifactResolver artifactResolver, CppCompileActionContext.Reply reply, NestedSetBuilder<Artifact> inputs) throws ActionExecutionException { + if (getDotdFile() == null) { + return; + } try { // Read .d file. DependencySet depSet = processDepset(execRoot, reply); @@ -1193,7 +1199,8 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable CcToolchainFeatures.Variables variables, @Nullable String fdoBuildStamp) { this.sourceFile = Preconditions.checkNotNull(sourceFile); - this.dotdFile = Preconditions.checkNotNull(dotdFile); + this.dotdFile = CppFileTypes.mustProduceDotdFile(sourceFile.getPath().toString()) + ? Preconditions.checkNotNull(dotdFile) : null; this.copts = Preconditions.checkNotNull(copts); this.coptsFilter = coptsFilter; this.pluginOpts = Preconditions.checkNotNull(pluginOpts); @@ -1243,6 +1250,8 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable return C_COMPILE; } else if (CppFileTypes.CPP_SOURCE.matches(sourcePath)) { return CPP_COMPILE; + } else if (CppFileTypes.ASSEMBLER.matches(sourcePath)) { + return ASSEMBLE; } else if (CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches(sourcePath)) { return PREPROCESS_ASSEMBLE; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index a943057030..ab1196c1f7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -382,13 +382,17 @@ public class CppCompileActionBuilder { } public CppCompileActionBuilder setDotdFile(PathFragment outputName, String extension) { - if (configuration.getFragment(CppConfiguration.class).getInmemoryDotdFiles()) { - // Just set the path, no artifact is constructed - PathFragment file = FileSystemUtils.replaceExtension(outputName, extension); - Root root = configuration.getBinDirectory(); - dotdFile = new DotdFile(root.getExecPath().getRelative(file)); + if (CppFileTypes.mustProduceDotdFile(outputName.toString())) { + if (configuration.getFragment(CppConfiguration.class).getInmemoryDotdFiles()) { + // Just set the path, no artifact is constructed + PathFragment file = FileSystemUtils.replaceExtension(outputName, extension); + Root root = configuration.getBinDirectory(); + dotdFile = new DotdFile(root.getExecPath().getRelative(file)); + } else { + dotdFile = new DotdFile(ruleContext.getRelatedArtifact(outputName, extension)); + } } else { - dotdFile = new DotdFile(ruleContext.getRelatedArtifact(outputName, extension)); + dotdFile = null; } return this; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 655dcd5f1a..a7e3a1a1da 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -59,11 +59,12 @@ public final class CppFileTypes { final String ext = ".s"; @Override public boolean apply(String filename) { - return filename.endsWith(ext) && !PIC_ASSEMBLER.matches(filename); + return (filename.endsWith(ext) && !PIC_ASSEMBLER.matches(filename)) + || filename.endsWith(".asm"); } @Override public List<String> getExtensions() { - return ImmutableList.of(ext); + return ImmutableList.of(ext, ".asm"); } }; @@ -139,4 +140,8 @@ public final class CppFileTypes { // Output of the dwp tool public static final FileType DEBUG_INFO_PACKAGE = FileType.of(".dwp"); + + public static final boolean mustProduceDotdFile(String source) { + return !(ASSEMBLER.matches(source) || PIC_ASSEMBLER.matches(source)); + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index de1c92ce96..f651f629cc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fro import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_LIBRARY; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ALWAYS_LINK_PIC_LIBRARY; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ARCHIVE; +import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ASSEMBLER; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.CPP_HEADER; import static com.google.devtools.build.lib.rules.cpp.CppFileTypes.CPP_SOURCE; @@ -54,7 +55,8 @@ public class CppRuleClasses { * those. */ static final InstrumentationSpec INSTRUMENTATION_SPEC = new InstrumentationSpec( - FileTypeSet.of(CPP_SOURCE, C_SOURCE, CPP_HEADER, ASSEMBLER_WITH_C_PREPROCESSOR), + FileTypeSet.of(CPP_SOURCE, C_SOURCE, CPP_HEADER, ASSEMBLER_WITH_C_PREPROCESSOR, + ASSEMBLER), "srcs", "deps", "data", "hdrs"); public static final LibraryLanguage LANGUAGE = new LibraryLanguage("C++"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LocalGccStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LocalGccStrategy.java index 7b1cd6fef4..d9be59b264 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LocalGccStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LocalGccStrategy.java @@ -46,7 +46,11 @@ public class LocalGccStrategy implements CppCompileActionContext { public static void updateEnv(CppCompileAction action, Map<String, String> env) { // We cannot locally execute an action that does not expect to output a .d file, since we would // have no way to tell what files that it included were used during compilation. - env.put("INTERCEPT_LOCALLY_EXECUTABLE", action.getDotdFile().artifact() == null ? "0" : "1"); + // The exception to this is that if no .d file can be produced (as indicated by + // dotdfile == null), then the assumption is that there are truly no depencies, + // and therefore we don't care whether the step executes locally or remotely. + env.put("INTERCEPT_LOCALLY_EXECUTABLE", + (action.getDotdFile() != null && action.getDotdFile().artifact() == null) ? "0" : "1"); } @Override |