Skip to content

Commit

Permalink
[bazel] Added new java_toolchain entry timezoneData support.
Browse files Browse the repository at this point in the history
--
PiperOrigin-RevId: 147741120
MOS_MIGRATED_REVID=147741120
  • Loading branch information
Googler authored and dslomov committed Feb 17, 2017
1 parent 577fd46 commit 5a1af9c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.devtools.build.lib.cmdline.Label;
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.packages.BuildType;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
Expand Down Expand Up @@ -77,6 +78,9 @@ public ConfiguredTarget create(RuleContext ruleContext)
attributesBuilder.addClassPathResources(
ruleContext.getPrerequisiteArtifacts("classpath_resources", Mode.TARGET).list());

// Add Java8 timezone resource data
addTimezoneResourceForJavaBinaries(ruleContext, attributesBuilder);

List<String> userJvmFlags = JavaCommon.getJvmFlags(ruleContext);

ruleContext.checkSrcsSamePackage(true);
Expand Down Expand Up @@ -429,6 +433,16 @@ private ImmutableList<String> getDeployManifestLines(RuleContext ruleContext,
return builder.build();
}

/** Add Java8 timezone resource jar to java binary, if specified in tool chain. */
private void addTimezoneResourceForJavaBinaries(
RuleContext ruleContext, JavaTargetAttributes.Builder attributesBuilder) {
JavaToolchainProvider toolchainProvider = JavaToolchainProvider.fromRuleContext(ruleContext);
if (toolchainProvider.getTimezoneData() != null) {
attributesBuilder.addResourceJars(
NestedSetBuilder.create(Order.STABLE_ORDER, toolchainProvider.getTimezoneData()));
}
}

private void collectDefaultRunfiles(Runfiles.Builder builder, RuleContext ruleContext,
JavaCommon common, JavaCompilationArtifacts javaArtifacts, NestedSet<Artifact> filesToBuild,
Artifact launcher, Iterable<Artifact> dynamicRuntimeActionInputs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorExceptio
Artifact oneVersionWhitelist = getArtifact("oneversion_whitelist", ruleContext);
Artifact genClass = getArtifact("genclass", ruleContext);
Artifact resourceJarBuilder = getArtifact("resourcejar", ruleContext);
Artifact timezoneData = getArtifact("timezone_data", ruleContext);
FilesToRunProvider ijar = ruleContext.getExecutablePrerequisite("ijar", Mode.HOST);
ImmutableListMultimap<String, String> compatibleJavacOptions =
getCompatibleJavacOptions(ruleContext);
Expand Down Expand Up @@ -93,6 +94,7 @@ public ConfiguredTarget create(RuleContext ruleContext) throws RuleErrorExceptio
oneVersionWhitelist,
genClass,
resourceJarBuilder,
timezoneData,
ijar,
compatibleJavacOptions);
RuleConfiguredTargetBuilder builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static JavaToolchainProvider create(
Artifact oneVersionWhitelist,
Artifact genClass,
@Nullable Artifact resourceJarBuilder,
@Nullable Artifact timezoneData,
FilesToRunProvider ijar,
ImmutableListMultimap<String, String> compatibleJavacOptions) {
return new AutoValue_JavaToolchainProvider(
Expand All @@ -72,6 +73,7 @@ public static JavaToolchainProvider create(
oneVersionWhitelist,
genClass,
resourceJarBuilder,
timezoneData,
ijar,
compatibleJavacOptions,
// merges the defaultJavacFlags from
Expand Down Expand Up @@ -137,6 +139,13 @@ public static JavaToolchainProvider create(
@Nullable
public abstract Artifact getResourceJarBuilder();

/**
* Returns the {@link Artifact} of the latest timezone data resource jar that can be loaded by
* Java 8 binaries.
*/
@Nullable
public abstract Artifact getTimezoneData();

/** Returns the ijar executable */
public abstract FilesToRunProvider getIjar();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ The encoding of the java files (e.g., 'UTF-8').
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("resourcejar", LABEL_LIST).cfg(HOST).allowedFileTypes(FileTypeSet.ANY_FILE).exec())
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(timezone_data) -->
Label of a resource jar containing timezone data. If set, the timezone data is added as an
implicitly runtime dependency of all java_binary rules.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("timezone_data", LABEL).cfg(HOST).allowedFileTypes(FileTypeSet.ANY_FILE).exec())
/* <!-- #BLAZE_RULE(java_toolchain).ATTRIBUTE(ijar) -->
Label of the ijar executable.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
Expand Down

0 comments on commit 5a1af9c

Please sign in to comment.