Skip to content

Commit

Permalink
Restructure ruleset to conform to style guide (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum authored Apr 27, 2024
1 parent 764d241 commit 7cb9c69
Show file tree
Hide file tree
Showing 45 changed files with 142 additions and 57 deletions.
10 changes: 8 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
test --test_output=errors

# Isolate sandboxed build actions from each other.
build --sandbox_tmpfs_path=/tmp
common --sandbox_tmpfs_path=/tmp

# Prevent PATH from being inherited from the environment.
build --incompatible_strict_action_env
common --incompatible_strict_action_env

common --java_language_version=8
common --java_runtime_version=remotejdk_21

common --tool_java_language_version=21
common --tool_java_runtime_version=remotejdk_21
2 changes: 1 addition & 1 deletion .github/workflows/run-tests-externally.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: bazelisk test --config=ci --disk_cache=${{ matrix.cache }} --profile=${{ github.workspace }}/profile.gz ${{ matrix.bazel_extra_args }} //...

- name: Check coverage
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.jdk == '17') }}
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.jdk == '8' || matrix.jdk == '21') }}
env:
USE_BAZEL_VERSION: ${{ matrix.bazel }}
working-directory: ./tests
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_license", version = "0.0.7")

download_jdk_deps = use_extension(
"@rules_jni//bzlmod:extensions.bzl",
"@rules_jni//jni/private/extensions:download_jdk_deps.bzl",
"download_jdk_deps",
)
use_repo(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ rules_jni_dependencies()

## Documentation

See the documentation for [targets](docs/targets.md), [rules](docs/rules.md)
and [workspace macros](docs/workspace_macros.md) provided by rules_jni.
See the documentation for [targets](docs/targets.md), [rules](docs-gen/rules.md)
and [workspace macros](docs-gen/workspace_macros.md) provided by rules_jni.

## Examples

Expand Down
4 changes: 4 additions & 0 deletions docs-gen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports_files(
glob(["*.md"]),
visibility = ["//docs:__pkg__"],
)
File renamed without changes.
File renamed without changes.
19 changes: 4 additions & 15 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ javadoc(

stardoc(
name = "rules",
out = "rules_gen.md",
out = "rules.md",
input = "//jni:defs.bzl",
deps = ["//jni:all_rules"],
)
Expand All @@ -19,12 +19,12 @@ diff_test(
name = "rules_test",
failure_message = "Please run:\n bazel run //docs:update",
file1 = "rules.md",
file2 = "rules_gen.md",
file2 = "//docs-gen:rules.md",
)

stardoc(
name = "workspace_macros",
out = "workspace_macros_gen.md",
out = "workspace_macros.md",
input = "//jni:repositories.bzl",
deps = ["//jni:all_rules"],
)
Expand All @@ -33,18 +33,7 @@ diff_test(
name = "workspace_macros_test",
failure_message = "Please run:\n bazel run //docs:update",
file1 = "workspace_macros.md",
file2 = "workspace_macros_gen.md",
)

write_file(
name = "update_script",
out = "update.sh",
content = [
"#!/bin/sh",
"cd $BUILD_WORKSPACE_DIRECTORY",
"cp -fv bazel-bin/docs/rules_gen.md docs/rules.md",
"cp -fv bazel-bin/docs/workspace_macros_gen.md docs/workspace_macros.md",
],
file2 = "//docs-gen:workspace_macros.md",
)

sh_binary(
Expand Down
14 changes: 9 additions & 5 deletions docs/update_docs.sh → docs/update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
# Copyright 2021 Fabian Meumertzheim
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,8 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

bazel_bin_dir=$(bazel info bazel-bin)
docs_dir=$(realpath "$(dirname "$0")")
set -euo pipefail

bazel build //docs:all
cp -f "${bazel_bin_dir}/docs/rules.md" "${bazel_bin_dir}/docs/workspace_macros.md" "${docs_dir}"
cd "$BUILD_WORKSPACE_DIRECTORY"

bazel build $(bazel query 'kind(stardoc, //docs:all)')

mkdir -p docs-gen
cp -fv bazel-bin/docs/rules.md docs-gen/rules.md
cp -fv bazel-bin/docs/workspace_macros.md docs-gen/workspace_macros.md
11 changes: 7 additions & 4 deletions jni/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ exports_files(glob(["*.bzl"]))

alias(
name = "jni",
actual = "//jni/internal:jni",
actual = "//jni/private:jni",
applicable_licenses = ["//:jdk_license"],
visibility = ["//visibility:public"],
)

alias(
name = "libjvm",
actual = "//jni/tools/libjvm_stub:libjvm_stub_with_jni",
actual = "//jni/private/tools/libjvm_stub:libjvm_stub_with_jni",
visibility = ["//visibility:public"],
)

alias(
name = "libjvm_lite",
actual = "//jni/tools/libjvm_stub:libjvm_stub_release_with_jni",
actual = "//jni/private/tools/libjvm_stub:libjvm_stub_release_with_jni",
visibility = ["//visibility:public"],
)

bzl_library(
name = "all_rules",
srcs = [
"cc_jni_library.bzl",
"defs.bzl",
"java_jni_library.bzl",
"jni_headers.bzl",
"repositories.bzl",
],
visibility = ["//visibility:public"],
deps = [
"//jni/internal:all_rules",
"//jni/private:all_rules",
],
)
19 changes: 19 additions & 0 deletions jni/cc_jni_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Fabian Meumertzheim
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jni/private:cc_jni_library.bzl", _cc_jni_library = "cc_jni_library")

visibility("public")

cc_jni_library = _cc_jni_library
10 changes: 6 additions & 4 deletions jni/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jni/internal:cc_jni_library.bzl", _cc_jni_library = "cc_jni_library")
load("//jni/internal:java_jni_library.bzl", _java_jni_library = "java_jni_library")
load("//jni/internal:jni_headers.bzl", _jni_headers = "jni_headers")
load(":cc_jni_library.bzl", _cc_jni_library = "cc_jni_library")
load(":java_jni_library.bzl", _java_jni_library = "java_jni_library")
load(":jni_headers.bzl", _jni_headers = "jni_headers")

visibility("public")

cc_jni_library = _cc_jni_library
java_jni_library = _java_jni_library
jni_headers = _jni_headers
cc_jni_library = _cc_jni_library
19 changes: 19 additions & 0 deletions jni/java_jni_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Fabian Meumertzheim
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jni/private:java_jni_library.bzl", _java_jni_library = "java_jni_library")

visibility("public")

java_jni_library = _java_jni_library
19 changes: 19 additions & 0 deletions jni/jni_headers.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Fabian Meumertzheim
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jni/private:jni_headers.bzl", _jni_headers = "jni_headers")

visibility("public")

jni_headers = _jni_headers
4 changes: 2 additions & 2 deletions jni/internal/BUILD.bazel → jni/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ cc_library(
cc_library(
name = "jni_md",
hdrs = select({
"@platforms//os:windows": ["//jni/internal/windows:jni_md_h"],
"//conditions:default": ["//jni/internal/unix:jni_md_h"],
"@platforms//os:windows": ["//jni/private/windows:jni_md_h"],
"//conditions:default": ["//jni/private/unix:jni_md_h"],
}),
includes = select({
"@platforms//os:windows": ["windows"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ load(":jni_headers.bzl", "jni_headers")
load(":os_cpu_utils.bzl", "SELECT_TARGET_CPU", "SELECT_TARGET_OS")
load(":transitions.bzl", "multi_platform_transition")

visibility("//jni")

SinglePlatformArtifactInfo = provider(
fields = ["cpu", "file", "os", "platform"],
)
Expand Down
2 changes: 2 additions & 0 deletions jni/internal/common.bzl → jni/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

visibility("//jni/private/tools/...")

def _merge_default_infos(ctx, infos):
return DefaultInfo(
files = depset(transitive = [info.files for info in infos]),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.

load("@bazel_skylib//lib:modules.bzl", "modules")
load("//jni/internal:repositories.bzl", "jdk_deps")
load("//jni/private:repositories.bzl", "jdk_deps")

download_jdk_deps = modules.as_extension(jdk_deps)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load(":common.bzl", "merge_java_infos")
load(":jni_headers.bzl", "jni_headers")

visibility("//jni")

def java_jni_library(
name,
native_libs = [],
Expand Down
2 changes: 2 additions & 0 deletions jni/internal/jni_headers.bzl → jni/private/jni_headers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load(":transitions.bzl", "return_to_original_target_platforms_transition")

visibility("//jni")

def _jni_headers_impl(ctx):
# Giving the include directory a name with a header extension ensures
# compatibility with Bazel 4.0.0, which only considers the extension and not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

visibility("private")

CPUS = [
"aarch64",
"arm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

visibility("//jni/...")

def jdk_deps():
maybe(
http_file,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//jni/internal:common.bzl", "make_root_relative", "merge_cc_infos")
load("//jni/private:common.bzl", "make_root_relative", "merge_cc_infos")
load(":current_java_runtime.bzl", "current_java_runtime")
load(":current_repository.bzl", "RULES_JNI_REPOSITORY_DEFINE")

Expand Down Expand Up @@ -69,7 +69,7 @@ cc_library(
"//conditions:default": ["-ldl"],
}),
local_defines = select({
"//jni/internal:collect_coverage": ["RULES_JNI_COLLECT_COVERAGE=1"],
"//jni/private:collect_coverage": ["RULES_JNI_COLLECT_COVERAGE=1"],
"//conditions:default": [],
}),
deps = [
Expand All @@ -88,11 +88,11 @@ cc_library(
"rules_jni_internal.h",
],
data = select({
"//jni/internal:collect_coverage": ["//jni/tools/libjvm_stub/coverage:CoverageAgent_deploy.jar"],
"//jni/private:collect_coverage": ["//jni/private/tools/libjvm_stub/coverage:CoverageAgent_deploy.jar"],
"//conditions:default": [],
}),
local_defines = [RULES_JNI_REPOSITORY_DEFINE] + select({
"//jni/internal:collect_coverage": ["RULES_JNI_COLLECT_COVERAGE=1"],
"//jni/private:collect_coverage": ["RULES_JNI_COLLECT_COVERAGE=1"],
"//conditions:default": [],
}),
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <utility>
#include <vector>

#include "jni/tools/libjvm_stub/current_java_runtime.h"
#include "jni/private/tools/libjvm_stub/current_java_runtime.h"
#include "rules_jni_internal.h"
#include "tools/cpp/runfiles/runfiles.h"

Expand Down Expand Up @@ -155,7 +155,7 @@ jint rules_jni_create_java_vm_for_coverage(
if (runfiles != nullptr) {
coverage_agent = runfiles->Rlocation(
RULES_JNI_REPOSITORY
"/jni/tools/libjvm_stub/coverage/CoverageAgent_deploy.jar");
"/jni/private/tools/libjvm_stub/coverage/CoverageAgent_deploy.jar");
} else if (getenv(RULES_JNI_COVERAGE_AGENT_JAR) != nullptr) {
// This should only every happen in tests.
coverage_agent = getenv(RULES_JNI_COVERAGE_AGENT_JAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ java_binary(
deploy_manifest_lines = [
"Premain-Class: com.github.fmeum.rules_jni.libjvm_stub.CoverageAgent",
],
visibility = ["//jni/tools/libjvm_stub:__pkg__"],
visibility = ["//jni/private/tools/libjvm_stub:__pkg__"],
deps = [
"@bazel_tools//tools/jdk:JacocoCoverageRunner",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

visibility("private")

def rlocation_path(ctx, short_path):
return paths.normalize(ctx.workspace_name + "/" + short_path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

visibility("private")

RULES_JNI_REPOSITORY_DEFINE = "RULES_JNI_REPOSITORY=\\\"%s\\\"" % Label("//:LICENSE").workspace_name
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion jni/internal/transitions.bzl → jni/private/transitions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

visibility("private")

_COMMAND_LINE_OPTION_PLATFORMS = "//command_line_option:platforms"
_SETTING_PRE_TRANSITION_PLATFORMS = str(Label("//jni/internal:pre_transition_platforms"))
_SETTING_PRE_TRANSITION_PLATFORMS = str(Label("//jni/private:pre_transition_platforms"))

def _multi_platform_transition_impl(settings, attrs):
if not attrs.platforms:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ copy_file(
src = "@com_github_openjdk_jdk_unix_jni_md_h//file",
out = "jni_md.h",
is_executable = False,
visibility = ["//jni/internal:__pkg__"],
visibility = ["//jni/private:__pkg__"],
)
Loading

0 comments on commit 7cb9c69

Please sign in to comment.