Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/rules_labgrid
1 result
Show changes
Commits on Source (26)
Showing
with 4556 additions and 1201 deletions
.cache
e2e
examples
include:
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/hooks@v1.4.0"
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/hooks@v1.5.0"
inputs:
extends:
- .base
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/version@v1.4.0"
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/version@v1.5.0"
inputs:
extends:
- .base
......@@ -12,9 +12,9 @@ include:
versions:
- 7.4.0
- 7.x
- 8.x
- 8.2.1
# FIXME: enable remote builds
#- component: "${CI_SERVER_HOST}/ci/component/bazelisk/config@v1.4.0"
#- component: "${CI_SERVER_HOST}/ci/component/bazelisk/config@v1.5.0"
# inputs:
# extends:
# - .base
......@@ -22,7 +22,7 @@ include:
# - hooks
# config:
# - remote
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/semantic-release@v1.4.0"
- component: "${CI_SERVER_HOST}/ci/component/bazelisk/semantic-release@v1.5.0"
inputs:
extends:
- .base
......@@ -43,10 +43,16 @@ default:
script:
- cd "${ROOT}"; bazelisk test --config="${CONFIG}" -- ${TARGET} $(bazelisk query "${EXCLUDE_QUERY}" | sed 's/^/-/')
qemu:
.smoke:
extends: .base
needs:
- hooks
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"
qemu:
extends: .smoke
variables:
ROOT: e2e
CONFIG: local
......@@ -56,6 +62,11 @@ qemu:
- arm64
- linux
- kvm
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"
examples:
extends: .smoke
variables:
ROOT: examples
CONFIG: local
TARGET: //...
EXCLUDE_QUERY: ""
# [1.0.0-alpha.3](https://git.gitlab.arm.com/bazel/rules_labgrid/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2025-07-01)
### Bug Fixes
- **//labgrid/run:** handle quoted `program_prefix` ([da53a02](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/da53a028b4937ebfeb562b0c30572735e4b907de))
- **examples/docker:** use hermetic Python bootstrapper ([d5b920e](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/d5b920e2f1781ca41bd1418caa46d3ad05287b8e))
- **examples:** make `bazel test //...` work ([4761a03](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/4761a03f1ba1cfb016de60d3f2926b50fbf25d62))
- make it possible to provide one path in `FileTransfer` ([99de8c6](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/99de8c622b70d6e80fc0a85710f84345f3d0e4d8))
- runfiles location ([06df427](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/06df427c2207f7c89f68dd9e9b4a5bd9f1efe78e))
### Features
- make `device` constraint setting public ([bec8232](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/bec8232eff2de4467305115f79b3095a24f2ff37))
- **runner:** check non-zero exit code ([555c648](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/555c6482d0ad51be55b8414616222879e6927209))
- **runner:** stdout and stderr ([0707d24](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/0707d248170448587ac2321ccb3d8f8db0751514))
- use local toolchain as default ([58f540f](https://git.gitlab.arm.com/bazel/rules_labgrid/commit/58f540f897af34d520d2301723088b5dcb10eaf9))
### BREAKING CHANGES
- **runner:** `Runner.run()` returns just the exit code.
Runner can redirect stdout and stderr to files.
# [1.0.0-alpha.2](https://git.gitlab.arm.com/bazel/rules_labgrid/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2025-05-01)
### Bug Fixes
......
module(
name = "rules_labgrid",
version = "1.0.0-alpha.2",
version = "1.0.0-alpha.3",
bazel_compatibility = [
">=7.4.0",
],
......@@ -44,7 +44,15 @@ resolved = use_repo_rule("@toolchain_utils//toolchain/resolved:defs.bzl", "toolc
for kind in ("qemu-system", "qemu-img")
]
register_toolchains("//labgrid/toolchain/...")
register_toolchains(
"//labgrid/toolchain/qemu-img/...",
"//labgrid/toolchain/qemu-system/...",
"//labgrid/toolchain/config/qemu/...",
"//labgrid/toolchain/config/ssh/...",
)
#local config must be last to ensure correct resolution when no platform is set.
register_toolchains("//labgrid/toolchain/config/local/...")
# We need to pin to Python 3.11
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
......
......@@ -766,7 +766,7 @@
"@@rules_python~//python/extensions:pip.bzl%pip": {
"general": {
"bzlTransitiveDigest": "PVBDpSH3uhnjldJb0HM6S0qZopukgHpVgLAm1Z+h+O4=",
"usagesDigest": "MxRmMlR95q1rFHiIyt9ucR7TDbcMWb8jr66q4AQJvB4=",
"usagesDigest": "m30iB+RjlOWNzSYUDoAJu0yhRTj/uWsXG9mC/Spts5c=",
"recordedFileInputs": {
"@@rules_python~//tools/publish/requirements_linux.txt": "d576e0d8542df61396a9b38deeaa183c24135ed5e8e73bb9622f298f2671811e",
"@@rules_python~~internal_deps~pypi__packaging//BUILD.bazel": "6b3ce4866652a6d87846b383e5bf3a9ca2f77560c1ce75616c0b90527492b5ff",
......
......@@ -3,9 +3,9 @@ from __future__ import annotations
import logging
from contextlib import contextmanager
from dataclasses import dataclass
from io import StringIO
from os import environ, linesep
from pathlib import Path, PurePath
from sys import stderr, stdout
from typing import (
Iterator,
Mapping,
......@@ -13,6 +13,7 @@ from typing import (
from threading import get_native_id
from uuid import getnode
from subprocess import CalledProcessError
from sys import stdout, stderr
from bazel.labgrid.strategy import State, transition
from labgrid import Environment
......@@ -27,14 +28,11 @@ class FileTransfer:
remote: PurePath
local: Path
optional: bool
# FIXME: Decide whether or not to transfer runfiles implicitly instead of using a flag
include_runfiles: bool
def __init__(self, remote: str, local: str, optional=False, include_runfiles=False):
def __init__(self, remote: str, local: str = "", optional=False):
object.__setattr__(self, "remote", PurePath(remote))
object.__setattr__(self, "local", Path(local))
object.__setattr__(self, "local", Path(local if local else remote))
object.__setattr__(self, "optional", optional)
object.__setattr__(self, "include_runfiles", include_runfiles)
def _log_level(value):
......@@ -68,6 +66,9 @@ def runner():
class Runner:
_xml_output_file = "results.xml"
_test_shard_status_file = "test.shard"
def __init__(self, transfer, shell):
self._transfer = transfer
self._shell = shell
......@@ -90,12 +91,6 @@ class Runner:
self._run(f"{self._tools.mkdir(remote.parent)}")
self._transfer.put(local, remote)
if upload.include_runfiles:
src_runfiles = local.with_suffix(".runfiles")
dest_runfiles = remote.with_suffix(".runfiles")
if src_runfiles.exists():
self._transfer.put(f"{src_runfiles}", f"{dest_runfiles}")
def get(self, downloads: Iterator[FileTransfer], code: int):
"""Files to transfer from the device to the host.
......@@ -110,18 +105,19 @@ class Runner:
if not download.optional and code == 0:
raise e
def run(self, cmd: str, env: Mapping[str, str] = {}) -> int:
def run(
self,
cmd: str,
env: Mapping[str, str] = {},
stdout=stdout,
stderr=stderr,
check=False,
) -> int:
"""Run a command on the device with given environment variables."""
cmd = (
f"cd {self._exec_root} && {self._tools.env(self._default_env() | env, cmd)}"
)
out, err, code = self._run(cmd, check=False)
for line in out:
stdout.write(f"{line}{linesep}")
for line in err:
stderr.write(f"{line}{linesep}")
return (code, linesep.join(out))
return self._run(cmd, stdout=stdout, stderr=stderr, check=check)
def __enter__(self):
# Get a unique temporary directory, avoiding concurrent instances
......@@ -156,28 +152,47 @@ class Runner:
return base / path
return path
def _run(self, cmd, check=True):
def _run(self, cmd, stdout=None, stderr=None, check=True):
# We should let Bazel kill the process with the configured timeout if running a test
timeout = None if environ.get("BAZEL_TEST") == "1" else 30
out, err, code = self._shell.run(cmd, timeout=timeout)
if check and code:
raise CalledProcessError(
cmd=cmd, returncode=code, output=stdout, stderr=err
)
raise CalledProcessError(cmd=cmd, returncode=code, output=out, stderr=err)
if stdout:
for line in out:
stdout.write(f"{line}{linesep}")
if stderr:
for line in err:
stderr.write(f"{line}{linesep}")
return out, err, code
return code
def _read_path(self, cmd):
out, _, _ = self._run(cmd)
return PurePath(linesep.join(out).rstrip())
try:
output = StringIO()
self._run(cmd, stdout=output)
return PurePath(output.getvalue().rstrip())
finally:
output.close()
@staticmethod
def _default_env():
inherit_env = ["BAZEL_TEST", "TEST_TOTAL_SHARDS", "TEST_SHARD_INDEX"]
inherit_env = [
"BAZEL_TEST",
"LOGNAME",
"TEST_SHARD_INDEX",
"TEST_SRCDIR",
"TEST_TMPDIR",
"TEST_TOTAL_SHARDS",
"TZ",
"USER",
]
env = {
"XML_OUTPUT_FILE": "results.xml",
"TEST_SHARD_STATUS_FILE": "test.shard",
"XML_OUTPUT_FILE": Runner._xml_output_file,
"TEST_SHARD_STATUS_FILE": Runner._test_shard_status_file,
}
return {k: environ.get(k) for k in inherit_env if k in environ} | {
......@@ -187,8 +202,8 @@ class Runner:
@staticmethod
def _default_downloads():
get = {
"XML_OUTPUT_FILE": "results.xml",
"TEST_SHARD_STATUS_FILE": "test.shard",
"XML_OUTPUT_FILE": Runner._xml_output_file,
"TEST_SHARD_STATUS_FILE": Runner._test_shard_status_file,
}
return [
......
This diff is collapsed.
......@@ -5,7 +5,6 @@ load("@rules_labgrid//labgrid/binary:defs.bzl", "labgrid_binary")
labgrid_binary(
name = "printenv",
src = "@ape//ape:printenv",
platform = "@rules_labgrid//labgrid/platform:localhost",
)
genrule(
......
......@@ -6,7 +6,6 @@ labgrid_genrule(
name = "actual",
outs = ["stdout.actual"],
cmd = "echo -n $LG_STATE > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
)
write_file(
......
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_diff//diff/file/test:defs.bzl", "diff_file_test")
load("@rules_labgrid//labgrid/genrule:defs.bzl", "labgrid_genrule")
load("@rules_labgrid//labgrid/run/binary:defs.bzl", "labgrid_run_binary")
load("@rules_python//python:defs.bzl", "py_binary")
labgrid_genrule(
......@@ -8,7 +9,6 @@ labgrid_genrule(
srcs = ["@ape//ape:echo"],
outs = ["run.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) $(location @ape//ape:echo) world > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -23,7 +23,6 @@ labgrid_genrule(
srcs = [":echo-with-runfiles"],
outs = ["runfiles.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) $(locations :echo-with-runfiles) world > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -33,7 +32,6 @@ labgrid_genrule(
srcs = ["@ape//ape:bash"],
outs = ["transfer-file-back.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$@ $(location @ape//ape:bash) -c 'echo world > output.txt'",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -43,7 +41,6 @@ labgrid_genrule(
srcs = ["@ape//ape:bash"],
outs = ["transfer-to-ruledir.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$(RULEDIR)/transfer-to-ruledir.actual $(location @ape//ape:bash) -c 'echo world > output.txt'",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -53,7 +50,6 @@ labgrid_genrule(
srcs = ["@ape//ape:bash"],
outs = ["transfer-to-d.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$D/transfer-to-d.actual $(location @ape//ape:bash) -c 'echo world > output.txt'",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -63,7 +59,6 @@ labgrid_genrule(
srcs = ["@ape//ape:bash"],
outs = ["nested/transfer-to-d.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --get output.txt:$D/transfer-to-d.actual $(location @ape//ape:bash) -c 'echo world > output.txt'",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -80,7 +75,6 @@ labgrid_genrule(
],
outs = ["put-file-with-remote.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --put $(location :hello.txt):hello.txt $(location @ape//ape:cat) hello.txt > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -92,7 +86,6 @@ labgrid_genrule(
],
outs = ["put-file-without-remote.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --put $(location :hello.txt) $(location @ape//ape:cat) $(location :hello.txt) > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
......@@ -101,10 +94,26 @@ labgrid_genrule(
srcs = ["@ape//ape:printenv"],
outs = ["env.actual"],
cmd = "$(location @rules_labgrid//labgrid/run) --env HELLO=world -- $(location @ape//ape:printenv) HELLO > $@",
platform = "@rules_labgrid//labgrid/platform:localhost",
tools = ["@rules_labgrid//labgrid/run"],
)
# Regression test for: https://gitlab.arm.com/bazel/rules_labgrid/-/issues/73
labgrid_run_binary(
name = "hello-with-program-prefix",
srcs = ["@ape//ape:bash"],
outs = ["program-prefix.actual"],
args = [
"--program-prefix",
"''",
"--get",
"output.txt:$(location :program-prefix.actual)",
"$(location @ape//ape:bash)",
"-c",
"echo world > output.txt",
],
tool = "@rules_labgrid//labgrid/run",
)
write_file(
name = "expected",
out = ":hello.txt",
......@@ -131,5 +140,6 @@ write_file(
"put-file-with-remote",
"put-file-without-remote",
"env",
"program-prefix",
)
]
......@@ -9,7 +9,6 @@ labgrid_run_binary(
"-c",
"echo -n $LG_STATE > $(location :stdout.actual)",
],
platform = "@rules_labgrid//labgrid/platform:localhost",
tool = "@ape//ape:bash",
)
......
......@@ -7,6 +7,7 @@ py_binary(
srcs = ["hello.py"],
data = [":hello.txt"],
main = "hello.py",
visibility = [":__subpackages__"],
deps = ["@rules_python//python/runfiles"],
)
......@@ -14,7 +15,13 @@ labgrid_test(
name = "test",
size = "small",
src = ":inner",
platform = "@rules_labgrid//labgrid/platform:localhost",
)
# Regression test for: https://gitlab.arm.com/bazel/rules_labgrid/-/issues/77
labgrid_test(
name = "src-in-subpackage",
size = "small",
src = "//test/subdir:inner",
)
write_file(
......@@ -37,7 +44,6 @@ labgrid_test(
name = "src-env",
size = "small",
src = ":inner-with-env",
platform = "@rules_labgrid//labgrid/platform:localhost",
)
py_binary(
......@@ -51,7 +57,6 @@ labgrid_test(
size = "small",
src = ":inner-without-env",
env = {"GREETING": "hello"},
platform = "@rules_labgrid//labgrid/platform:localhost",
)
py_binary(
......@@ -66,7 +71,6 @@ labgrid_test(
size = "small",
src = ":inner-with-override-env",
env = {"GREETING": "hello"},
platform = "@rules_labgrid//labgrid/platform:localhost",
)
write_file(
......@@ -92,7 +96,6 @@ labgrid_test(
"hello",
"world",
],
platform = "@rules_labgrid//labgrid/platform:localhost",
)
py_binary(
......@@ -107,7 +110,6 @@ labgrid_test(
size = "small",
src = ":inner-without-data",
data = [":hello.txt"],
platform = "@rules_labgrid//labgrid/platform:localhost",
)
write_file(
......@@ -135,7 +137,6 @@ labgrid_test(
env = {
"HELLO_PATH": "$(location :hello.txt)",
},
platform = "@rules_labgrid//labgrid/platform:localhost",
)
write_file(
......@@ -161,6 +162,5 @@ labgrid_test(
name = "sharding",
size = "small",
src = ":inner-sharding",
platform = "@rules_labgrid//labgrid/platform:localhost",
shard_count = 2,
)
load("@rules_labgrid//labgrid/test:defs.bzl", "labgrid_test")
load("@rules_python//python:defs.bzl", "py_binary")
py_binary(
name = "inner",
srcs = ["hello.py"],
data = [":hello.txt"],
main = "hello.py",
visibility = ["//test:__subpackages__"],
deps = ["@rules_python//python/runfiles"],
)
# Regression test for: https://gitlab.arm.com/bazel/rules_labgrid/-/issues/77
labgrid_test(
name = "src-in-upper-package",
size = "small",
src = "//test:inner",
)
import unittest
from pathlib import Path
from python.runfiles import Runfiles
def _runfile(path):
r = Runfiles.Create()
return Path(r.Rlocation(path)).read_text()
class HelloTestCase(unittest.TestCase):
def test(self):
self.assertEqual(_runfile("_main/test/subdir/hello.txt").rstrip(), "world")
if __name__ == "__main__":
unittest.main()
world
# `bzlmod` pre-release registries
common --registry https://bcr.bazel.build
common --registry=https://gitlab.arm.com/bazel/rules_patchelf/-/releases/v1.0.0/downloads
# Enable hermetic `rules_python`
common --@rules_python//python/config_settings:bootstrap_impl=script
# User-specific .bazelrc
try-import %workspace%/.bazelrc.user
# Declare all run commands that are loaded
common --announce_rc
# Use relative paths where possible for concise CI output
common --attempt_to_print_relative_paths
# Prevent progress bars or similar
common --curses=no
# CI "terminals" support colour
common --color=yes
# Output timestamps for each command to aid debugging of CI runtime
common --show_timestamps
# Do not wrap any output
common --terminal_columns=0
# Output as much information in the CI log about failures as possible
build --verbose_failures
# Increase logging verbosity
build --action_env=LOG_LEVEL=INFO
test --test_env=LOG_LEVEL=INFO
# Noisy logs but allows debugging CI run failures
test --test_output=errors
# Output as much information when a test exceeds a timeout
test --test_verbose_timeout_warnings
# Validate that the lockfile is correct
common --lockfile_mode=${CI_LOCKFILE_MODE}
# These locations are cached on the CI
build:local --disk_cache=${CI_PROJECT_DIR}/.cache/bazel/disk
build:local --repository_cache=${CI_PROJECT_DIR}/.cache/bazel/repo
File moved
module(
name = "e2e",
name = "examples",
bazel_compatibility = [
">=7.0.0",
">=7.4.0",
],
)
bazel_dep(name = "rules_python", version = "0.33.2")
bazel_dep(name = "rules_diff", version = "1.0.0-beta.3")
bazel_dep(name = "ape", version = "1.0.0-beta.12")
bazel_dep(name = "rules_python", version = "1.2.0")
bazel_dep(name = "rules_diff", version = "1.0.0")
bazel_dep(name = "ape", version = "1.0.1")
bazel_dep(name = "rules_labgrid")
local_path_override(
module_name = "rules_labgrid",
path = "../..",
path = "..",
)
bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.0", dev_dependency = True)
......@@ -42,6 +42,6 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pip",
python_version = "3.11",
requirements_lock = "//python:requirements.txt",
requirements_lock = "//docker/python:requirements.txt",
)
use_repo(pip, "pip")
This diff is collapsed.