72
72
import java .util .Map ;
73
73
import java .util .Optional ;
74
74
import java .util .OptionalInt ;
75
- import java .util .OptionalLong ;
76
75
import java .util .SequencedMap ;
77
76
import java .util .Set ;
78
77
import java .util .concurrent .Semaphore ;
@@ -141,21 +140,12 @@ public enum ConfigSettingVisibilityPolicy {
141
140
*/
142
141
private static final String DUMMY_WORKSPACE_NAME_FOR_BZLMOD_PACKAGES = "__dummy_workspace_bzlmod" ;
143
142
144
- /** Sentinel value for package overhead being empty. */
145
- private static final long PACKAGE_OVERHEAD_UNSET = -1 ;
146
-
147
143
// ==== General package metadata fields ====
148
144
149
145
private final Metadata metadata ;
150
146
151
147
private final Declarations declarations ;
152
148
153
- /**
154
- * A rough approximation of the memory and general accounting costs associated with a loaded
155
- * package. A value of -1 means it is unset. Stored as a long to take up less memory per pkg.
156
- */
157
- private long packageOverhead = PACKAGE_OVERHEAD_UNSET ;
158
-
159
149
// ==== Fields specific to external package / WORKSPACE logic ====
160
150
161
151
/**
@@ -344,13 +334,6 @@ private static ImmutableList<Label> computeTransitiveLoads(Iterable<Module> dire
344
334
return ImmutableList .copyOf (loads );
345
335
}
346
336
347
- /** Returns package overhead as configured by the configured {@link PackageOverheadEstimator}. */
348
- public OptionalLong getPackageOverhead () {
349
- return packageOverhead == PACKAGE_OVERHEAD_UNSET
350
- ? OptionalLong .empty ()
351
- : OptionalLong .of (packageOverhead );
352
- }
353
-
354
337
// ==== Accessors specific to external package / WORKSPACE logic ====
355
338
356
339
/**
@@ -412,11 +395,6 @@ OptionalInt getFirstWorkspaceSuffixRegisteredToolchain() {
412
395
413
396
// ==== Target and macro accessors ====
414
397
415
- /** Returns an (immutable, ordered) view of all the targets belonging to this package. */
416
- public ImmutableSortedMap <String , Target > getTargets () {
417
- return targets ;
418
- }
419
-
420
398
/**
421
399
* Returns a (read-only, ordered) iterable of all the targets belonging to this package which are
422
400
* instances of the specified class.
@@ -612,6 +590,11 @@ public String toString() {
612
590
+ (targets != null ? getTargets (Rule .class ) : "initializing..." );
613
591
}
614
592
593
+ @ Override
594
+ public String getShortDescription () {
595
+ return "package " + getPackageIdentifier ().getCanonicalForm ();
596
+ }
597
+
615
598
/**
616
599
* Dumps the package for debugging. Do not depend on the exact format/contents of this debugging
617
600
* output.
@@ -957,6 +940,10 @@ void setPackageFunctionUsed() {
957
940
packageFunctionUsed = true ;
958
941
}
959
942
943
+ public Set <Target > getTargets () {
944
+ return recorder .getTargets ();
945
+ }
946
+
960
947
/** Adds an environment group to the package. Not valid within symbolic macros. */
961
948
void addEnvironmentGroup (
962
949
String name ,
@@ -1157,9 +1144,7 @@ protected void finalBuilderValidationHook() {
1157
1144
}
1158
1145
1159
1146
@ Override
1160
- public Packageoid finishBuild () {
1161
- var unused = super .finishBuild ();
1162
-
1147
+ protected void packageoidInitializationHook () {
1163
1148
// Finish Package.Declarations construction.
1164
1149
if (pkg .getDeclarations ().directLoads == null
1165
1150
&& pkg .getDeclarations ().transitiveLoads == null ) {
@@ -1168,8 +1153,6 @@ public Packageoid finishBuild() {
1168
1153
}
1169
1154
pkg .getDeclarations ().workspaceName = workspaceName ;
1170
1155
pkg .getDeclarations ().makeEnv = ImmutableMap .copyOf (makeEnv );
1171
-
1172
- return pkg ;
1173
1156
}
1174
1157
1175
1158
AbstractBuilder (
@@ -1182,6 +1165,7 @@ public Packageoid finishBuild() {
1182
1165
String workspaceName ,
1183
1166
RepositoryMapping mainRepositoryMapping ,
1184
1167
@ Nullable Semaphore cpuBoundSemaphore ,
1168
+ PackageOverheadEstimator packageOverheadEstimator ,
1185
1169
@ Nullable ImmutableMap <Location , String > generatorMap ,
1186
1170
@ Nullable Globber globber ,
1187
1171
boolean enableNameConflictChecking ,
@@ -1194,6 +1178,7 @@ public Packageoid finishBuild() {
1194
1178
workspaceName ,
1195
1179
mainRepositoryMapping ,
1196
1180
cpuBoundSemaphore ,
1181
+ packageOverheadEstimator ,
1197
1182
generatorMap ,
1198
1183
globber ,
1199
1184
enableNameConflictChecking ,
@@ -1261,9 +1246,6 @@ default boolean precomputeTransitiveLoads() {
1261
1246
private final HashMap <RepositoryName , LinkedHashMap <String , RepositoryName >>
1262
1247
externalPackageRepositoryMappings = new HashMap <>();
1263
1248
1264
- /** Estimates the package overhead of this package. */
1265
- private final PackageOverheadEstimator packageOverheadEstimator ;
1266
-
1267
1249
// The snapshot of {@link #targets} for use in rule finalizer macros. Contains all
1268
1250
// non-finalizer-instantiated rule targets (i.e. all rule targets except for those instantiated
1269
1251
// in a finalizer or in a macro called from a finalizer).
@@ -1320,11 +1302,11 @@ private Builder(
1320
1302
workspaceName ,
1321
1303
mainRepositoryMapping ,
1322
1304
cpuBoundSemaphore ,
1305
+ packageOverheadEstimator ,
1323
1306
generatorMap ,
1324
1307
globber ,
1325
1308
enableNameConflictChecking ,
1326
1309
trackFullMacroInformation );
1327
- this .packageOverheadEstimator = packageOverheadEstimator ;
1328
1310
}
1329
1311
1330
1312
/** Retrieves this object from a Starlark thread. Returns null if not present. */
@@ -1435,10 +1417,6 @@ void setComputationSteps(long n) {
1435
1417
getPackage ().computationSteps = n ;
1436
1418
}
1437
1419
1438
- public Set <Target > getTargets () {
1439
- return recorder .getTargets ();
1440
- }
1441
-
1442
1420
void replaceTarget (Target newTarget ) {
1443
1421
Preconditions .checkArgument (
1444
1422
newTarget .getPackage () == pkg , // pointer comparison since we're constructing `pkg`
@@ -1607,7 +1585,13 @@ public Builder buildPartial() throws NoSuchPackageException {
1607
1585
1608
1586
@ Override
1609
1587
public Package finishBuild () {
1610
- Package pkg = (Package ) super .finishBuild ();
1588
+ return (Package ) super .finishBuild ();
1589
+ }
1590
+
1591
+ @ Override
1592
+ protected void packageoidInitializationHook () {
1593
+ super .packageoidInitializationHook ();
1594
+ Package pkg = getPackage ();
1611
1595
pkg .macroNamespaceViolatingTargets =
1612
1596
ImmutableMap .copyOf (recorder .getMacroNamespaceViolatingTargets ());
1613
1597
pkg .targetsToDeclaringMacro =
@@ -1634,16 +1618,6 @@ public Package finishBuild() {
1634
1618
externalPackageRepositoryMappings .forEach (
1635
1619
(k , v ) -> repositoryMappingsBuilder .put (k , ImmutableMap .copyOf (v )));
1636
1620
pkg .externalPackageRepositoryMappings = repositoryMappingsBuilder .buildOrThrow ();
1637
- OptionalLong overheadEstimate = packageOverheadEstimator .estimatePackageOverhead (pkg );
1638
- pkg .packageOverhead = overheadEstimate .orElse (PACKAGE_OVERHEAD_UNSET );
1639
-
1640
- // Verify that we haven't introduced new errors on the builder since the call to
1641
- // finalBuilderValidationHook().
1642
- if (containsErrors ()) {
1643
- checkState (pkg .containsErrors (), "Package.Builder error status not propagated to Package" );
1644
- }
1645
-
1646
- return pkg ;
1647
1621
}
1648
1622
1649
1623
/** Completes package construction. Idempotent. */
0 commit comments