Skip to content

Commit

Permalink
[py] Replace devtools genrule with proper generate_devtools rule. (#1…
Browse files Browse the repository at this point in the history
…1392)

The existing genrule does not handle directories properly.
  • Loading branch information
jameshilliard authored Jan 25, 2023
1 parent 3f6717d commit b803c68
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 36 deletions.
6 changes: 0 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ rules_closure_toolchains()

http_archive(
name = "rules_pkg",
patch_args = [
"-p1",
],
patches = [
"//py:rules_pkg_tree.patch",
],
sha256 = "eea0f59c28a9241156a47d7a8e32db9122f3d50b505fae0f33de6ce4d9b61834",
urls = [
"https://mirror.bazel.build/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
1 change: 0 additions & 1 deletion py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ def main(browser_protocol_path, js_protocol_path, output_path):
browser_protocol_path,
js_protocol_path,
]
output_path.mkdir(parents=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(ctx.attr.outdir)

args = ctx.actions.args()
args.add(ctx.file.browser_protocol)
args.add(ctx.file.js_protocol)
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 b803c68

Please sign in to comment.