Skip to content

Commit eeec121

Browse files
tetrominocopybara-github
authored andcommitted
Automated rollback of commit f6c4e62.
*** Reason for rollback *** Blaze crashes when building DriveFS - see b/219077770 *** Original change description *** Changes necessary for Starlark cc_library Blaze changes for cc_library.bzl RELNOTES:none PiperOrigin-RevId: 428122831
1 parent 152e705 commit eeec121

5 files changed

Lines changed: 90 additions & 45 deletions

File tree

src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingOutputs.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.collect.ImmutableList;
1919
import com.google.common.collect.ImmutableSetMultimap;
2020
import com.google.devtools.build.lib.actions.Artifact;
21+
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
2122
import com.google.devtools.build.lib.starlarkbuildapi.cpp.CcLinkingOutputsApi;
2223
import com.google.devtools.build.lib.vfs.FileSystemUtils;
2324
import javax.annotation.Nullable;
@@ -35,14 +36,17 @@ public class CcLinkingOutputs implements CcLinkingOutputsApi<Artifact, LtoBacken
3536
@Nullable private final Artifact executable;
3637

3738
private final ImmutableList<LtoBackendArtifacts> allLtoArtifacts;
39+
private final ImmutableList<Artifact> linkActionInputs;
3840

3941
private CcLinkingOutputs(
4042
LibraryToLink libraryToLink,
4143
Artifact executable,
42-
ImmutableList<LtoBackendArtifacts> allLtoArtifacts) {
44+
ImmutableList<LtoBackendArtifacts> allLtoArtifacts,
45+
ImmutableList<Artifact> linkActionInputs) {
4346
this.libraryToLink = libraryToLink;
4447
this.executable = executable;
4548
this.allLtoArtifacts = allLtoArtifacts;
49+
this.linkActionInputs = linkActionInputs;
4650
}
4751

4852
@Override
@@ -68,6 +72,10 @@ public Sequence<LtoBackendArtifacts> getAllLtoArtifactsForStarlark(StarlarkThrea
6872
return StarlarkList.immutableCopyOf(getAllLtoArtifacts());
6973
}
7074

75+
public ImmutableList<Artifact> getLinkActionInputs() {
76+
return linkActionInputs;
77+
}
78+
7179
public boolean isEmpty() {
7280
return libraryToLink == null;
7381
}
@@ -121,9 +129,11 @@ private Builder() {
121129
// same list return the .pdb file for Windows.
122130
private final ImmutableList.Builder<LtoBackendArtifacts> allLtoArtifacts =
123131
ImmutableList.builder();
132+
private final ImmutableList.Builder<Artifact> linkActionInputs = ImmutableList.builder();
124133

125134
public CcLinkingOutputs build() {
126-
return new CcLinkingOutputs(libraryToLink, executable, allLtoArtifacts.build());
135+
return new CcLinkingOutputs(
136+
libraryToLink, executable, allLtoArtifacts.build(), linkActionInputs.build());
127137
}
128138

129139
public Builder setLibraryToLink(LibraryToLink libraryToLink) {
@@ -140,5 +150,10 @@ public Builder addAllLtoArtifacts(Iterable<LtoBackendArtifacts> allLtoArtifacts)
140150
this.allLtoArtifacts.addAll(allLtoArtifacts);
141151
return this;
142152
}
153+
154+
public Builder addLinkActionInputs(NestedSet<Artifact> linkActionInputs) {
155+
this.linkActionInputs.addAll(linkActionInputs.toList());
156+
return this;
157+
}
143158
}
144159
}

src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java

100755100644
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ public LibraryToLink createLibraryLinkerInput(
635635
"If you pass '%s_library', you must also pass a 'feature_configuration'", library);
636636
}
637637
}
638+
if (nopicObjects != null && staticLibrary == null) {
639+
throw Starlark.errorf("If you pass 'objects' you must also pass a 'static_library'");
640+
}
641+
if (picObjects != null && picStaticLibrary == null) {
642+
throw Starlark.errorf("If you pass 'pic_objects' you must also pass a 'pic_static_library'");
643+
}
638644
if (notNullArtifactForIdentifier == null) {
639645
throw Starlark.errorf("Must pass at least one artifact");
640646
}
@@ -1798,7 +1804,7 @@ public Tuple createLinkingContextFromCompilationOutputs(
17981804
CcToolchainProvider starlarkCcToolchainProvider,
17991805
CcCompilationOutputs compilationOutputs,
18001806
Sequence<?> userLinkFlags, // <String> expected
1801-
Sequence<?> linkingContextsObjects, // <CcLinkingContext> expected
1807+
Sequence<?> linkingContexts, // <CcLinkingContext> expected
18021808
String name,
18031809
String languageString,
18041810
boolean alwayslink,
@@ -1808,11 +1814,9 @@ public Tuple createLinkingContextFromCompilationOutputs(
18081814
Object grepIncludes,
18091815
Object variablesExtension,
18101816
Object stamp,
1811-
Object linkedDllNameSuffix,
1812-
Object winDefFile,
18131817
StarlarkThread thread)
18141818
throws InterruptedException, EvalException {
1815-
if (checkObjectsBound(stamp, linkedDllNameSuffix, winDefFile)) {
1819+
if (checkObjectsBound(stamp)) {
18161820
CcModule.checkPrivateStarlarkificationAllowlist(thread);
18171821
}
18181822
Language language = parseLanguage(languageString);
@@ -1841,8 +1845,6 @@ public Tuple createLinkingContextFromCompilationOutputs(
18411845
} else {
18421846
staticLinkTargetType = LinkTargetType.OBJC_ARCHIVE;
18431847
}
1844-
List<CcLinkingContext> ccLinkingContexts =
1845-
Sequence.cast(linkingContextsObjects, CcLinkingContext.class, "linking_contexts");
18461848
CcLinkingHelper helper =
18471849
new CcLinkingHelper(
18481850
actions.getActionConstructionContext().getRuleErrorConsumer(),
@@ -1866,42 +1868,43 @@ public Tuple createLinkingContextFromCompilationOutputs(
18661868
.addNonCodeLinkerInputs(
18671869
Sequence.cast(additionalInputs, Artifact.class, "additional_inputs"))
18681870
.setShouldCreateStaticLibraries(!disallowStaticLibraries)
1869-
.addCcLinkingContexts(ccLinkingContexts)
18701871
.setShouldCreateDynamicLibrary(
18711872
!disallowDynamicLibraries
1872-
&& (!featureConfiguration
1873-
.getFeatureConfiguration()
1874-
.isEnabled(CppRuleClasses.TARGETS_WINDOWS)
1875-
|| winDefFile != null))
1873+
&& !featureConfiguration
1874+
.getFeatureConfiguration()
1875+
.isEnabled(CppRuleClasses.TARGETS_WINDOWS))
18761876
.setStaticLinkType(staticLinkTargetType)
18771877
.setDynamicLinkType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)
18781878
.emitInterfaceSharedLibraries(true)
1879-
.setLinkedDLLNameSuffix(
1880-
convertFromNoneable(linkedDllNameSuffix, /* defaultValue= */ ""))
1881-
.setDefFile(convertFromNoneable(winDefFile, /* defaultValue= */ null))
18821879
.setIsStampingEnabled(isStampingEnabled)
18831880
.addLinkopts(Sequence.cast(userLinkFlags, String.class, "user_link_flags"));
18841881
if (!asDict(variablesExtension).isEmpty()) {
18851882
helper.addVariableExtension(new UserVariablesExtension(asDict(variablesExtension)));
18861883
}
18871884
try {
1885+
CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
18881886
ImmutableList<LibraryToLink> libraryToLink = ImmutableList.of();
1889-
CcLinkingOutputs ccLinkingOutputs = helper.link(compilationOutputs);
1890-
if (!ccLinkingOutputs.isEmpty()) {
1891-
LibraryToLink rewrappedForAlwaysLink =
1892-
ccLinkingOutputs.getLibraryToLink().toBuilder().setAlwayslink(alwayslink).build();
1893-
ccLinkingOutputs =
1894-
CcLinkingOutputs.builder()
1895-
.setExecutable(ccLinkingOutputs.getExecutable())
1896-
.setLibraryToLink(rewrappedForAlwaysLink)
1897-
.addAllLtoArtifacts(ccLinkingOutputs.getAllLtoArtifacts())
1898-
.build();
1899-
libraryToLink = ImmutableList.of(rewrappedForAlwaysLink);
1887+
if (!compilationOutputs.isEmpty()) {
1888+
ccLinkingOutputs = helper.link(compilationOutputs);
1889+
if (!ccLinkingOutputs.isEmpty()) {
1890+
libraryToLink =
1891+
ImmutableList.of(
1892+
ccLinkingOutputs.getLibraryToLink().toBuilder()
1893+
.setAlwayslink(alwayslink)
1894+
.build());
1895+
}
19001896
}
19011897
CcLinkingContext linkingContext =
19021898
helper.buildCcLinkingContextFromLibrariesToLink(
19031899
libraryToLink, CcCompilationContext.EMPTY);
1904-
return Tuple.of(linkingContext, ccLinkingOutputs);
1900+
return Tuple.of(
1901+
CcLinkingContext.merge(
1902+
ImmutableList.<CcLinkingContext>builder()
1903+
.add(linkingContext)
1904+
.addAll(
1905+
Sequence.cast(linkingContexts, CcLinkingContext.class, "linking_contexts"))
1906+
.build()),
1907+
ccLinkingOutputs);
19051908
} catch (RuleErrorException e) {
19061909
throw Starlark.errorf("%s", e.getMessage());
19071910
}
@@ -1999,7 +2002,7 @@ protected Tuple compile(
19992002
Object textualHeadersStarlarkObject,
20002003
Object additionalExportedHeadersObject,
20012004
Sequence<?> includes, // <String> expected
2002-
Object starlarkLooseIncludes,
2005+
Object starlarkIncludes,
20032006
Sequence<?> quoteIncludes, // <String> expected
20042007
Sequence<?> systemIncludes, // <String> expected
20052008
Sequence<?> frameworkIncludes, // <String> expected
@@ -2039,15 +2042,15 @@ protected Tuple compile(
20392042
hdrsCheckingModeObject,
20402043
implementationCcCompilationContextsObject,
20412044
coptsFilterObject,
2042-
starlarkLooseIncludes)) {
2045+
starlarkIncludes)) {
20432046
CcModule.checkPrivateStarlarkificationAllowlist(thread);
20442047
}
20452048

20462049
StarlarkActionFactory actions = starlarkActionFactoryApi;
20472050
CcToolchainProvider ccToolchainProvider =
20482051
convertFromNoneable(starlarkCcToolchainProvider, null);
20492052

2050-
ImmutableList<String> looseIncludes = asClassImmutableList(starlarkLooseIncludes);
2053+
ImmutableList<String> looseIncludes = asClassImmutableList(starlarkIncludes);
20512054
CppModuleMap moduleMap = convertFromNoneable(moduleMapNoneable, /* defaultValue= */ null);
20522055
ImmutableList<CppModuleMap> additionalModuleMaps =
20532056
asClassImmutableList(additionalModuleMapsNoneable);

src/main/java/com/google/devtools/build/lib/rules/cpp/LibraryToLink.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,18 @@ public abstract static class Builder implements LibraryToLink.Builder {
363363
public final LibraryToLink build() {
364364
LibraryToLink result = autoBuild();
365365
Preconditions.checkNotNull(result.getLibraryIdentifier(), result);
366+
Preconditions.checkState(
367+
(result.getObjectFiles() == null
368+
&& result.getLtoCompilationContext() == null
369+
&& result.getSharedNonLtoBackends() == null)
370+
|| result.getStaticLibrary() != null,
371+
result);
372+
Preconditions.checkState(
373+
(result.getPicObjectFiles() == null
374+
&& result.getPicLtoCompilationContext() == null
375+
&& result.getPicSharedNonLtoBackends() == null)
376+
|| result.getPicStaticLibrary() != null,
377+
result);
366378
Preconditions.checkState(
367379
result.getResolvedSymlinkDynamicLibrary() == null || result.getDynamicLibrary() != null,
368380
result);

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java

100755100644
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,18 +1236,6 @@ CcToolchainConfigInfoT ccToolchainConfigInfoFromStarlark(
12361236
named = true,
12371237
documented = false,
12381238
defaultValue = "unbound"),
1239-
@Param(
1240-
name = "linked_dll_name_suffix",
1241-
positional = false,
1242-
named = true,
1243-
documented = false,
1244-
defaultValue = "unbound"),
1245-
@Param(
1246-
name = "win_def_file",
1247-
documented = false,
1248-
positional = false,
1249-
named = true,
1250-
defaultValue = "unbound"),
12511239
})
12521240
Tuple createLinkingContextFromCompilationOutputs(
12531241
StarlarkActionFactoryT starlarkActionFactoryApi,
@@ -1265,8 +1253,6 @@ Tuple createLinkingContextFromCompilationOutputs(
12651253
Object grepIncludes,
12661254
Object variablesExtension,
12671255
Object stamp,
1268-
Object linkedDllNameSuffix,
1269-
Object winDefFile,
12701256
StarlarkThread thread)
12711257
throws InterruptedException, EvalException;
12721258

src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java

100755100644
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6745,6 +6745,35 @@ public void testObjectFilesInCreateLibrary() throws Exception {
67456745
.containsExactly("object.pic.o");
67466746
}
67476747

6748+
@Test
6749+
public void testObjectFilesInCreateLibraryWithoutStaticLibrary() throws Exception {
6750+
setUpCcLinkingContextTest(true);
6751+
scratch.file(
6752+
"b/BUILD",
6753+
"load('//tools/build_defs/cc:rule.bzl', 'crule')",
6754+
"crule(name='import_objects_no_lib',",
6755+
" objects = ['object.o'],",
6756+
")");
6757+
6758+
checkError(
6759+
"//b:import_objects_no_lib", "If you pass 'objects' you must also pass a 'static_library'");
6760+
}
6761+
6762+
@Test
6763+
public void testObjectFilesInCreateLibraryWithoutPicStaticLibrary() throws Exception {
6764+
setUpCcLinkingContextTest(true);
6765+
scratch.file(
6766+
"b/BUILD",
6767+
"load('//tools/build_defs/cc:rule.bzl', 'crule')",
6768+
"crule(name='import_objects_no_pic_lib',",
6769+
" pic_objects = ['object.pic.o'],",
6770+
")");
6771+
6772+
checkError(
6773+
"//b:import_objects_no_pic_lib",
6774+
"If you pass 'pic_objects' you must also pass a 'pic_static_library'");
6775+
}
6776+
67486777
private void setupDebugPackageProviderTest(String fission) throws Exception {
67496778
getAnalysisMock()
67506779
.ccSupport()

0 commit comments

Comments
 (0)