Skip to content

Commit 758565c

Browse files
authored
Merge pull request #190 from hjellek/fix-python-scripts
Fix dupe_check for Bazel 7
2 parents 4eec7f1 + b56c5ec commit 758565c

File tree

6 files changed

+34
-41
lines changed

6 files changed

+34
-41
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
#
77

8+
common --enable_bzlmod
9+
810
# **********************************
911
# ARTIFACT STAMPING
1012
# **********************************

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.1
1+
6.5.0

MODULE.bazel

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
module(
2-
name = "rules_spring",
3-
version = "2.3.1",
4-
repo_name = "rules_spring",
5-
compatibility_level = 1,
2+
name = "rules_spring",
3+
version = "2.3.1",
4+
compatibility_level = 1,
5+
repo_name = "rules_spring",
6+
)
7+
8+
bazel_dep(name = "rules_python", version = "0.31.0")
9+
10+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
11+
python.toolchain(
12+
is_default = True,
13+
python_version = "3.11",
614
)

springboot/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# See the README.md file for detailed usage instructions.
1212

13+
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
14+
1315
exports_files([
1416
"springboot.bzl",
1517
"springboot_pkg.sh",

springboot/springboot.bzl

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def _dupeclasses_rule_impl(ctx):
103103
inputs = []
104104
input_args = ctx.actions.args()
105105

106-
# inputs (dupe checker python script, spring boot jar file, ignorelist)
107-
inputs.append(ctx.attr.script.files.to_list()[0])
108-
input_args.add(ctx.attr.script.files.to_list()[0].path)
106+
# inputs (spring boot jar file, ignorelist)
109107
inputs.append(ctx.attr.springbootjar.files.to_list()[0])
110108
input_args.add(ctx.attr.springbootjar.files.to_list()[0].path)
111109
if ctx.attr.dupeclassescheck_ignorelist != None:
@@ -117,12 +115,9 @@ def _dupeclasses_rule_impl(ctx):
117115
# add the output file to the args, so python script knows where to write result
118116
input_args.add(output.path)
119117

120-
# compute the location of python
121-
python_interpreter = _compute_python_executable(ctx)
122-
123118
# run the dupe checker
124119
ctx.actions.run(
125-
executable = python_interpreter,
120+
executable = ctx.executable.script,
126121
outputs = outputs,
127122
inputs = inputs,
128123
arguments = [input_args],
@@ -135,13 +130,16 @@ _dupeclasses_rule = rule(
135130
implementation = _dupeclasses_rule_impl,
136131
attrs = {
137132
"dupeclasses_rule": attr.label(),
138-
"script": attr.label(),
133+
"script": attr.label(
134+
executable = True,
135+
cfg = "exec",
136+
allow_files = True,
137+
),
139138
"springbootjar": attr.label(),
140-
"dupeclassescheck_ignorelist": attr.label(allow_files=True),
139+
"dupeclassescheck_ignorelist": attr.label(allow_files = True),
141140
"dupeclassescheck_enable": attr.bool(),
142141
"out": attr.string(),
143142
},
144-
toolchains = ["@bazel_tools//tools/python:toolchain_type"],
145143
)
146144

147145
# ***************************************************************
@@ -159,9 +157,7 @@ def _javaxdetect_rule_impl(ctx):
159157
inputs = []
160158
input_args = ctx.actions.args()
161159

162-
# inputs (dupe checker python script, spring boot jar file, ignorelist)
163-
inputs.append(ctx.attr.script.files.to_list()[0])
164-
input_args.add(ctx.attr.script.files.to_list()[0].path)
160+
# inputs (spring boot jar file, ignorelist)
165161
inputs.append(ctx.attr.springbootjar.files.to_list()[0])
166162
input_args.add(ctx.attr.springbootjar.files.to_list()[0].path)
167163
if ctx.attr.javaxdetect_ignorelist != None:
@@ -173,12 +169,9 @@ def _javaxdetect_rule_impl(ctx):
173169
# add the output file to the args, so python script knows where to write result
174170
input_args.add(output.path)
175171

176-
# compute the location of python
177-
python_interpreter = _compute_python_executable(ctx)
178-
179172
# run the dupe checker
180173
ctx.actions.run(
181-
executable = python_interpreter,
174+
executable = ctx.executable.script,
182175
outputs = outputs,
183176
inputs = inputs,
184177
arguments = [input_args],
@@ -191,31 +184,18 @@ _javaxdetect_rule = rule(
191184
implementation = _javaxdetect_rule_impl,
192185
attrs = {
193186
"javaxdetect_rule": attr.label(),
194-
"script": attr.label(),
187+
"script": attr.label(
188+
executable = True,
189+
cfg = "exec",
190+
allow_files = True,
191+
),
195192
"springbootjar": attr.label(),
196-
"javaxdetect_ignorelist": attr.label(allow_files=True),
193+
"javaxdetect_ignorelist": attr.label(allow_files = True),
197194
"javaxdetect_enable": attr.bool(),
198195
"out": attr.string(),
199196
},
200-
toolchains = ["@bazel_tools//tools/python:toolchain_type"],
201197
)
202198

203-
def _compute_python_executable(ctx):
204-
python_interpreter = None
205-
206-
# hard requirement on python3 being available
207-
python_runtime = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"].py3_runtime
208-
if python_runtime != None:
209-
if python_runtime.interpreter != None:
210-
# registered python toolchain, or the Bazel python wrapper script (for system python)
211-
python_interpreter = python_runtime.interpreter
212-
elif python_runtime.interpreter_path != None:
213-
# legacy python only?
214-
python_interpreter = python_runtime.interpreter_path
215-
216-
# print(python_interpreter)
217-
return python_interpreter
218-
219199
# ***************************************************************
220200
# BANNED DEPS RULE
221201

tools/python_interpreter/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Licensed under the BSD 3-Clause license.
55
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
#
7+
load("@rules_python//python:defs.bzl", "py_binary")
78

89
#
910
# PYTHON PATH

0 commit comments

Comments
 (0)