Skip to content

Commit

Permalink
Fixup generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Dec 29, 2023
1 parent bf8aca2 commit 7d65995
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 73 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "rules_bzlmodrio_jdk",
version = "0.0.0",
version = "17.0.8+7",
compatibility_level = 2024,
)

Expand All @@ -14,7 +14,7 @@ bazel_dep(name = "rules_bzlmodrio_toolchains", version = "2024-1")
REMOTE_JDK_REPOS = [
"roboriojdk_linux",
"roboriojdk_mac",
"roboriojdk_win",
"roboriojdk_windows",
]

[use_repo(
Expand Down
10 changes: 5 additions & 5 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions generate/auto_update.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import os
import re
from bazelrio_gentool.auto_update_utils import get_latest_tag, split_tag
from bazelrio_gentool.auto_update_utils import download_url


def main():
raise
contents = download_url("https://raw.githubusercontent.com/wpilibsuite/WPILibInstaller-Avalonia/main/scripts/versions.gradle")

for line in contents.decode("utf-8").split("\n"):
search = re.search("ext.jdkVersion = '(.*)'", line)
if search:
version = search[1]


SCRIPT_DIR = os.environ["BUILD_WORKSPACE_DIRECTORY"]

file_to_replace = os.path.join(SCRIPT_DIR, "get_toolchain_dependencies.py")

with open(file_to_replace, "r") as f:
contents = f.read()
contents = re.sub(
'( +)jdk_version = "(.*)"', f'\\1jdk_version = "{version}"', contents
)

with open(file_to_replace, "w") as f:
f.write(contents)
print(version)


if __name__ == "__main__":
Expand Down
10 changes: 7 additions & 3 deletions generate/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from bazelrio_gentool.generate_shared_files import get_bazel_dependencies
from bazelrio_gentool.cli import add_generic_cli, GenericCliArgs
from get_toolchain_dependencies import get_toolchain_dependencies
import argparse
import os

Expand All @@ -26,13 +27,15 @@ def main():
add_generic_cli(parser)
args = parser.parse_args()

group = get_toolchain_dependencies()

mandatory_dependencies = create_default_mandatory_settings(GenericCliArgs(args))

write_shared_root_files(REPO_DIR, dict(repo_name="rules_bzlmodrio_jdk"))
write_shared_test_files(REPO_DIR, dict())
write_shared_root_files(REPO_DIR, group)
write_shared_test_files(REPO_DIR, group)

template_files = [
# "templates/maven_deps.bzl",
"maven_deps.bzl",
"WORKSPACE",
"MODULE.bazel",
"tests/WORKSPACE",
Expand All @@ -45,6 +48,7 @@ def main():
os.path.join(SCRIPT_DIR, "templates"),
bazel_dependencies=get_bazel_dependencies(),
mandatory_dependencies=mandatory_dependencies,
group=group,
)


Expand Down
58 changes: 58 additions & 0 deletions generate/get_toolchain_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from bazelrio_gentool.deps.sha256_helper import get_hash


def get_toolchain_dependencies():
class PlatformConfig:
def __init__(self, repo_os, platforms_os, strip_prefix, suffix):
self.repo_os = repo_os
self.platforms_os = platforms_os
self.strip_prefix = strip_prefix
self.suffix = suffix

def get_sha256(self):
return get_hash(self.get_url(), fail_on_miss=True)

def get_url(self):
return f"https://github.com/adoptium/temurin17-binaries/releases/download/jdk-{escaped_version}/OpenJDK17U-jdk_x64_{self.repo_os}_hotspot_{underscore_version}.{self.suffix}"

platforms = []

jdk_version = "17.0.8+7"
underscore_version = jdk_version.replace("+", "_")
escaped_version = jdk_version.replace("+", "%2B")

platforms.append(
PlatformConfig(
repo_os="linux",
platforms_os="linux",
strip_prefix="jdk-" + jdk_version,
suffix="tar.gz",
)
)
platforms.append(
PlatformConfig(
repo_os="mac",
platforms_os="macos",
strip_prefix="jdk-" + jdk_version + "/Contents/Home",
suffix="tar.gz",
)
)
platforms.append(
PlatformConfig(
repo_os="windows",
platforms_os="windows",
strip_prefix="jdk-" + jdk_version,
suffix="zip",
)
)

output = dict(
repo_name="rules_bzlmodrio_jdk",
platforms=platforms,
jdk_version=jdk_version,
escaped_version=escaped_version,
underscore_version=underscore_version,
jre_version=17,
)

return output
2 changes: 1 addition & 1 deletion generate/get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def main():
raise
print(get_toolchain_dependencies()['jdk_version'])


if __name__ == "__main__":
Expand Down
7 changes: 2 additions & 5 deletions generate/templates/MODULE.bazel.jinja2
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
module(
name = "rules_bzlmodrio_jdk",
version = "0.0.0",
version = "{{group.jdk_version}}",
compatibility_level = 2024,
)

{{bazel_dependencies.platforms.module_dep()}}
{{bazel_dependencies.rules_java.module_dep()}}

deps = use_extension("//:maven_deps.bzl", "deps")
use_repo(deps, "roborio_jre")

{{ mandatory_dependencies.rules_bzlmodrio_toolchain.module_dep() }}

REMOTE_JDK_REPOS = [
"roboriojdk_linux",
"roboriojdk_mac",
"roboriojdk_win",
"roboriojdk_windows",
]

print(REMOTE_JDK_REPOS)

[use_repo(
deps,
repo,
Expand Down
35 changes: 17 additions & 18 deletions generate/templates/maven_deps.bzl.jinja2
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_java//toolchains:remote_java_repository.bzl", "remote_java_repository")


def __setup_jdk_dependencies(mctx):
{%- for config in group.configs %}
# {{config.short_name}}
{%- for platform_config in config.cpp_platform_configs %}
maybe(
http_archive,
"bazelrio_{{config.short_name_underscore}}_toolchain_{{platform_config.os}}",
url = "{{config.get_cpp_url(platform_config)}}",
sha256 = "{{config.get_cpp_sha256(platform_config)}}",
build_file_content = filegroup_all,
{%- if platform_config.patch_toolchain %}
patches = [
"@bazelrio//libraries/toolchains/{{config.year}}/{{config.release_version_underscore}}/patches:libc_no_sandboxfs.patch",
"@bazelrio//libraries/toolchains/{{config.year}}/{{config.release_version_underscore}}/patches:libpthread_no_sandboxfs.patch",
{%- for platform in group.platforms %}
remote_java_repository(
name = "roboriojdk_{{platform.repo_os}}",
prefix = "roboriojdk",
version = "{{group.jre_version}}",
target_compatible_with = [
"@platforms//os:{{platform.platforms_os}}",
],
{%- endif %}
sha256 = "{{platform.get_sha256()}}",
urls = ["{{platform.get_url()}}"],
strip_prefix = "{{platform.strip_prefix}}",
)
{%- endfor %}
{%- endfor %}
{% endfor %}

def setup_legacy_setup_jdk_dependencies():
__setup_jdk_dependencies(None)

REMOTE_JDK_REPOS = ["roboriojdk_linux", "roboriojdk_mac", "roboriojdk_win"]
[native.register_toolchains("@" + name + "_toolchain_config_repo//:all") for name in REMOTE_JDK_REPOS]


deps = module_extension(
__setup_jdk_dependencies,
)
Expand Down
20 changes: 10 additions & 10 deletions maven_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def __setup_jdk_dependencies(mctx):
target_compatible_with = [
"@platforms//os:linux",
],
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.4.1%2B1/OpenJDK17U-jdk_x64_linux_hotspot_17.0.4.1_1.tar.gz"],
sha256 = "5fbf8b62c44f10be2efab97c5f5dbf15b74fae31e451ec10abbc74e54a04ff44",
strip_prefix = "jdk-17.0.4.1+1",
sha256 = "aa5fc7d388fe544e5d85902e68399d5299e931f9b280d358a3cbee218d6017b0",
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.8_7.tar.gz"],
strip_prefix = "jdk-17.0.8+7",
)

remote_java_repository(
Expand All @@ -20,21 +20,21 @@ def __setup_jdk_dependencies(mctx):
target_compatible_with = [
"@platforms//os:macos",
],
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.4.1%2B1/OpenJDK17U-jdk_x64_mac_hotspot_17.0.4.1_1.tar.gz"],
sha256 = "ac21a5a87f7cfa00212ab7c41f7eb80ca33640d83b63ad850be811c24095d61a",
strip_prefix = "jdk-17.0.4.1+1/Contents/Home",
sha256 = "6fea89cea64a0f56ecb9e5d746b4921d2b0a80aa65c92b265ee9db52b44f4d93",
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8%2B7/OpenJDK17U-jdk_x64_mac_hotspot_17.0.8_7.tar.gz"],
strip_prefix = "jdk-17.0.8+7/Contents/Home",
)

remote_java_repository(
name = "roboriojdk_win",
name = "roboriojdk_windows",
prefix = "roboriojdk",
version = "17",
target_compatible_with = [
"@platforms//os:windows",
],
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.4.1%2B1/OpenJDK17U-jdk_x64_windows_hotspot_17.0.4.1_1.zip"],
sha256 = "3860d2ed7405674baeb0f9f4c71377421716759fe4301e92bdd4dd43c0442dc3",
strip_prefix = "jdk-17.0.4.1+1",
sha256 = "341a7243778802019a100ba7ae32a05a3f4ae5fd64dbf2a970d02f07c7d1c804",
urls = ["https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8%2B7/OpenJDK17U-jdk_x64_windows_hotspot_17.0.8_7.zip"],
strip_prefix = "jdk-17.0.8+7",
)

def setup_legacy_setup_jdk_dependencies():
Expand Down
Loading

0 comments on commit 7d65995

Please sign in to comment.