Skip to content

Commit ae3ee14

Browse files
committed
Remove hacky WORKSPACE method, and rely on archive_override
1 parent ae9c1d4 commit ae3ee14

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed

README.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ Here are the instructions for quickly using the generator:
1515

1616
### Adding the Module
1717

18-
There is a [known issue](#not-hosted-in-a-bazel-registry) where this module can't be manually added
19-
into the `MODULE.bazel` file.
20-
The current method is to follow modify the `WORKSPACE` file, not relying on Bazel's module system.
21-
22-
When the issue is resolved, and this module is added to a Bazel registry,
23-
the dependency is added by inserting this line into `MODULE.bazel`:
18+
The dependency is added by inserting these lines into `MODULE.bazel`:
2419
```skylark
2520
bazel_dep(name = "swift-openapi-generator", version = "1.0.0-alpha1")
21+
archive_override(
22+
module_name = "swift-openapi-generator",
23+
integrity = "sha256-wx04p5+/Kzp062CkvY+I+Dho+qRqEY9rQd7Ow/uI9KA=",
24+
strip_prefix = "bazel-swift-openapi-generator-0.0.1-dev.2",
25+
urls = ["https://github.com/Dreksh/bazel-swift-openapi-generator/archive/refs/tags/v0.0.1-dev.2.tar.gz"],
26+
)
2627
```
2728

2829
### Using the Rule
@@ -80,24 +81,3 @@ single_version_override(
8081
patch_strip = 1, # Remove 1 directory level, as it's a git diff
8182
)
8283
```
83-
84-
### Not Hosted in a Bazel Registry
85-
86-
Since this is not in the bazel registry yet, the module will need to be added via the WORKSPACE.
87-
This is due to the `swift-openapi-generator` bazel module containing another repository dependency, which requires
88-
Accessing the `@swift-openapi-generator//:extensions.bzl` file to load.
89-
90-
The steps to do this is:
91-
1. Add this to the `WORKSPACE` file:
92-
```skylark
93-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
94-
95-
http_archive(
96-
name = "swift-openapi-generator",
97-
url = "https://github.com/Dreksh/bazel-swift-openapi-generator/archive/refs/tags/v1.0.0-alpha.1.tar.gz",
98-
# sha256 = "5ddbe9c50cb72017e93b83531af6dd5f580b04e3f2e922a093af4e609db35dfa", (SHA not known at time of writing)
99-
strip_prefix = "bazel-swift-openapi-generator-1.0.0-alpha.1",
100-
)
101-
load("@swift-openapi-generator//:extensions.bzl", swift_openapi_generator_deps = "deps")
102-
swift_openapi_generator_deps(repository_name="@swift-openapi-generator")
103-
```

extensions.bzl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# THIS IS AUTO-GENERATED BY bazel run //:update
22
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
33

4-
# Exposing this for others to declare dependencies in their WORKSPACE
5-
def deps(repository_name):
4+
def _load_code_impl(module_ctx):
65
http_archive(
76
name = "swift-openapi-generator-code",
87
url = "https://github.com/apple/swift-openapi-generator/archive/refs/tags/1.0.0-alpha.1.tar.gz",
98
sha256 = "dc79d7779357f387a94f59e55a64cb041c13828a6318b99931f154122f66d600",
109
strip_prefix = "swift-openapi-generator-1.0.0-alpha.1",
1110

12-
patches = [repository_name + "//:internal/swift-openapi-generator.patch"], # Add pre-calculated bazel files to the repo
13-
patch_args = ["-p1"], # Using Git-diff requires stripping the first path
11+
patches = ["//:internal/swift-openapi-generator.patch"], # Add pre-calculated bazel files to the repo
12+
patch_args = ["-p1"], # Using Git-diff requires stripping the first path
1413
)
1514

16-
def _load_code_impl(module_ctx):
17-
deps("") # Using current repository
18-
1915
load_code = module_extension(
2016
implementation = _load_code_impl,
2117
doc = "Fetches the source code from the swift-openapi-generator git repository.",

internal/extensions.bzl.template

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

3-
# Exposing this for others to declare dependencies in their WORKSPACE
4-
def deps(repository_name):
3+
def _load_code_impl(module_ctx):
54
http_archive(
65
name = "swift-openapi-generator-code",
76
url = "{URL}",
87
sha256 = "{SHASUM}",
98
strip_prefix = "swift-openapi-generator-{VERSION}",
109

11-
patches = [repository_name + "//:internal/swift-openapi-generator.patch"], # Add pre-calculated bazel files to the repo
12-
patch_args = ["-p1"], # Using Git-diff requires stripping the first path
10+
patches = ["//:internal/swift-openapi-generator.patch"], # Add pre-calculated bazel files to the repo
11+
patch_args = ["-p1"], # Using Git-diff requires stripping the first path
1312
)
1413

15-
def _load_code_impl(module_ctx):
16-
deps("") # Using current repository
17-
1814
load_code = module_extension(
1915
implementation = _load_code_impl,
2016
doc = "Fetches the source code from the swift-openapi-generator git repository.",

0 commit comments

Comments
 (0)