-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge CppDebugFileProvider with CcInfo
.dwo files were previously propagated in a separate provider, and this provider cannot be accessed from Starlark. We had 2 options: * expose the provider in Starlark * merge it with CcInfo We went with unification with CcInfo, as it simplifies Starlark rules, and CppDebugFileProvider is not used by other languages anyway. While at it, I realized we don't need the DwoArtifactsCollector to collect both pic and nopic dwos just for cc binary to then throw one of them away. Thus I removed the collector. And I changed unit tests to access dwo through action inputs, not by calling the same methods as the production code calls. RELNOTES: None. PiperOrigin-RevId: 257601965
- Loading branch information
1 parent
80a63d7
commit ece92fb
Showing
13 changed files
with
193 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/com/google/devtools/build/lib/rules/cpp/CcDebugInfoContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2014 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.ImmutableList; | ||
import com.google.devtools.build.lib.actions.Artifact; | ||
import com.google.devtools.build.lib.collect.nestedset.NestedSet; | ||
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; | ||
import com.google.devtools.build.lib.collect.nestedset.Order; | ||
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A struct that stores .dwo files which can be combined into a .dwp in the packaging step. See | ||
* https://gcc.gnu.org/wiki/DebugFission for details. | ||
*/ | ||
@Immutable | ||
public final class CcDebugInfoContext { | ||
|
||
public static final CcDebugInfoContext EMPTY = | ||
new CcDebugInfoContext( | ||
/* transitiveDwoFiles= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER), | ||
/* transitivePicDwoFiles= */ NestedSetBuilder.emptySet(Order.STABLE_ORDER)); | ||
private final NestedSet<Artifact> transitiveDwoFiles; | ||
private final NestedSet<Artifact> transitivePicDwoFiles; | ||
|
||
public CcDebugInfoContext( | ||
NestedSet<Artifact> transitiveDwoFiles, NestedSet<Artifact> transitivePicDwoFiles) { | ||
this.transitiveDwoFiles = transitiveDwoFiles; | ||
this.transitivePicDwoFiles = transitivePicDwoFiles; | ||
} | ||
|
||
/** Merge multiple {@link CcDebugInfoContext}s into one. */ | ||
public static CcDebugInfoContext merge(ImmutableList<CcDebugInfoContext> contexts) { | ||
NestedSetBuilder<Artifact> transitiveDwoFiles = NestedSetBuilder.stableOrder(); | ||
NestedSetBuilder<Artifact> transitivePicDwoFiles = NestedSetBuilder.stableOrder(); | ||
|
||
for (CcDebugInfoContext context : contexts) { | ||
transitiveDwoFiles.addTransitive(context.getTransitiveDwoFiles()); | ||
transitivePicDwoFiles.addTransitive(context.getTransitivePicDwoFiles()); | ||
} | ||
|
||
return new CcDebugInfoContext(transitiveDwoFiles.build(), transitivePicDwoFiles.build()); | ||
} | ||
|
||
public static CcDebugInfoContext from(CcCompilationOutputs outputs) { | ||
return new CcDebugInfoContext( | ||
NestedSetBuilder.wrap(Order.STABLE_ORDER, outputs.getDwoFiles()), | ||
NestedSetBuilder.wrap(Order.STABLE_ORDER, outputs.getPicDwoFiles())); | ||
} | ||
|
||
/** | ||
* Returns the .dwo files that should be included in this target's .dwp packaging (if this | ||
* target is linked) or passed through to a dependant's .dwp packaging (e.g. if this is a | ||
* cc_library depended on by a statically linked cc_binary). | ||
* | ||
* Assumes the corresponding link consumes .o files (vs. .pic.o files). | ||
*/ | ||
public NestedSet<Artifact> getTransitiveDwoFiles() { | ||
return transitiveDwoFiles; | ||
} | ||
|
||
/** | ||
* Same as above, but assumes the corresponding link consumes pic.o files. | ||
*/ | ||
public NestedSet<Artifact> getTransitivePicDwoFiles() { | ||
return transitivePicDwoFiles; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
CcDebugInfoContext that = (CcDebugInfoContext) o; | ||
return Objects.equals(transitiveDwoFiles, that.transitiveDwoFiles) | ||
&& Objects.equals(transitivePicDwoFiles, that.transitivePicDwoFiles); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(transitiveDwoFiles, transitivePicDwoFiles); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.