1
+ load ("@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" )
2
+ load ("@bazel_tools//tools/build_defs/repo:utils.bzl" , "maybe" )
3
+
1
4
versions = struct (
2
5
RULES_KOTLIN = struct (
3
6
urls = [
@@ -6,6 +9,13 @@ versions = struct(
6
9
sha256 = "d8650bb939d87a080448ffbbbd1594f5ae054738df5d9471941c18784aa139b9" ,
7
10
prefix = "rules_kotlin-1.5.0-beta-3" ,
8
11
),
12
+ RULES_KOTLIN_HEAD = struct (
13
+ urls = [
14
+ "https://github.com/bazelbuild/rules_kotlin/archive/refs/heads/master.zip" ,
15
+ ],
16
+ sha256 = "cd5388f019d856ede82dd2a3dc7cf935d4925340fee56094f1e23d93a62b5439" ,
17
+ prefix = "rules_kotlin-master" ,
18
+ ),
9
19
)
10
20
11
21
def archive_repository_implementation (repository_ctx ):
@@ -38,10 +48,31 @@ def archive_repository_implementation(repository_ctx):
38
48
# move to execroot, then reference local repo.
39
49
workspace = repository_ctx .path ("../../%s" % release_archive .workspace_root )
40
50
51
+ if not workspace .exists :
52
+ fail ("local workspace %s does not exist" % workspace )
53
+
41
54
target = "//%s:%s" % (release_archive .package , release_archive .name )
42
55
56
+ workspace_file = workspace .get_child ("WORKSPACE" )
57
+
58
+ # if kt_download_local_dev_dependencies isn't there, the WORKSPACE file is invalid
59
+ # probably generated by http_archive.
60
+ if not ("kt_download_local_dev_dependencies" in repository_ctx .read (workspace_file )):
61
+ repository_ctx .report_progress (
62
+ "Symlinking WORKSPACE to WORKSPACE.dev.bazel in %s" % (workspace .basename ),
63
+ )
64
+
65
+ # Remove existing WORKSPACE, as it might be created by http_archive
66
+ repository_ctx .delete (workspace_file )
67
+
68
+ # Symlink the WORKSPACE
69
+ repository_ctx .symlink (
70
+ workspace .get_child ("WORKSPACE.dev.bazel" ),
71
+ workspace_file ,
72
+ )
73
+
43
74
repository_ctx .report_progress (
44
- "Building %s in %s... (may take a while.)" % (target , workspace ),
75
+ "Building %s in %s... (may take a while.)" % (target , workspace . basename ),
45
76
)
46
77
47
78
result = repository_ctx .execute (
@@ -66,10 +97,12 @@ def archive_repository_implementation(repository_ctx):
66
97
)
67
98
68
99
# update release when the contents change.
69
- return [
70
- repository_ctx .path ("../../%s" % release_archive .workspace_root ),
71
- ]
72
- return []
100
+ return {
101
+ "release_archive" : str (workspace ),
102
+ }
103
+ return {
104
+ "release_archive" : "" ,
105
+ }
73
106
74
107
# not windows compatible.
75
108
def _find_workspace (attr , environ , path ):
@@ -99,7 +132,6 @@ _archive_repository = repository_rule(
99
132
),
100
133
"local_release_archive_target" : attr .label (
101
134
doc = "release_archive rule." ,
102
- default = Label ("@rules_kotlin_release//:rules_kotlin_release" ),
103
135
),
104
136
"env_archive" : attr .string (
105
137
doc = "release archive path environment variable name" ,
@@ -116,17 +148,46 @@ _archive_repository = repository_rule(
116
148
},
117
149
)
118
150
119
- def archive_repository (name , local_path = "../.." , release_archive_target = Label ("//:rules_kotlin_release" )):
120
- release_name = "%s_head" % name
121
- if not native .existing_rule (release_name ):
122
- native .local_repository (
123
- name = release_name ,
151
+ def archive_repository (
152
+ name ,
153
+ local_path = "../.." ,
154
+ release_archive_target = Label ("//:rules_kotlin_release" ),
155
+ remote_source_archive = None ,
156
+ source_repository_name = None ):
157
+ """
158
+ archive_repository builds rules_kotlin from either a local_path or a remote archive.
159
+
160
+ Args:
161
+ name: of the repository
162
+ local_path: to an un-archived rules_kotlin repository. Defaults to '../..'.
163
+ release_archive_target: Label to build a rules_kotlin release
164
+ remote_source_archive: struct(
165
+ urls = list of urls for a remote source archive,
166
+ sha256 = hash of remote archive,
167
+ prefix = directory string to strip from extracted archive
168
+ )
169
+ source_repository_name: of the release archive. Defaults to `name`_head. If set to an existing
170
+ repository no new repository will be created.
171
+ """
172
+ source_repository_name = source_repository_name or ("%s_head" % name )
173
+ if remote_source_archive :
174
+ maybe (
175
+ http_archive ,
176
+ name = source_repository_name ,
177
+ sha256 = remote_source_archive .sha256 ,
178
+ strip_prefix = remote_source_archive .prefix ,
179
+ urls = remote_source_archive .urls ,
180
+ )
181
+ else :
182
+ maybe (
183
+ native .local_repository ,
184
+ name = source_repository_name ,
124
185
path = local_path ,
125
186
)
126
187
_archive_repository (
127
188
name = name ,
128
189
local_release_archive_target = "@%s//%s:%s" % (
129
- release_name ,
190
+ source_repository_name ,
130
191
release_archive_target .package ,
131
192
release_archive_target .name ,
132
193
),
0 commit comments