Skip to content

Commit c76c5c0

Browse files
authored
Merge pull request #4 from OpenAPITools/windows_compat
fix(windows): Use semicolon as classpath delimiter
2 parents 03c072a + 8cf6f6f commit c76c5c0

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

internal/openapi_generator.bzl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ def _new_generator_command(ctx, declared_dir, rjars):
2020
java_path = ctx.attr._jdk[java_common.JavaRuntimeInfo].java_executable_exec_path
2121
gen_cmd = str(java_path)
2222

23-
gen_cmd += " -cp {cli_jar}:{jars} org.openapitools.codegen.OpenAPIGenerator generate -i {spec} -g {generator} -o {output}".format(
23+
jar_delimiter = ":"
24+
if ctx.attr.is_windows:
25+
jar_delimiter = ";"
26+
27+
jars = [ctx.file.openapi_generator_cli] + rjars.to_list()
28+
29+
30+
gen_cmd += " -cp \"{jars}\" org.openapitools.codegen.OpenAPIGenerator generate -i {spec} -g {generator} -o {output}".format(
2431
java = java_path,
25-
cli_jar = ctx.file.openapi_generator_cli.path,
26-
jars = ":".join([j.path for j in rjars.to_list()]),
32+
jars = jar_delimiter.join([j.path for j in jars]),
2733
spec = ctx.file.spec.path,
2834
generator = ctx.attr.generator,
2935
output = declared_dir.path,
@@ -80,9 +86,10 @@ def _impl(ctx):
8086
# TODO: Convert to run
8187
ctx.actions.run_shell(
8288
inputs = inputs,
83-
command = "mkdir -p {gen_dir}".format(
89+
command = "mkdir -p {gen_dir} && {generator_command}".format(
8490
gen_dir = declared_dir.path,
85-
) + " && " + _new_generator_command(ctx, declared_dir, rjars),
91+
generator_command = _new_generator_command(ctx, declared_dir, rjars)
92+
),
8693
outputs = [declared_dir],
8794
tools = ctx.files._jdk,
8895
)
@@ -123,7 +130,7 @@ def _collect_jars(targets):
123130

124131
return struct(compiletime = compile_jars, runtime = runtime_jars)
125132

126-
openapi_generator = rule(
133+
_openapi_generator = rule(
127134
attrs = {
128135
# downstream dependencies
129136
"deps": attr.label_list(),
@@ -142,6 +149,7 @@ openapi_generator = rule(
142149
"additional_properties": attr.string_dict(),
143150
"system_properties": attr.string_dict(),
144151
"type_mappings": attr.string_dict(),
152+
"is_windows": attr.bool(mandatory = True),
145153
"_jdk": attr.label(
146154
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
147155
providers = [java_common.JavaRuntimeInfo],
@@ -154,3 +162,13 @@ openapi_generator = rule(
154162
},
155163
implementation = _impl,
156164
)
165+
166+
def openapi_generator(name, **kwargs):
167+
_openapi_generator(
168+
name = name,
169+
is_windows = select({
170+
"@bazel_tools//src/conditions:windows": True,
171+
"//conditions:default": False,
172+
}),
173+
**kwargs
174+
)

0 commit comments

Comments
 (0)