aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar pcloudy <pcloudy@google.com>2018-03-23 07:05:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-23 07:07:18 -0700
commitbb9ae6a174b8cd255a62249f01919426f1d817f8 (patch)
treef21cc2f6ff0f6ca6937eefa585bfb5ca8b4e6678 /src/main/java/com
parent8f5327af7940dc46f04acfe07448256dca164006 (diff)
Shorten object file path
Closes #4781. Fix https://github.com/bazelbuild/bazel/issues/4149 RELNOTES: Users can now pass --experimental_shortened_obj_file_path=true to have a shorter object file path, the object file paths (and all other related paths) will be constructed as following: If there's no two or more source files with the same base name: <bazel-bin>/<target_package_path>/_objs/<target_name>/<source_base_name>.<extension> otherwise: <bazel-bin>/<target_package_path>/_objs/<target_name>/N/<source_base_name>.<extension> N = the file?s order among the source files with the same basename, starts from 0. Examples: 1. Output names for ["lib1/foo.cc", "lib2/bar.cc"] are ["foo", "bar"] 2. Output names for ["foo.cc", "bar.cc", "foo.cpp", "lib/foo.cc"] are ["0/foo", "bar", "1/foo", "2/foo"] The default value of --experimental_shortened_obj_file_path option is false, but we plan to flip it to true and eventually remove this option. You shouldn't depend on the format of generated object file path, but if you do and this change breaks you, please use --experimental_shortened_obj_file_path=false to work around it. PiperOrigin-RevId: 190214375
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java58
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java16
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/ObjectFilePathHelper.java90
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java47
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java29
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java2
9 files changed, 201 insertions, 57 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
index f71585a731..2b9910bf84 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java
@@ -70,6 +70,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
@@ -1305,14 +1306,22 @@ public final class CcCompilationHelper {
/** @return the non-pic header module artifact for the current target. */
private Artifact getHeaderModule(Artifact moduleMapArtifact) {
PathFragment objectDir = CppHelper.getObjDirectory(ruleContext.getLabel());
- PathFragment outputName = objectDir.getRelative(moduleMapArtifact.getRootRelativePath());
+ PathFragment outputName =
+ objectDir.getRelative(
+ cppConfiguration.shortenObjFilePath()
+ ? moduleMapArtifact.getRootRelativePath().getBaseName()
+ : moduleMapArtifact.getRootRelativePath().getPathString());
return ruleContext.getRelatedArtifact(outputName, ".pcm");
}
/** @return the pic header module artifact for the current target. */
private Artifact getPicHeaderModule(Artifact moduleMapArtifact) {
PathFragment objectDir = CppHelper.getObjDirectory(ruleContext.getLabel());
- PathFragment outputName = objectDir.getRelative(moduleMapArtifact.getRootRelativePath());
+ PathFragment outputName =
+ objectDir.getRelative(
+ cppConfiguration.shortenObjFilePath()
+ ? moduleMapArtifact.getRootRelativePath().getBaseName()
+ : moduleMapArtifact.getRootRelativePath().getPathString());
return ruleContext.getRelatedArtifact(outputName, ".pic.pcm");
}
@@ -1346,11 +1355,25 @@ public final class CcCompilationHelper {
}
}
+ String outputNamePrefixDir = null;
+ // purpose is only used by objc rules, it ends with either "_non_objc_arc" or "_objc_arc".
+ // Here we use it to distinguish arc and non-arc compilation.
+ if (purpose != null) {
+ outputNamePrefixDir = purpose.endsWith("_non_objc_arc") ? "non_arc" : "arc";
+ }
+
+ ObjectFilePathHelper objectFilePathHelper =
+ new ObjectFilePathHelper(
+ compilationUnitSources
+ .stream()
+ .map(source -> source.getSource())
+ .collect(Collectors.toList()),
+ cppConfiguration.shortenObjFilePath(),
+ outputNamePrefixDir);
+
for (CppSource source : compilationUnitSources) {
Artifact sourceArtifact = source.getSource();
Label sourceLabel = source.getLabel();
- String outputName =
- FileSystemUtils.removeExtension(sourceArtifact.getRootRelativePath()).getPathString();
CppCompileActionBuilder builder = initializeCompileAction(sourceArtifact);
builder
@@ -1362,6 +1385,8 @@ public final class CcCompilationHelper {
featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)
&& CppFileTypes.LTO_SOURCE.matches(sourceArtifact.getFilename());
+ String outputName = objectFilePathHelper.getOutputName(sourceArtifact);
+
if (!sourceArtifact.isTreeArtifact()) {
switch (source.getType()) {
case HEADER:
@@ -1401,6 +1426,7 @@ public final class CcCompilationHelper {
createCompileActionTemplate(
env,
source,
+ outputName,
builder,
ImmutableList.of(
ArtifactCategory.GENERATED_HEADER, ArtifactCategory.PROCESSED_HEADER),
@@ -1410,7 +1436,12 @@ public final class CcCompilationHelper {
case SOURCE:
Artifact objectFile =
createCompileActionTemplate(
- env, source, builder, ImmutableList.of(ArtifactCategory.OBJECT_FILE), false);
+ env,
+ source,
+ outputName,
+ builder,
+ ImmutableList.of(ArtifactCategory.OBJECT_FILE),
+ false);
result.addObjectFile(objectFile);
if (getGeneratePicActions()) {
@@ -1418,6 +1449,7 @@ public final class CcCompilationHelper {
createCompileActionTemplate(
env,
source,
+ outputName,
builder,
ImmutableList.of(ArtifactCategory.PIC_OBJECT_FILE),
true);
@@ -1437,12 +1469,13 @@ public final class CcCompilationHelper {
private Artifact createCompileActionTemplate(
AnalysisEnvironment env,
CppSource source,
+ String outputName,
CppCompileActionBuilder builder,
Iterable<ArtifactCategory> outputCategories,
boolean usePic) {
SpecialArtifact sourceArtifact = (SpecialArtifact) source.getSource();
SpecialArtifact outputFiles =
- CppHelper.getCompileOutputTreeArtifact(ruleContext, sourceArtifact, usePic);
+ CppHelper.getCompileOutputTreeArtifact(ruleContext, sourceArtifact, outputName, usePic);
// TODO(rduan): Dotd file output is not supported yet.
builder.setOutputs(outputFiles, /* dotdFile= */ null);
setupCompileBuildVariables(
@@ -1659,7 +1692,10 @@ public final class CcCompilationHelper {
// If we find one, support needs to be added here.
return;
}
- String outputName = module.getRootRelativePath().getPathString();
+ String outputName =
+ cppConfiguration.shortenObjFilePath()
+ ? module.getRootRelativePath().getBaseName()
+ : module.getRootRelativePath().getPathString();
// TODO(djasper): Make this less hacky after refactoring how the PIC/noPIC actions are created.
boolean pic = module.getFilename().contains(".pic.");
@@ -1772,7 +1808,13 @@ public final class CcCompilationHelper {
// - it creates a header module (.pcm file).
return createSourceAction(
Label.parseAbsoluteUnchecked(cppModuleMap.getName()),
- FileSystemUtils.removeExtension(moduleMapArtifact.getRootRelativePath()).getPathString(),
+ // The header module(.pcm) is generated at most one file per target,
+ // so it's safe to remove module map's package path from its output name.
+ cppConfiguration.shortenObjFilePath()
+ ? FileSystemUtils.removeExtension(moduleMapArtifact.getRootRelativePath())
+ .getBaseName()
+ : FileSystemUtils.removeExtension(moduleMapArtifact.getRootRelativePath())
+ .getPathString(),
result,
env,
moduleMapArtifact,
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 0b4e7713a1..aefe027332 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
@@ -639,7 +639,7 @@ public class CppCompileActionBuilder {
return this;
}
- Artifact getOutputFile() {
+ public Artifact getOutputFile() {
return outputFile;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index 85e875349b..d1ca0f5ad1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -1059,6 +1059,10 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
return cppOptions.forceIgnoreDashStatic;
}
+ public boolean shortenObjFilePath() {
+ return cppOptions.shortenObjFilePath;
+ }
+
public boolean legacyWholeArchive() {
return cppOptions.legacyWholeArchive;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index deeca3e78b..199d735f2d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -993,17 +993,17 @@ public class CppHelper {
/** Returns the corresponding compiled TreeArtifact given the source TreeArtifact. */
public static SpecialArtifact getCompileOutputTreeArtifact(
- RuleContext ruleContext, Artifact sourceTreeArtifact, boolean usePic) {
+ RuleContext ruleContext, Artifact sourceTreeArtifact, String outputName, boolean usePic) {
PathFragment objectDir = getObjDirectory(ruleContext.getLabel(), usePic);
- PathFragment rootRelativePath = sourceTreeArtifact.getRootRelativePath();
+
return ruleContext.getTreeArtifact(
- objectDir.getRelative(rootRelativePath), sourceTreeArtifact.getRoot());
+ objectDir.getRelative(outputName), sourceTreeArtifact.getRoot());
}
/** Returns the corresponding compiled TreeArtifact given the source TreeArtifact. */
public static Artifact getCompileOutputTreeArtifact(
- RuleContext ruleContext, Artifact sourceTreeArtifact) {
- return getCompileOutputTreeArtifact(ruleContext, sourceTreeArtifact, false);
+ RuleContext ruleContext, Artifact sourceTreeArtifact, String outputName) {
+ return getCompileOutputTreeArtifact(ruleContext, sourceTreeArtifact, outputName, false);
}
static String getArtifactNameForCategory(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
index 2a9627845b..7e7553326a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
@@ -406,6 +406,22 @@ public class CppOptions extends FragmentOptions {
public Label customMalloc;
@Option(
+ name = "experimental_shortened_obj_file_path",
+ defaultValue = "false",
+ category = "semantics",
+ documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
+ effectTags = {OptionEffectTag.ACTION_COMMAND_LINES, OptionEffectTag.AFFECTS_OUTPUTS},
+ help =
+ "When off, object files are generated at _objs/<target_name>/<source_package_path>/"
+ + "<source_base_name>.o, otherwise they are shortened to _objs/<target_name>/"
+ + "<source_base_name>.o. If there are multiple source files with the same base name, "
+ + "to avoid conflict, the object file path is _objs/<target_name>/<N>"
+ + "/<source_base_name>.o, where N = the source file's order among all source files "
+ + "with the same base name, N starts with 0."
+ )
+ public boolean shortenObjFilePath;
+
+ @Option(
name = "legacy_whole_archive",
defaultValue = "true",
category = "semantics",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/ObjectFilePathHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/ObjectFilePathHelper.java
new file mode 100644
index 0000000000..2ceda006cf
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/ObjectFilePathHelper.java
@@ -0,0 +1,90 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.rules.cpp;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
+/**
+ * A helper class for calculating the output names for object file paths from a set of source files.
+ *
+ * <p>If {@link shortenObjFilePath} is true, the object file path is constructed
+ *
+ * <p>The object file path is constructed in the following format:
+ * <bazel-bin>/<target_package_path>/_objs/<target_name>/<output_name>.<obj_extension> When there's
+ * no two source files having the same basename: <output_name> = <source_file_base_name> otherwise:
+ * <output_name> = N/<source_file_base_name>, N = the file’s order among the source files with the
+ * same basename
+ *
+ * <p>Examples: 1. Output names for ["lib1/foo.cc", "lib2/bar.cc"] are ["foo", "bar"] 2. Output
+ * names for ["foo.cc", "bar.cc", "foo.cpp", "lib/foo.cc"] are ["0/foo", "bar", "1/foo", "2/foo"]
+ *
+ * <p>TODO(b/76143707): Inline this class when it's not used anywhere outside of
+ * CcCompilationHelper.
+ */
+public class ObjectFilePathHelper {
+
+ private final ImmutableMap<Artifact, String> outputNameMap;
+ private final boolean shortenObjFilePath;
+
+ public ObjectFilePathHelper(
+ Iterable<Artifact> sourceArtifacts, boolean shortenObjFilePath, String prefixDir) {
+ // If legacy object file path is used, no need to calculate outputNameMap
+ this.shortenObjFilePath = shortenObjFilePath;
+ if (!shortenObjFilePath) {
+ outputNameMap = null;
+ return;
+ }
+
+ ImmutableMap.Builder<Artifact, String> builder = ImmutableMap.builder();
+
+ HashMap<String, Integer> count = new LinkedHashMap<>();
+ HashMap<String, Integer> number = new LinkedHashMap<>();
+ for (Artifact source : sourceArtifacts) {
+ String outputName =
+ FileSystemUtils.removeExtension(source.getRootRelativePath()).getBaseName();
+ count.put(outputName, count.getOrDefault(outputName, 0) + 1);
+ }
+
+ for (Artifact source : sourceArtifacts) {
+ String outputName =
+ FileSystemUtils.removeExtension(source.getRootRelativePath()).getBaseName();
+ if (count.getOrDefault(outputName, 0) > 1) {
+ int num = number.getOrDefault(outputName, 0);
+ number.put(outputName, num + 1);
+ outputName = num + "/" + outputName;
+ }
+ // If prefixDir is set, prepend it to the outputName
+ if (prefixDir != null) {
+ outputName = prefixDir + "/" + outputName;
+ }
+ builder.put(source, outputName);
+ }
+
+ outputNameMap = builder.build();
+ }
+
+ /** Return the output name for the object file path of a given source file. */
+ public String getOutputName(Artifact source) {
+ if (shortenObjFilePath) {
+ return outputNameMap.get(source);
+ } else {
+ return FileSystemUtils.removeExtension(source.getRootRelativePath()).getPathString();
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index a6b9f8cf7e..8f9424284c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -114,6 +114,7 @@ import com.google.devtools.build.lib.rules.cpp.IncludeProcessing;
import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness;
import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
import com.google.devtools.build.lib.rules.cpp.NoProcessing;
+import com.google.devtools.build.lib.rules.cpp.ObjectFilePathHelper;
import com.google.devtools.build.lib.rules.cpp.PrecompiledFiles;
import com.google.devtools.build.lib.rules.cpp.UmbrellaHeaderAction;
import com.google.devtools.build.lib.rules.objc.ObjcProvider.Flag;
@@ -273,19 +274,6 @@ public class CompilationSupport {
public static final SafeImplicitOutputsFunction FULLY_LINKED_LIB =
fromTemplates("%{name}_fully_linked.a");
- private static ImmutableList<Artifact> getObjFiles(
- CompilationArtifacts compilationArtifacts, IntermediateArtifacts intermediateArtifacts) {
- ImmutableList.Builder<Artifact> result = new ImmutableList.Builder<>();
- for (Artifact sourceFile : compilationArtifacts.getSrcs()) {
- result.add(intermediateArtifacts.objFile(sourceFile));
- }
- for (Artifact nonArcSourceFile : compilationArtifacts.getNonArcSrcs()) {
- result.add(intermediateArtifacts.objFile(nonArcSourceFile));
- }
- result.addAll(compilationArtifacts.getPrecompiledSrcs());
- return result.build();
- }
-
private IncludeProcessing createIncludeProcessing(
Iterable<Artifact> privateHdrs, ObjcProvider objcProvider, @Nullable Artifact pchHdr) {
if (isHeaderThinningEnabled()) {
@@ -859,6 +847,26 @@ public class CompilationSupport {
}
/**
+ * TODO(b/76143707): Remove this function after ObjectFilePathHelper is no longer used here.
+ *
+ * <p>Add constructed object files based on given sources.
+ */
+ private void addObjectFiles(
+ ImmutableList.Builder<Artifact> objectFilesBuilder,
+ Iterable<Artifact> sources,
+ boolean isArc) {
+ ObjectFilePathHelper objectFilePathHelper =
+ new ObjectFilePathHelper(
+ sources,
+ ruleContext.getFragment(CppConfiguration.class).shortenObjFilePath(),
+ isArc ? "arc" : "non_arc");
+ for (Artifact artifact : sources) {
+ objectFilesBuilder.add(
+ intermediateArtifacts.objFile(artifact, objectFilePathHelper.getOutputName(artifact)));
+ }
+ }
+
+ /**
* Returns a provider that collects this target's instrumented sources as well as those of its
* dependencies.
*
@@ -870,9 +878,8 @@ public class CompilationSupport {
if (common.getCompilationArtifacts().isPresent()) {
CompilationArtifacts artifacts = common.getCompilationArtifacts().get();
- for (Artifact artifact : Iterables.concat(artifacts.getSrcs(), artifacts.getNonArcSrcs())) {
- oFiles.add(intermediateArtifacts.objFile(artifact));
- }
+ addObjectFiles(oFiles, artifacts.getSrcs(), true);
+ addObjectFiles(oFiles, artifacts.getNonArcSrcs(), false);
}
return InstrumentedFilesCollector.collect(
@@ -1011,9 +1018,6 @@ public class CompilationSupport {
if (compilationArtifacts.getArchive().isPresent()) {
Artifact objList = intermediateArtifacts.archiveObjList();
- // TODO(b/30783125): Signal the need for this action in the CROSSTOOL.
- registerObjFilelistAction(getObjFiles(compilationArtifacts, intermediateArtifacts), objList);
-
extension.addVariableCategory(VariableCategory.ARCHIVE_VARIABLES);
compilationInfo =
@@ -1027,6 +1031,9 @@ public class CompilationSupport {
priorityHeaders,
LinkTargetType.OBJC_ARCHIVE,
objList);
+
+ // TODO(b/30783125): Signal the need for this action in the CROSSTOOL.
+ registerObjFilelistAction(compilationInfo.getFirst().getObjectFiles(false), objList);
} else {
compilationInfo =
ccCompileAndLink(
@@ -1827,7 +1834,7 @@ public class CompilationSupport {
headerThinningInfos.add(
new ObjcHeaderThinningInfo(
sourceFile,
- intermediateArtifacts.headersListFile(sourceFile),
+ intermediateArtifacts.headersListFile(objectFile),
action.getCompilerOptions()));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
index 0cc7fa9fc2..86cdb0dcd5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
@@ -21,7 +21,6 @@ import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap.UmbrellaHeaderStrategy;
@@ -267,10 +266,9 @@ public final class IntermediateArtifacts {
"lib%s%s.a", basename, archiveFileNameSuffix)));
}
- private Artifact inUniqueObjsDir(Artifact source, String extension) {
+ private Artifact inUniqueObjsDir(String outputName, String extension) {
PathFragment uniqueDir = OBJS.getRelative(ruleContext.getLabel().getName());
- PathFragment sourceFile = uniqueDir.getRelative(source.getRootRelativePath());
- PathFragment scopeRelativePath = FileSystemUtils.replaceExtension(sourceFile, extension);
+ PathFragment scopeRelativePath = uniqueDir.getRelative(outputName + extension);
return scopedArtifact(scopeRelativePath);
}
@@ -278,25 +276,17 @@ public final class IntermediateArtifacts {
* The artifact for the .o file that should be generated when compiling the {@code source}
* artifact.
*/
- public Artifact objFile(Artifact source) {
+ public Artifact objFile(Artifact source, String outputName) {
if (source.isTreeArtifact()) {
- return CppHelper.getCompileOutputTreeArtifact(ruleContext, source);
+ return CppHelper.getCompileOutputTreeArtifact(ruleContext, source, outputName);
} else {
- return inUniqueObjsDir(source, ".o");
+ return inUniqueObjsDir(outputName, ".o");
}
}
/** The artifact for the .headers file output by the header thinning action for this source. */
- public Artifact headersListFile(Artifact source) {
- return inUniqueObjsDir(source, ".headers_list");
- }
-
- /**
- * The artifact for the .gcno file that should be generated when compiling the {@code source}
- * artifact.
- */
- public Artifact gcnoFile(Artifact source) {
- return inUniqueObjsDir(source, ".gcno");
+ public Artifact headersListFile(Artifact objectFile) {
+ return ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".headers_list");
}
/**
@@ -416,11 +406,6 @@ public final class IntermediateArtifacts {
return appendExtension("_runner.sh");
}
- /** Dependency file that is generated when compiling the {@code source} artifact. */
- public DotdFile dotdFile(Artifact source) {
- return new DotdFile(inUniqueObjsDir(source, ".d"));
- }
-
/**
* {@link CppModuleMap} that provides the clang module map for this target.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java
index 3207d78116..53836f4348 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCppSemantics.java
@@ -104,7 +104,7 @@ public class ObjcCppSemantics implements CppSemantics {
if (!sourceFile.isTreeArtifact()
&& SOURCES_FOR_HEADER_THINNING.matches(sourceFile.getFilename())) {
actionBuilder.addMandatoryInputs(
- ImmutableList.of(intermediateArtifacts.headersListFile(sourceFile)));
+ ImmutableList.of(intermediateArtifacts.headersListFile(actionBuilder.getOutputFile())));
}
} else {
// Header thinning feature will make all generated files mandatory inputs to the