Skip to content

Commit

Permalink
Add support for bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
BradHolmes committed Jan 3, 2025
1 parent 5ea617b commit c4136e4
Show file tree
Hide file tree
Showing 17 changed files with 2,309 additions and 40 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ jobs:
# Build
- name: Build all target
run: |
cd internal/test
cd internal/test/basic
bazel build //...
- name: Integration BCR test
run: |
cd internal/test/bcr
bazel mod path
bazel build //...
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
name = "openapi_tools_generator_bazel",
version = "0.1.7",
compatibility_level = 0,
)

bazel_dep(name = "rules_pkg", version = "1.0.1")
openapi_gen = use_extension("@openapi_tools_generator_bazel//:extension.bzl", "openapi_gen")
openapi_gen.client()
use_repo(openapi_gen, "openapi_tools_generator_bazel_cli")

535 changes: 535 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions WORKSPACE

This file was deleted.

2 changes: 0 additions & 2 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
load(
"//internal:openapi_generator.bzl",
_openapi_generator = "openapi_generator",
_openapi_tools_generator_bazel_repositories = "openapi_tools_generator_bazel_repositories",
)

openapi_generator = _openapi_generator

openapi_tools_generator_bazel_repositories = _openapi_tools_generator_bazel_repositories
29 changes: 29 additions & 0 deletions extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"modules extension to use with openapi-generator-bazel"
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

def _openapi_generator_impl(module_ctx):
for mod in module_ctx.modules:
for install in mod.tags.client:
jvm_maven_import_external(
name = "openapi_tools_generator_bazel_cli",
artifact_sha256 = install.sha256,
artifact = "org.openapitools:openapi-generator-cli:" + install.version,
server_urls = install.server_urls,
)

_cli = tag_class(attrs = {
"version": attr.string(
default = "7.2.0",
),
"sha256": attr.string(
default = "1cf0c80de12c0fdc8594289c19e414b402108ef10b8dd0bfda1953151341ab5d",
),
"server_urls": attr.string_list(
default = ["https://repo1.maven.org/maven2"],
),
})
openapi_gen = module_extension(
implementation = _openapi_generator_impl,
tag_classes = {"client": _cli},
)

22 changes: 1 addition & 21 deletions internal/openapi_generator.bzl
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
# Copyright 2019 OpenAPI-Generator-Bazel Contributors

load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

def openapi_tools_generator_bazel_repositories(
openapi_generator_cli_version = "6.5.0",
sha256 = "f18d771e98f2c5bb169d1d1961de4f94866d2901abc1e16177dd7e9299834721",
prefix = "openapi_tools_generator_bazel",
server_urls = [
"https://repo1.maven.org/maven2"
]):
jvm_maven_import_external(
name = "openapi_tools_generator_bazel_cli",
artifact_sha256 = sha256,
artifact = "org.openapitools:openapi-generator-cli:" + openapi_generator_cli_version,
server_urls = server_urls,
)
native.bind(
name = prefix + "/dependency/openapi-generator-cli",
actual = "@" + prefix + "_cli//jar",
)

def _comma_separated_pairs(pairs):
return ",".join([
"{}={}".format(k, v)
Expand Down Expand Up @@ -193,7 +173,7 @@ _openapi_generator = rule(
),
"openapi_generator_cli": attr.label(
cfg = "exec",
default = Label("//external:openapi_tools_generator_bazel/dependency/openapi-generator-cli"),
default = Label("@openapi_tools_generator_bazel_cli//:openapi_tools_generator_bazel_cli"),
allow_single_file = True,
),
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions internal/test/bcr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-bcr
bazel-bin
bazel-out
bazel-testlogs
9 changes: 9 additions & 0 deletions internal/test/bcr/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@openapi_tools_generator_bazel//:defs.bzl", "openapi_generator")

openapi_generator(
name = "pylib",
config = "config.yaml",
spec = "petstore.yaml",
generator = "python",
)

13 changes: 13 additions & 0 deletions internal/test/bcr/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module(
name = "openapi_tools_generator_bazel_bcr_tests",
version = "1.2.3",
)

bazel_dep(name = "openapi_tools_generator_bazel", version = "")
local_path_override(
module_name = "openapi_tools_generator_bazel",
path = "../../..",
)
openapi_gen = use_extension("@openapi_tools_generator_bazel//:extension.bzl", "openapi_gen")
use_repo(openapi_gen, "openapi_tools_generator_bazel_cli")

Loading

0 comments on commit c4136e4

Please sign in to comment.