Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-azarchs committed Jun 7, 2022
1 parent 54421e5 commit d0d892f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ build --tool_java_language_version=11

# User-specific .bazelrc
try-import user.bazelrc

build --java_runtime_version=remote_jdk11
10 changes: 10 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,13 @@ REMOTE_PLATFORMS = ("rbe_ubuntu1804_java11",)
)
for platform_name in REMOTE_PLATFORMS
]

toolchain(
name = "java_toolchain",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = "@bazel_tools//tools/jdk:remotejdk11_linux",
toolchain_type = "@bazel_tools//tools/jdk:runtime_toolchain_type",
)
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,7 @@ debian_deps()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

register_toolchains(
"//:java_toolchain",
)
53 changes: 48 additions & 5 deletions site/en/docs/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,59 @@ py_test(
)
```

If you are using a hermetic python toolchain, you can instead simply add
If you are using a hermetic python toolchain, instead of adding an attribute to
every `py_test` rule you can instead add the coverage tool to the toolchain
configuration.

Because the `pip_install` rule depends on the python toolchain, you cannot use
it to fetch the `coverage` module. Instead, add in your `WORKSPACE` e.g.

```starlark
coverage_tool = ":coverage",
http_archive(
name = "coverage_linux_x86_64"",
build_file_content = """
filegroup(
name = "coverage",
srcs = ["coverage/__main__.py"],
data = glob(["coverage/*", "coverage/**/*.py"]),
visibility = ["//visibility:public"],
)
""",
sha256 = "84631e81dd053e8a0d4967cedab6db94345f1c36107c71698f746cb2636c63e3",
type = "zip",
urls = [
"https://files.pythonhosted.org/packages/74/0d/0f3c522312fd27c32e1abe2fb5c323b583a5c108daf2c26d6e8dfdd5a105/coverage-6.4.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
],
)
```

to your `py_runtime` target. This ensures that coverage is available for all
`py_test` and `py_binary` targets, and prevents those targets from incurring a
dependency on `coverage` except when building with coverage enabled.
Then configure your python toolchain as e.g.

```starlark
py_runtime(
name = "py3_runtime_linux_x86_64",
coverage_tool = "@coverage_linux_x86_64//:coverage",
files = ["@python3_9_x86_64-unknown-linux-gnu//:files"],
interpreter = "@python3_9_x86_64-unknown-linux-gnu//:bin/python3",
python_version = "PY3",
)

py_runtime_pair(
name = "python_runtimes_linux_x86_64",
py2_runtime = None,
py3_runtime = ":py3_runtime_linux_x86_64",
)

toolchain(
name = "python_toolchain_linux_x86_64",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":python_runtimes_linux_x86_64",
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)
```

[lcov]: https://github.com/linux-test-project/lcov
[rules_python]: https://github.com/bazelbuild/rules_python
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/bazel_coverage_hermetic_py_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ python_register_toolchains(
)
http_archive(
name = "coverage_linux_x64",
name = "coverage_linux_x86_64",
build_file_content = """
filegroup(
name = "coverage",
Expand Down Expand Up @@ -105,7 +105,7 @@ load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
py_runtime(
name = "py3_runtime",
coverage_tool = "@coverage_linux_x64//:coverage",
coverage_tool = "@coverage_linux_x86_64//:coverage",
files = ["@python3_9_x86_64-unknown-linux-gnu//:files"],
interpreter = "@python3_9_x86_64-unknown-linux-gnu//:bin/python3",
python_version = "PY3",
Expand Down
1 change: 1 addition & 0 deletions src/tools/singlejar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ cc_library(
":zip_headers",
],
hdrs = ["output_jar.h"],
linkopts = ["-lm"],
deps = [
":combiners",
":diag",
Expand Down
1 change: 1 addition & 0 deletions tools/jdk/BUILD.java_tools
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ cc_library(
hdrs = ["java_tools/src/tools/singlejar/output_jar.h"],
copts = SUPRESSED_WARNINGS,
strip_include_prefix = "java_tools",
linkopts = ["-lm"],
deps = [
":combiners",
":cpp_util",
Expand Down

0 comments on commit d0d892f

Please sign in to comment.