From 0fb0f9ef151c7904cdeb224f13a98fd941a59ede Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Sun, 20 Aug 2023 20:45:15 -0700 Subject: [PATCH] feat: dependency support for components - feat: collect and track component dependencies in bindist - feat: resolve and traverse dependencies (flat) on install - chore: map initial component dependencies Signed-off-by: Sam Gammon --- MODULE.bazel | 1 + MODULE.bazel.lock | 32 +++++++++++------------ docs/api/BUILD.bazel | 1 + internal/config.bzl | 1 + internal/graalvm_bindist.bzl | 31 ++++++++++++++++++++-- internal/graalvm_bindist_map.bzl | 10 ++++--- lib/BUILD.bazel | 1 + tools/scripts/mapping_generator/render.py | 10 ++++--- 8 files changed, 63 insertions(+), 24 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index d2ff94db..b9bf9406 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,6 +14,7 @@ GRAALVM_DIST = "ce" GRAALVM_SDK_VERSION = "23.0.1" GRAALVM_COMPONENTS = [ "wasm", + "js", ] ## diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index adc71a9f..c65b41e9 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 1, - "moduleFileHash": "5ece49b5eed722d4b4a69c5f07cb655c8e17efec2e604cb706dbd6982714857f", + "moduleFileHash": "de10ed86a95e3c6bd3ddda9da976c6018665c0842f47b540f868d0ac59577cbe", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -32,7 +32,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 143, + "line": 144, "column": 22 }, "imports": { @@ -50,7 +50,7 @@ "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 148, + "line": 149, "column": 14 } } @@ -64,7 +64,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 164, + "line": 165, "column": 20 }, "imports": { @@ -76,11 +76,11 @@ "tags": [ { "tagName": "graalvm", - "attributeValues": {"name":"--graalvm","components":["--wasm"],"distribution":"--ce","java_version":"--20","version":"--20.0.2"}, + "attributeValues": {"name":"--graalvm","components":["--wasm","--js"],"distribution":"--ce","java_version":"--20","version":"--20.0.2"}, "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 169, + "line": 170, "column": 12 } } @@ -94,7 +94,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 189, + "line": 190, "column": 23 }, "imports": { @@ -112,7 +112,7 @@ "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 194, + "line": 195, "column": 17 } } @@ -126,7 +126,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 200, + "line": 201, "column": 20 }, "imports": { @@ -144,7 +144,7 @@ "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 206, + "line": 207, "column": 10 } } @@ -158,7 +158,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 220, + "line": 221, "column": 21 }, "imports": {}, @@ -170,7 +170,7 @@ "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 226, + "line": 227, "column": 15 } } @@ -184,7 +184,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 228, + "line": 229, "column": 20 }, "imports": { @@ -200,7 +200,7 @@ "devDependency": true, "location": { "file": "@@//:MODULE.bazel", - "line": 234, + "line": 235, "column": 23 } } @@ -3863,13 +3863,13 @@ } }, "//:extensions.bzl%graalvm": { - "bzlTransitiveDigest": "cNb2JthPMcR2HW9uhVOQGm8mFgYvgs+A6d2hFIJH7HM=", + "bzlTransitiveDigest": "g+5jGAzcblQwfDqiFSuS7qM7bzx+TMWCKl4g0iUaIQY=", "envVariables": {}, "generatedRepoSpecs": { "graalvm": { "bzlFile": "@@//internal:graalvm_bindist.bzl", "ruleClassName": "_graalvm_bindist_repository", - "attributes": {"name":"--_main~graalvm~graalvm","version":"--20.0.2","java_version":"--20","distribution":"--ce","components":["--wasm"],"setup_actions":[],"enable_toolchain":true,"toolchain_config":"--graalvm_toolchain_config_repo","sha256":"--"} + "attributes": {"name":"--_main~graalvm~graalvm","version":"--20.0.2","java_version":"--20","distribution":"--ce","components":["--wasm","--js"],"setup_actions":[],"enable_toolchain":true,"toolchain_config":"--graalvm_toolchain_config_repo","sha256":"--"} }, "graalvm_toolchain_config_repo": { "bzlFile": "@@//internal:graalvm_bindist.bzl", diff --git a/docs/api/BUILD.bazel b/docs/api/BUILD.bazel index 90b7cc95..90ecacc8 100755 --- a/docs/api/BUILD.bazel +++ b/docs/api/BUILD.bazel @@ -24,6 +24,7 @@ stardoc( "//lib:tooling", "//lib/nativeimage:internals", "//lib/nativeimage:rules", + "@bazel_skylib//lib:new_sets", "@bazel_skylib//lib:paths", ], ) diff --git a/internal/config.bzl b/internal/config.bzl index b0929996..bde4b7c9 100644 --- a/internal/config.bzl +++ b/internal/config.bzl @@ -51,6 +51,7 @@ MAVEN_REPOSITORIES = [ GRAALVM_COMPONENTS = [ "wasm", + "js", ] TARGET_JAVA_VERSIONS = [ diff --git a/internal/graalvm_bindist.bzl b/internal/graalvm_bindist.bzl index 81751788..0cded9f8 100644 --- a/internal/graalvm_bindist.bzl +++ b/internal/graalvm_bindist.bzl @@ -8,6 +8,10 @@ load( "@bazel_skylib//lib:paths.bzl", "paths", ) +load( + "@bazel_skylib//lib:new_sets.bzl", + "sets", +) load( "//internal:jdk_build_file.bzl", _JDK_BUILD_TEMPLATE = "JDK_BUILD_TEMPLATE", @@ -15,6 +19,7 @@ load( ) load( "//internal:graalvm_bindist_map.bzl", + "ComponentDependencies", "VmReleaseVersions", "resolve_distribution_artifact", Component = "DistributionComponent", @@ -151,6 +156,25 @@ alias( path = path, ) +def _build_component_graph(components): + """Resolve dependencies for all components, returning each set first in a list which is eventually flattened. + + If there are no dependencies, the component itself is returned as the only list member.""" + + effective_components = [] + unique_components = sets.make(components) + found_dependencies = False + for component in components: + deps = ComponentDependencies.get(component, None) + if deps != None: + found_dependencies = True + stanza = [i for i in (deps + [component]) if not sets.contains(unique_components, i)] + [sets.insert(unique_components, i) for i in stanza] + effective_components += stanza + else: + effective_components.append(component) + return effective_components + def _graal_bindist_repository_impl(ctx): """Implements the GraalVM repository rule (`graalvm_repository`).""" @@ -325,9 +349,12 @@ def _graal_bindist_repository_impl(ctx): if ctx.attr.components and len(ctx.attr.components) > 0: ctx.report_progress("Downloading %s GraalVM components" % len(ctx.attr.components)) + # address dependencies + resolved_components = _build_component_graph(ctx.attr.components) + all_url_hash_pairs = [ (c, _get_artifact_info(ctx, distribution, platform, version, component = c, strict = False)) - for c in ctx.attr.components + for c in resolved_components ] downloads = [] manual = [] @@ -369,7 +396,7 @@ def _graal_bindist_repository_impl(ctx): stderr = exec_result.stderr, )) - all_components.extend(ctx.attr.components) + all_components.extend(resolved_components) _bin_paths.extend( [(n, v) for (k, n, v) in _conditional_paths if k in all_components], ) diff --git a/internal/graalvm_bindist_map.bzl b/internal/graalvm_bindist_map.bzl index 80e90016..74cc37ce 100644 --- a/internal/graalvm_bindist_map.bzl +++ b/internal/graalvm_bindist_map.bzl @@ -42,9 +42,13 @@ _DistributionComponent = struct( # Lists dependencies for known components. # buildifier: disable=name-conventions -_ComponentDependencies = struct( - JS = [_DistributionComponent.REGEX, _DistributionComponent.ICU4J], -) +_ComponentDependencies = { + "regex": [_DistributionComponent.ICU4J], + "js": [_DistributionComponent.ICU4J, _DistributionComponent.REGEX], + "python": [_DistributionComponent.LLVM], + "ruby": [_DistributionComponent.LLVM], + "llvm-toolchain": [_DistributionComponent.LLVM], +} # Aligned GraalVM distribution versions. # buildifier: disable=name-conventions diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 28e01ecb..82308896 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -108,6 +108,7 @@ bzl_library( ":engines", ":java_toolchains", ":tooling", + "@bazel_skylib//lib:new_sets", ], ) diff --git a/tools/scripts/mapping_generator/render.py b/tools/scripts/mapping_generator/render.py index f200bf00..78891fcb 100644 --- a/tools/scripts/mapping_generator/render.py +++ b/tools/scripts/mapping_generator/render.py @@ -66,9 +66,13 @@ # Lists dependencies for known components. # buildifier: disable=name-conventions -_ComponentDependencies = struct( - JS = [_DistributionComponent.REGEX, _DistributionComponent.ICU4J], -) +_ComponentDependencies = { + "regex": [_DistributionComponent.ICU4J], + "js": [_DistributionComponent.ICU4J, _DistributionComponent.REGEX], + "python": [_DistributionComponent.LLVM], + "ruby": [_DistributionComponent.LLVM], + "llvm-toolchain": [_DistributionComponent.LLVM], +} # Aligned GraalVM distribution versions. # buildifier: disable=name-conventions