Skip to content

Commit

Permalink
Add initial support for CDS images
Browse files Browse the repository at this point in the history
    PiperOrigin-RevId: 295770802
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent d63dcf5 commit f7f2267
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.Runfiles.Builder;
import com.google.devtools.build.lib.analysis.TransitionMode;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.LauncherFileWriteAction;
Expand All @@ -38,6 +37,7 @@
import com.google.devtools.build.lib.analysis.actions.Substitution.ComputedSubstitution;
import com.google.devtools.build.lib.analysis.actions.Template;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.test.TestConfiguration;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
Expand Down Expand Up @@ -184,7 +184,7 @@ public ImmutableList<Artifact> collectResources(RuleContext ruleContext) {
return ImmutableList.of();
}

return ruleContext.getPrerequisiteArtifacts("resources", TransitionMode.TARGET).list();
return ruleContext.getPrerequisiteArtifacts("resources", Mode.TARGET).list();
}

/**
Expand Down Expand Up @@ -219,12 +219,12 @@ public String getValue() {
if (!isRunfilesEnabled) {
buffer.append("$(rlocation ");
PathFragment runfilePath =
PathFragment.create(workspacePrefix).getRelative(artifact.getRootRelativePath());
PathFragment.create(workspacePrefix).getRelative(artifact.getRunfilesPath());
buffer.append(runfilePath.getPathString());
buffer.append(")");
} else {
buffer.append("${RUNPATH}");
buffer.append(artifact.getRootRelativePath().getPathString());
buffer.append(artifact.getRunfilesPath().getPathString());
}
}
buffer.append("\"");
Expand Down Expand Up @@ -617,7 +617,7 @@ public String addCoverageSupport(JavaCompilationHelper helper, Artifact executab

// Add the coverage runner to the list of dependencies when compiling in coverage mode.
TransitiveInfoCollection runnerTarget =
helper.getRuleContext().getPrerequisite("$jacocorunner", TransitionMode.TARGET);
helper.getRuleContext().getPrerequisite("$jacocorunner", Mode.TARGET);
if (JavaInfo.getProvider(JavaCompilationArgsProvider.class, runnerTarget) != null) {
helper.addLibrariesToAttributes(ImmutableList.of(runnerTarget));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class DeployArchiveBuilder {
@Nullable private Function<Artifact, Artifact> derivedJars = null;
private boolean checkDesugarDeps;
private OneVersionEnforcementLevel oneVersionEnforcementLevel = OneVersionEnforcementLevel.OFF;
@Nullable private Artifact oneVersionAllowlistArtifact;
@Nullable private Artifact oneVersionWhitelistArtifact;
@Nullable private Artifact sharedArchive;

/** Type of compression to apply to output archive. */
Expand Down Expand Up @@ -164,9 +164,9 @@ public DeployArchiveBuilder setCheckDesugarDeps(boolean checkDesugarDeps) {
/** Whether or not singlejar would attempt to enforce one version of java classes in the jar */
public DeployArchiveBuilder setOneVersionEnforcementLevel(
OneVersionEnforcementLevel oneVersionEnforcementLevel,
@Nullable Artifact oneVersionAllowlistArtifact) {
@Nullable Artifact oneVersionWhitelistArtifact) {
this.oneVersionEnforcementLevel = oneVersionEnforcementLevel;
this.oneVersionAllowlistArtifact = oneVersionAllowlistArtifact;
this.oneVersionWhitelistArtifact = oneVersionWhitelistArtifact;
return this;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLine(
Artifact launcher,
boolean usingNativeSinglejar,
OneVersionEnforcementLevel oneVersionEnforcementLevel,
@Nullable Artifact oneVersionAllowlistArtifact) {
@Nullable Artifact oneVersionWhitelistArtifact) {

CustomCommandLine.Builder args = CustomCommandLine.builder();
args.addExecPath("--output", outputJar);
Expand Down Expand Up @@ -255,8 +255,8 @@ public static CustomCommandLine.Builder defaultSingleJarCommandLine(
args.add("--enforce_one_version");
// RuleErrors should have been added in Builder.build() before this command
// line is invoked.
Preconditions.checkNotNull(oneVersionAllowlistArtifact);
args.addExecPath("--one_version_whitelist", oneVersionAllowlistArtifact);
Preconditions.checkNotNull(oneVersionWhitelistArtifact);
args.addExecPath("--one_version_whitelist", oneVersionWhitelistArtifact);
if (oneVersionEnforcementLevel == OneVersionEnforcementLevel.WARNING) {
args.add("--succeed_on_found_violations");
}
Expand Down Expand Up @@ -333,12 +333,12 @@ public void build() throws InterruptedException {
}

if (oneVersionEnforcementLevel != OneVersionEnforcementLevel.OFF) {
if (oneVersionAllowlistArtifact == null) {
if (oneVersionWhitelistArtifact == null) {
OneVersionCheckActionBuilder.addRuleErrorForMissingArtifacts(
ruleContext, JavaToolchainProvider.from(ruleContext));
return;
}
inputs.add(oneVersionAllowlistArtifact);
inputs.add(oneVersionWhitelistArtifact);
}
if (sharedArchive != null) {
inputs.add(sharedArchive);
Expand All @@ -364,7 +364,7 @@ public void build() throws InterruptedException {
launcher,
usingNativeSinglejar,
oneVersionEnforcementLevel,
oneVersionAllowlistArtifact,
oneVersionWhitelistArtifact,
sharedArchive);
if (checkDesugarDeps) {
commandLine = CommandLine.concat(commandLine, ImmutableList.of("--check_desugar_deps"));
Expand All @@ -375,7 +375,6 @@ public void build() throws InterruptedException {
if (!usingNativeSinglejar) {
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.addTransitiveInputs(inputs.build())
.addTransitiveInputs(JavaRuntimeInfo.forHost(ruleContext).javaBaseInputsMiddleman())
.addOutput(outputJar)
Expand All @@ -391,7 +390,6 @@ public void build() throws InterruptedException {
} else {
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.addTransitiveInputs(inputs.build())
.addOutput(outputJar)
.setResources(DEPLOY_ACTION_RESOURCE_SET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
try {
dynamicRuntimeActionInputs = ccToolchain.getDynamicRuntimeLinkInputs(featureConfiguration);
} catch (EvalException e) {
throw ruleContext.throwWithRuleError(e);
throw ruleContext.throwWithRuleError(e.getMessage());
}

collectDefaultRunfiles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
Expand Down Expand Up @@ -172,20 +173,19 @@ static Label hostJdkAttribute(RuleDefinitionEnvironment env) {
ImmutableList.copyOf(javaConfig.getExtraProguardSpecs()));

@AutoCodec
LabelLateBoundDefault<JavaConfiguration> BYTECODE_OPTIMIZER =
LabelLateBoundDefault.fromTargetConfiguration(
LabelListLateBoundDefault<JavaConfiguration> BYTECODE_OPTIMIZERS =
LabelListLateBoundDefault.fromTargetConfiguration(
JavaConfiguration.class,
null,
(rule, attributes, javaConfig) -> {
// Use a modicum of smarts to avoid implicit dependencies where we don't need them.
boolean hasProguardSpecs =
attributes.has("proguard_specs")
&& !attributes.get("proguard_specs", LABEL_LIST).isEmpty();
JavaConfiguration.NamedLabel optimizer = javaConfig.getBytecodeOptimizer();
if (!hasProguardSpecs || !optimizer.label().isPresent()) {
return null;
if (!hasProguardSpecs) {
return ImmutableList.<Label>of();
}
return optimizer.label().get();
return ImmutableList.copyOf(
Optional.presentInstances(javaConfig.getBytecodeOptimizers().values()));
});

String JACOCO_METADATA_PLACEHOLDER = "%set_jacoco_metadata%";
Expand Down Expand Up @@ -328,6 +328,10 @@ static boolean isTestTargetAndPersistentTestRunner(RuleContext ruleContext) {
&& ruleContext.getFragment(TestConfiguration.class).isPersistentTestRunner();
}

static boolean isPersistentTestRunner(RuleContext ruleContext) {
return ruleContext.getFragment(TestConfiguration.class).isPersistentTestRunner();
}

static Runfiles getTestSupportRunfiles(RuleContext ruleContext) {
TransitiveInfoCollection testSupport = getTestSupport(ruleContext);
if (testSupport == null) {
Expand Down

0 comments on commit f7f2267

Please sign in to comment.