Skip to content

Commit

Permalink
Add a build setting --//setting:stamp_manifest to disable Target-La…
Browse files Browse the repository at this point in the history
…bel stamping. (#355)

* Add a build setting to disable Target-Label stamping.

* Don't use custom COURSIER_CACHE

* Try bazelrc setting with --repo_env=COURSIER_CACHe

* Delete .bazelrc

* Disable it by default

* Tag diff_manifest_test as manual, and disable jar stamping by default
  • Loading branch information
jin authored Feb 20, 2020
1 parent f7821ed commit 27f6f3c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ tasks:
- bazel run @unpinned_regression_testing//:pin
- bazel run @unpinned_maven_install_in_custom_location//:pin
- bazel run @duplicate_artifacts_test//:pin
test_flags:
- "--//settings:stamp_manifest=True"
test_targets:
- "//..."
# manual tests
# TODO: Re-enable after fixing https://github.com/bazelbuild/rules_jvm_external/issues/375
# - "//tests/integration:UnsafeSharedCacheTest"
- "//tests/unit/manifest_stamp:diff_manifest_test" # https://github.com/bazelbuild/rules_jvm_external/issues/283
rbe_ubuntu1604:
shell_commands:
- bazel run @unpinned_regression_testing//:pin
Expand Down Expand Up @@ -72,10 +75,13 @@ tasks:
- bazel run @unpinned_regression_testing//:pin
- bazel run @unpinned_maven_install_in_custom_location//:pin
- bazel run @duplicate_artifacts_test//:pin
test_flags:
- "--//settings:stamp_manifest=True"
test_targets:
- "//..."
# manual tests
- "//tests/integration:UnsafeSharedCacheTest"
- "//tests/unit/manifest_stamp:diff_manifest_test" # https://github.com/bazelbuild/rules_jvm_external/issues/283
windows:
environment:
# This tests custom cache locations.
Expand Down
15 changes: 11 additions & 4 deletions private/rules/jvm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# [0]: https://github.com/square/bazel_maven_repository/pull/48
# [1]: https://github.com/bazelbuild/bazel/issues/4549

load("@rules_jvm_external//settings:stamp_manifest.bzl", "StampManifestProvider")

def _jvm_import_impl(ctx):
if len(ctx.files.jars) != 1:
fail("Please only specify one jar to import in the jars attribute.")
Expand All @@ -21,8 +23,7 @@ def _jvm_import_impl(ctx):
},
)

outjar_name = injar.basename[:-4] + '_stamped.jar'
outjar = ctx.actions.declare_file(outjar_name, sibling = injar)
outjar = ctx.actions.declare_file("processed_" + injar.basename, sibling = injar)
ctx.actions.run_shell(
inputs = [injar, manifest_update_file] + ctx.files._host_javabase,
outputs = [outjar],
Expand All @@ -40,10 +41,13 @@ def _jvm_import_impl(ctx):
output_jar = outjar.path,
),
]),
mnemonic = "StampJar",
progress_message = "Stamping manifest of %s" % ctx.label,
mnemonic = "StampJarManifest",
progress_message = "Stamping the manifest of %s" % ctx.label,
)

if not ctx.attr._stamp_manifest[StampManifestProvider].stamp_enabled:
outjar = injar

return [
DefaultInfo(
files = depset([outjar]),
Expand Down Expand Up @@ -89,6 +93,9 @@ jvm_import = rule(
default = Label("@rules_jvm_external//private/templates:manifest_target_label.tpl"),
allow_single_file = True,
),
"_stamp_manifest": attr.label(
default = Label("@rules_jvm_external//settings:stamp_manifest"),
)
},
implementation = _jvm_import_impl,
provides = [JavaInfo],
Expand Down
10 changes: 10 additions & 0 deletions settings/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("//settings:stamp_manifest.bzl", "stamp_manifest")

package(
default_visibility = ["//visibility:public"],
)

stamp_manifest(
name = "stamp_manifest",
build_setting_default = False,
)
9 changes: 9 additions & 0 deletions settings/stamp_manifest.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
StampManifestProvider = provider(fields = ['stamp_enabled'])

def _impl(ctx):
return StampManifestProvider(stamp_enabled = ctx.build_setting_value)

stamp_manifest = rule(
implementation = _impl,
build_setting = config.bool(flag = True)
)
4 changes: 4 additions & 0 deletions tests/unit/manifest_stamp/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@rules_jvm_external//settings:stamp_manifest.bzl", "stamp_manifest")

build_test(
name = "artifacts",
Expand Down Expand Up @@ -30,6 +31,9 @@ diff_test(
"//conditions:default": "guava_MANIFEST.MF.golden.unix",
}),
file2 = "guava_MANIFEST.MF",
# TODO(https://github.com/bazelbuild/rules_jvm_external/issues/283): Fix reproducibility issues.
# This test requires --//settings:stamp_manifest.
tags = ["manual"],
)

genrule(
Expand Down

0 comments on commit 27f6f3c

Please sign in to comment.