Skip to content

Commit

Permalink
[py] Replace devtools genrule with proper generate_devtools rule.
Browse files Browse the repository at this point in the history
The existing genrule does not handle directories properly.
  • Loading branch information
jameshilliard committed Dec 13, 2022
1 parent 29e1cf6 commit 06becaa
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
6 changes: 0 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ rules_closure_toolchains()

http_archive(
name = "rules_pkg",
patch_args = [
"-p1",
],
patches = [
"//py:rules_pkg_tree.patch",
],
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.8.0/rules_pkg-0.8.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.8.0/rules_pkg-0.8.0.tar.gz",
Expand Down
22 changes: 9 additions & 13 deletions py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
load("@py_dev_requirements//:requirements.bzl", "requirement")
load("//common:defs.bzl", "copy_file")
load("//py:defs.bzl", "py_test_suite")
load("//py:defs.bzl", "generate_devtools", "py_test_suite")
load("//py/private:browsers.bzl", "BROWSERS")
load("//py/private:import.bzl", "py_import")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
Expand Down Expand Up @@ -273,18 +273,14 @@ py_binary(
deps = [requirement("inflection")],
)

[genrule(
name = "create-cdp-srcs-" + n,
srcs = [
"//common/devtools/chromium/" + n + ":browser_protocol",
"//common/devtools/chromium/" + n + ":js_protocol",
],
outs = ["selenium/webdriver/common/devtools/" + n],
cmd = "$(location :generate) $(location //common/devtools/chromium/" + n + ":browser_protocol) $(location //common/devtools/chromium/" + n + ":js_protocol) $@",
tools = [
":generate",
],
) for n in BROWSER_VERSIONS]
[generate_devtools(
name = "create-cdp-srcs-{}".format(devtools_version),
outdir = "selenium/webdriver/common/devtools/{}".format(devtools_version),
browser_protocol = "//common/devtools/chromium/{}:browser_protocol".format(devtools_version),
generator = ":generate",
js_protocol = "//common/devtools/chromium/{}:js_protocol".format(devtools_version),
protocol_version = devtools_version,
) for devtools_version in BROWSER_VERSIONS]

py_test_suite(
name = "unit",
Expand Down
2 changes: 2 additions & 0 deletions py/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
load("//py/private:generate_devtools.bzl", _generate_devtools = "generate_devtools")
load("//py/private:import.bzl", _py_import = "py_import")
load("//py/private:pytest.bzl", _pytest_test = "pytest_test")
load("//py/private:suite.bzl", _py_test_suite = "py_test_suite")

generate_devtools = _generate_devtools
pytest_test = _pytest_test
py_import = _py_import
py_test_suite = _py_test_suite
2 changes: 1 addition & 1 deletion py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def main(browser_protocol_path, js_protocol_path, output_path):
browser_protocol_path,
js_protocol_path,
]
output_path.mkdir(parents=True)
output_path.mkdir(parents=True, exist_ok=True)

# Generate util.py
util_path = output_path / "util.py"
Expand Down
50 changes: 50 additions & 0 deletions py/private/generate_devtools.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
def _generate_devtools_impl(ctx):
outdir = ctx.actions.declare_directory("{}".format(ctx.attr.outdir))

args = ctx.actions.args()
args.add(ctx.attr.browser_protocol.files.to_list()[0])
args.add(ctx.attr.js_protocol.files.to_list()[0])
args.add(outdir.path)

ctx.actions.run(
executable = ctx.executable.generator,
progress_message = "Generating {} DevTools Protocol bindings for Python".format(ctx.attr.protocol_version),
arguments = [args],
outputs = [
outdir,
],
inputs = [
ctx.file.browser_protocol,
ctx.file.js_protocol,
],
use_default_shell_env = True,
)

return DefaultInfo(
files = depset([outdir]),
runfiles = ctx.runfiles(files = [outdir]),
)

generate_devtools = rule(
implementation = _generate_devtools_impl,
attrs = {
"protocol_version": attr.string(
mandatory = True,
default = "",
),
"browser_protocol": attr.label(
mandatory = True,
allow_single_file = True,
),
"js_protocol": attr.label(
mandatory = True,
allow_single_file = True,
),
"outdir": attr.string(),
"generator": attr.label(
executable = True,
cfg = "exec",
),
"deps": attr.label_list(),
},
)
16 changes: 0 additions & 16 deletions py/rules_pkg_tree.patch

This file was deleted.

0 comments on commit 06becaa

Please sign in to comment.