|
19 | 19 | import com.google.common.annotations.VisibleForTesting;
|
20 | 20 | import com.google.common.base.Preconditions;
|
21 | 21 | import com.google.common.collect.ImmutableList;
|
22 |
| -import com.google.common.collect.ImmutableSet; |
23 | 22 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
|
24 | 23 | import com.google.devtools.build.lib.packages.BuiltinProvider;
|
25 | 24 | import com.google.devtools.build.lib.packages.NativeInfo;
|
26 | 25 | import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ActionConfig;
|
27 | 26 | import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ArtifactNamePatternMapper;
|
28 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.EnvEntry; |
29 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.EnvSet; |
30 | 27 | import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Feature;
|
31 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Flag.SingleChunkFlag; |
32 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FlagGroup; |
33 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FlagSet; |
34 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Tool; |
35 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.VariableWithValue; |
36 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.WithFeatureSet; |
37 |
| -import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.Expandable; |
38 | 28 | import com.google.devtools.build.lib.starlarkbuildapi.cpp.CcToolchainConfigInfoApi;
|
39 | 29 | import com.google.devtools.build.lib.util.Pair;
|
40 |
| -import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; |
41 | 30 | import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
|
42 |
| -import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.ToolPath; |
43 | 31 | import java.util.List;
|
44 | 32 | import net.starlark.java.annot.StarlarkMethod;
|
45 | 33 | import net.starlark.java.eval.EvalException;
|
@@ -298,205 +286,6 @@ public String getBuiltinSysroot() {
|
298 | 286 | return builtinSysroot;
|
299 | 287 | }
|
300 | 288 |
|
301 |
| - @Override |
302 |
| - public String getProto() { |
303 |
| - CToolchain.Builder cToolchain = CToolchain.newBuilder(); |
304 |
| - cToolchain.addAllFeature( |
305 |
| - features.stream() |
306 |
| - .map(feature -> featureToProto(feature)) |
307 |
| - .collect(ImmutableList.toImmutableList())); |
308 |
| - cToolchain.addAllActionConfig( |
309 |
| - actionConfigs.stream() |
310 |
| - .map(actionConfig -> actionConfigToProto(actionConfig)) |
311 |
| - .collect(ImmutableList.toImmutableList())); |
312 |
| - cToolchain.addAllArtifactNamePattern( |
313 |
| - artifactNamePatterns.asImmutableMap().entrySet().stream() |
314 |
| - .map( |
315 |
| - entry -> |
316 |
| - CToolchain.ArtifactNamePattern.newBuilder() |
317 |
| - .setCategoryName(entry.getKey().getCategoryName()) |
318 |
| - .setPrefix(entry.getValue().getPrefix()) |
319 |
| - .setExtension(entry.getValue().getExtension()) |
320 |
| - .build()) |
321 |
| - .collect(ImmutableList.toImmutableList())); |
322 |
| - cToolchain.addAllToolPath( |
323 |
| - toolPaths.stream() |
324 |
| - .map( |
325 |
| - toolPath -> |
326 |
| - ToolPath.newBuilder() |
327 |
| - .setName(toolPath.getFirst()) |
328 |
| - .setPath(toolPath.getSecond()) |
329 |
| - .build()) |
330 |
| - .collect(ImmutableList.toImmutableList())); |
331 |
| - cToolchain.addAllMakeVariable( |
332 |
| - makeVariables.stream() |
333 |
| - .map( |
334 |
| - makeVariable -> |
335 |
| - CrosstoolConfig.MakeVariable.newBuilder() |
336 |
| - .setName(makeVariable.getFirst()) |
337 |
| - .setValue(makeVariable.getSecond()) |
338 |
| - .build()) |
339 |
| - .collect(ImmutableList.toImmutableList())); |
340 |
| - cToolchain |
341 |
| - .addAllCxxBuiltinIncludeDirectory(cxxBuiltinIncludeDirectories) |
342 |
| - .setToolchainIdentifier(toolchainIdentifier) |
343 |
| - .setHostSystemName(hostSystemName) |
344 |
| - .setTargetSystemName(targetSystemName) |
345 |
| - .setTargetCpu(targetCpu) |
346 |
| - .setTargetLibc(targetLibc) |
347 |
| - .setCompiler(compiler) |
348 |
| - .setAbiVersion(abiVersion) |
349 |
| - .setAbiLibcVersion(abiLibcVersion); |
350 |
| - if (!builtinSysroot.isEmpty()) { |
351 |
| - cToolchain.setBuiltinSysroot(builtinSysroot); |
352 |
| - } |
353 |
| - return cToolchain.build().toString(); |
354 |
| - } |
355 |
| - |
356 |
| - private static CToolchain.WithFeatureSet withFeatureSetToProto(WithFeatureSet withFeatureSet) { |
357 |
| - return CToolchain.WithFeatureSet.newBuilder() |
358 |
| - .addAllFeature(withFeatureSet.getFeatures()) |
359 |
| - .addAllNotFeature(withFeatureSet.getNotFeatures()) |
360 |
| - .build(); |
361 |
| - } |
362 |
| - |
363 |
| - private static CToolchain.EnvEntry envEntryToProto(EnvEntry envEntry) { |
364 |
| - return CToolchain.EnvEntry.newBuilder() |
365 |
| - .setKey(envEntry.getKey()) |
366 |
| - .setValue(envEntry.getValue()) |
367 |
| - .build(); |
368 |
| - } |
369 |
| - |
370 |
| - private static CToolchain.EnvSet envSetToProto(EnvSet envSet) { |
371 |
| - return CToolchain.EnvSet.newBuilder() |
372 |
| - .addAllAction(envSet.getActions()) |
373 |
| - .addAllEnvEntry( |
374 |
| - envSet.getEnvEntries().stream() |
375 |
| - .map(envEntry -> envEntryToProto(envEntry)) |
376 |
| - .collect(ImmutableList.toImmutableList())) |
377 |
| - .addAllWithFeature( |
378 |
| - envSet.getWithFeatureSets().stream() |
379 |
| - .map(withFeatureSet -> withFeatureSetToProto(withFeatureSet)) |
380 |
| - .collect(ImmutableList.toImmutableList())) |
381 |
| - .build(); |
382 |
| - } |
383 |
| - |
384 |
| - private static CToolchain.FlagGroup flagGroupToProto(FlagGroup flagGroup) { |
385 |
| - ImmutableList.Builder<CToolchain.FlagGroup> flagGroups = ImmutableList.builder(); |
386 |
| - ImmutableList.Builder<String> flags = ImmutableList.builder(); |
387 |
| - for (Expandable expandable : flagGroup.getExpandables()) { |
388 |
| - if (expandable instanceof FlagGroup expandableFlagGroup) { |
389 |
| - flagGroups.add(flagGroupToProto(expandableFlagGroup)); |
390 |
| - } else if (expandable instanceof SingleChunkFlag singleChunkFlag) { |
391 |
| - flags.add(singleChunkFlag.getString()); |
392 |
| - } else if (expandable instanceof CcToolchainFeatures.Flag) { |
393 |
| - flags.add(((CcToolchainFeatures.Flag) expandable).getString()); |
394 |
| - } else { |
395 |
| - throw new IllegalStateException("Unexpected subclass of Expandable."); |
396 |
| - } |
397 |
| - } |
398 |
| - |
399 |
| - CToolchain.FlagGroup.Builder flagGroupBuilder = CToolchain.FlagGroup.newBuilder(); |
400 |
| - if (flagGroup.getIterateOverVariable() != null) { |
401 |
| - flagGroupBuilder.setIterateOver(flagGroup.getIterateOverVariable()); |
402 |
| - } |
403 |
| - if (flagGroup.getExpandIfTrue() != null) { |
404 |
| - flagGroupBuilder.setExpandIfTrue(flagGroup.getExpandIfTrue()); |
405 |
| - } |
406 |
| - if (flagGroup.getExpandIfFalse() != null) { |
407 |
| - flagGroupBuilder.setExpandIfFalse(flagGroup.getExpandIfFalse()); |
408 |
| - } |
409 |
| - if (flagGroup.getExpandIfEqual() != null) { |
410 |
| - flagGroupBuilder.setExpandIfEqual(variableWithValueFromProto(flagGroup.getExpandIfEqual())); |
411 |
| - } |
412 |
| - return flagGroupBuilder |
413 |
| - .addAllExpandIfAllAvailable(flagGroup.getExpandIfAllAvailable()) |
414 |
| - .addAllExpandIfNoneAvailable(flagGroup.getExpandIfNoneAvailable()) |
415 |
| - .addAllFlagGroup(flagGroups.build()) |
416 |
| - .addAllFlag(flags.build()) |
417 |
| - .build(); |
418 |
| - } |
419 |
| - |
420 |
| - private static CToolchain.VariableWithValue variableWithValueFromProto( |
421 |
| - VariableWithValue variable) { |
422 |
| - return CToolchain.VariableWithValue.newBuilder() |
423 |
| - .setValue(variable.getValue()) |
424 |
| - .setVariable(variable.getVariable()) |
425 |
| - .build(); |
426 |
| - } |
427 |
| - |
428 |
| - private static CToolchain.Feature featureToProto(Feature feature) { |
429 |
| - return CToolchain.Feature.newBuilder() |
430 |
| - .setName(feature.getName()) |
431 |
| - .setEnabled(feature.isEnabled()) |
432 |
| - .addAllFlagSet( |
433 |
| - feature.getFlagSets().stream() |
434 |
| - .map(flagSet -> flagSetToProto(flagSet, /* forActionConfig= */ false)) |
435 |
| - .collect(ImmutableList.toImmutableList())) |
436 |
| - .addAllEnvSet( |
437 |
| - feature.getEnvSets().stream() |
438 |
| - .map(envSet -> envSetToProto(envSet)) |
439 |
| - .collect(ImmutableList.toImmutableList())) |
440 |
| - .addAllRequires( |
441 |
| - feature.getRequires().stream() |
442 |
| - .map(featureSet -> featureSetToProto(featureSet)) |
443 |
| - .collect(ImmutableList.toImmutableList())) |
444 |
| - .addAllImplies(feature.getImplies()) |
445 |
| - .addAllProvides(feature.getProvides()) |
446 |
| - .build(); |
447 |
| - } |
448 |
| - |
449 |
| - private static CToolchain.FlagSet flagSetToProto(FlagSet flagSet, boolean forActionConfig) { |
450 |
| - CToolchain.FlagSet.Builder flagSetBuilder = |
451 |
| - CToolchain.FlagSet.newBuilder() |
452 |
| - .addAllFlagGroup( |
453 |
| - flagSet.getFlagGroups().stream() |
454 |
| - .map(flagGroup -> flagGroupToProto(flagGroup)) |
455 |
| - .collect(ImmutableList.toImmutableList())) |
456 |
| - .addAllWithFeature( |
457 |
| - flagSet.getWithFeatureSets().stream() |
458 |
| - .map(withFeatureSet -> withFeatureSetToProto(withFeatureSet)) |
459 |
| - .collect(ImmutableList.toImmutableList())) |
460 |
| - .addAllExpandIfAllAvailable(flagSet.getExpandIfAllAvailable()); |
461 |
| - if (!forActionConfig) { |
462 |
| - flagSetBuilder.addAllAction(flagSet.getActions()); |
463 |
| - } |
464 |
| - return flagSetBuilder.build(); |
465 |
| - } |
466 |
| - |
467 |
| - private static CToolchain.FeatureSet featureSetToProto(ImmutableSet<String> features) { |
468 |
| - return CToolchain.FeatureSet.newBuilder().addAllFeature(features).build(); |
469 |
| - } |
470 |
| - |
471 |
| - private static CToolchain.Tool toolToProto(Tool tool) { |
472 |
| - return CToolchain.Tool.newBuilder() |
473 |
| - .setToolPath(tool.getToolPathFragment().toString()) |
474 |
| - .setToolPathOrigin(tool.getToolPathOrigin()) |
475 |
| - .addAllWithFeature( |
476 |
| - tool.getWithFeatureSetSets().stream() |
477 |
| - .map(withFeatureSet -> withFeatureSetToProto(withFeatureSet)) |
478 |
| - .collect(ImmutableList.toImmutableList())) |
479 |
| - .addAllExecutionRequirement(tool.getExecutionRequirements()) |
480 |
| - .build(); |
481 |
| - } |
482 |
| - |
483 |
| - private static CToolchain.ActionConfig actionConfigToProto(ActionConfig actionConfig) { |
484 |
| - return CToolchain.ActionConfig.newBuilder() |
485 |
| - .setConfigName(actionConfig.getName()) |
486 |
| - .setActionName(actionConfig.getActionName()) |
487 |
| - .setEnabled(actionConfig.isEnabled()) |
488 |
| - .addAllTool( |
489 |
| - actionConfig.getTools().stream() |
490 |
| - .map(tool -> toolToProto(tool)) |
491 |
| - .collect(ImmutableList.toImmutableList())) |
492 |
| - .addAllFlagSet( |
493 |
| - actionConfig.getFlagSets().stream() |
494 |
| - .map(flagSet -> flagSetToProto(flagSet, /* forActionConfig= */ true)) |
495 |
| - .collect(ImmutableList.toImmutableList())) |
496 |
| - .addAllImplies(actionConfig.getImplies()) |
497 |
| - .build(); |
498 |
| - } |
499 |
| - |
500 | 289 | /** Provider class for {@link CcToolchainConfigInfo} objects. */
|
501 | 290 | public static class Provider extends BuiltinProvider<CcToolchainConfigInfo>
|
502 | 291 | implements CcToolchainConfigInfoApi.Provider {
|
|
0 commit comments