From 1f2e19af682ed477b195cfcb47cef7384cb0cf2d Mon Sep 17 00:00:00 2001 From: Idan Saadon Date: Tue, 13 Aug 2024 14:12:34 +0000 Subject: [PATCH 1/2] refactor: moving `labgrid/executor` Python targets to `bazel/labgrid/executor` The previous target results in a `labgrid` import which conflicts with upstream `labgrid` module. This refactor means that the custom manager executor library is imported with `bazel.labgrid.executor`. BREAKING CHANGE: `@rules_labgrid//labgrid/executor:manager` is now `@rules_labgrid//bazel/labgrid/executor` --- bazel/labgrid/executor/BUILD.bazel | 7 +++++++ {labgrid => bazel/labgrid}/executor/manager.py | 0 e2e/docker/BUILD.bazel | 2 +- e2e/docker/manager.py | 2 +- labgrid/executor/BUILD.bazel | 10 ++-------- labgrid/executor/executor.py | 2 +- labgrid/executor/host.py | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 bazel/labgrid/executor/BUILD.bazel rename {labgrid => bazel/labgrid}/executor/manager.py (100%) diff --git a/bazel/labgrid/executor/BUILD.bazel b/bazel/labgrid/executor/BUILD.bazel new file mode 100644 index 00000000..5034f980 --- /dev/null +++ b/bazel/labgrid/executor/BUILD.bazel @@ -0,0 +1,7 @@ +load("@rules_python//python:defs.bzl", "py_library") + +py_library( + name = "executor", + srcs = ["manager.py"], + visibility = ["//visibility:public"], +) diff --git a/labgrid/executor/manager.py b/bazel/labgrid/executor/manager.py similarity index 100% rename from labgrid/executor/manager.py rename to bazel/labgrid/executor/manager.py diff --git a/e2e/docker/BUILD.bazel b/e2e/docker/BUILD.bazel index cc34f9a0..b729b8f4 100644 --- a/e2e/docker/BUILD.bazel +++ b/e2e/docker/BUILD.bazel @@ -32,7 +32,7 @@ py_library( name = "manager", srcs = ["manager.py"], data = ["local-ubuntu.16.04-gnu.yaml"], - deps = ["@rules_labgrid//labgrid/executor:manager"], + deps = ["@rules_labgrid//bazel/labgrid/executor"], ) # Create the LabGrid executor binary using our manager diff --git a/e2e/docker/manager.py b/e2e/docker/manager.py index cca44f05..192ab9df 100644 --- a/e2e/docker/manager.py +++ b/e2e/docker/manager.py @@ -5,7 +5,7 @@ from typing import Iterator from python.runfiles import Runfiles -from labgrid.executor.manager import Data, Manager +from bazel.labgrid.executor.manager import Data, Manager @contextmanager diff --git a/labgrid/executor/BUILD.bazel b/labgrid/executor/BUILD.bazel index b052be31..62a0f90d 100644 --- a/labgrid/executor/BUILD.bazel +++ b/labgrid/executor/BUILD.bazel @@ -6,17 +6,11 @@ exports_files( visibility = ["//visibility:public"], ) -py_library( - name = "manager", - srcs = ["manager.py"], - visibility = ["//visibility:public"], -) - py_binary( name = "executor", srcs = ["executor.py"], visibility = ["//visibility:public"], - deps = [":manager"], + deps = ["//bazel/labgrid/executor"], ) py_library( @@ -24,7 +18,7 @@ py_library( srcs = ["host.py"], data = ["hello-world.txt"], deps = [ - ":manager", + "//bazel/labgrid/executor", "@rules_python//python/runfiles", ], ) diff --git a/labgrid/executor/executor.py b/labgrid/executor/executor.py index c205278a..570ad65b 100644 --- a/labgrid/executor/executor.py +++ b/labgrid/executor/executor.py @@ -13,7 +13,7 @@ from shutil import which from subprocess import CalledProcessError, run from sys import argv, stderr -from labgrid.executor.manager import Manager +from bazel.labgrid.executor.manager import Manager def load(value: str) -> Manager: diff --git a/labgrid/executor/host.py b/labgrid/executor/host.py index 1e412cb7..d638d9e4 100644 --- a/labgrid/executor/host.py +++ b/labgrid/executor/host.py @@ -5,7 +5,7 @@ from typing import Iterator from python.runfiles import Runfiles -from labgrid.executor.manager import Data, Manager +from bazel.labgrid.executor.manager import Data, Manager @contextmanager -- GitLab From b8efb2ea47cb79caa7fad8078459b88b9edbc4d6 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Tue, 13 Aug 2024 15:24:49 +0100 Subject: [PATCH 2/2] refactor: add `labgrid/executor:{srcs,main}` Simplifies setting up `py_binary` targets. --- labgrid/executor/BUILD.bazel | 21 ++++++++++++++++----- labgrid/executor/macro.bzl | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/labgrid/executor/BUILD.bazel b/labgrid/executor/BUILD.bazel index 62a0f90d..ba75acaf 100644 --- a/labgrid/executor/BUILD.bazel +++ b/labgrid/executor/BUILD.bazel @@ -3,12 +3,23 @@ load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_t exports_files( ["executor.py"], +) + +alias( + name = "main", + actual = "executor.py", + visibility = ["//visibility:public"], +) + +filegroup( + name = "srcs", + srcs = ["executor.py"], visibility = ["//visibility:public"], ) py_binary( name = "executor", - srcs = ["executor.py"], + srcs = [":srcs"], visibility = ["//visibility:public"], deps = ["//bazel/labgrid/executor"], ) @@ -26,21 +37,21 @@ py_library( py_test( name = "argument", size = "small", - srcs = ["executor.py"], + srcs = [":srcs"], args = [ "--manager", "labgrid.executor.host:manager", "echo", "$${DATA}", ], - main = "executor.py", + main = ":main", deps = ["host"], ) py_test( name = "envvar", size = "small", - srcs = ["executor.py"], + srcs = [":srcs"], args = [ "echo", "$${DATA}", @@ -48,6 +59,6 @@ py_test( env = { "LABGRID_EXECUTOR_MANAGER": "labgrid.executor.host:manager", }, - main = "executor.py", + main = ":main", deps = ["host"], ) diff --git a/labgrid/executor/macro.bzl b/labgrid/executor/macro.bzl index f868e57a..da9217e8 100644 --- a/labgrid/executor/macro.bzl +++ b/labgrid/executor/macro.bzl @@ -23,8 +23,8 @@ def labgrid_executor( labels = [native.package_relative_label(d) for d in deps] py_binary( name = name, - srcs = [Label(":executor.py")], - main = "executor.py", + srcs = [Label(":srcs")], + main = Label(":main"), deps = labels + [Label("@rules_python//python/runfiles")], env = env | { "LABGRID_EXECUTOR_MANAGER": _manager(labels, manager), -- GitLab