Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUILD and lock file improvements #30

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
- name: Build
# TODO(evan.flynn): uncomment once the rules are properly fixed
# run: bazel build //...
run: bazel build -- $(cat repos/config/bazel.repos | sed -e '/^[#r]/d' -e '/^ /d' -e 's%/%.%' -e 's% \(.*\):%@\1//...%' -e '/@ros2.rosidl/d' -e '/@ros2.rcl_interfaces/d' -e '/@ros2.common_interfaces/d')
run: bazel build --keep_going -- $(cat repos/config/bazel.repos | sed -e '/^[#r]/d' -e '/^ /d' -e 's%/%.%' -e 's% \(.*\):%@\1//...%' -e '/@ros2.rosidl/d' -e '/@ros2.rcl_interfaces/d' -e '/@ros2.common_interfaces/d')
- name: Test
run: bazel test -- $(cat repos/config/bazel.repos | sed -e '/^[#r]/d' -e '/^ /d' -e 's%/%.%' -e 's% \(.*\):%@\1//...%' -e '/@ros2.rosidl/d' -e '/@ros2.rcl_interfaces/d' -e '/@ros2.common_interfaces/d')
run: bazel test --keep_going -- //repos/config/detail/... //thirdparty/... $(cat repos/config/bazel.repos | sed -e '/^[#r]/d' -e '/^ /d' -e 's%/%.%' -e 's% \(.*\):%@\1//...%' -e '/@ros2.rosidl/d' -e '/@ros2.rcl_interfaces/d' -e '/@ros2.common_interfaces/d')
- name: Store the bazel-testlogs
uses: actions/upload-artifact@v3
if: always()
Expand Down
13 changes: 13 additions & 0 deletions repos/config/detail/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ py_binary(
visibility = ["//visibility:public"],
deps = [requirement("pyyaml")],
)

sh_test(
name = "test_repos_index_sha256",
srcs = ["test/test_repos_index_sha256.sh"],
args = [
"$(execpath {})".format(REPOS_INDEX_FILE),
"$(execpath {})".format(REPOS_SETUP_FILE),
],
data = [
REPOS_INDEX_FILE,
REPOS_SETUP_FILE,
],
)
26 changes: 18 additions & 8 deletions repos/config/detail/generate_ros2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@
# limitations under the License.

import yaml


HEADER = """#
import hashlib

def get_sha256sum(file):
sha256_hash = hashlib.sha256()
with open(file, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()

def print_setup(repos, output_file, repos_file, use_tar = False):
BZL_CMD = "bazel run @rules_ros//repos/config:repos_lock.update"
if use_tar:
BZL_CMD += " -- --tar"
HEADER = f"""#
# DO NOT EDIT THIS FILE MANUALLY!
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
# To update, call `{BZL_CMD}` with the right distro set in the WORKSPACE
#
# SHA256 of {repos_file}: {get_sha256sum(repos_file)}

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand All @@ -30,8 +42,6 @@ def setup():
pass
"""


def print_setup(repos, output_file):
print(HEADER, file=output_file)
printed_first_load = False
for repo, spec in repos.items():
Expand Down Expand Up @@ -109,9 +119,9 @@ def merge_dict(origin, to_add):
origin[key]=value


def print_setup_file(repos, yaml_files, output_file):
def print_setup_file(repos, yaml_files, output_file, repos_file, use_tar = False):
for input_path in yaml_files:
with (open(input_path,"r")) as repo_file:
merge_dict(repos, yaml.safe_load(repo_file)["repositories"])

print_setup(repos, output_file)
print_setup(repos, output_file, repos_file, use_tar)
6 changes: 5 additions & 1 deletion repos/config/detail/lock_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def main():
print("{}: {}".format(repo, [*additional_attributes.values()]))

with open(args.setup_bzl, mode='w', encoding='utf8') as setup_bzl:
print_setup_file(repos = repos["repositories"], yaml_files=args.overlays, output_file=setup_bzl)
print_setup_file(repos = repos["repositories"],
yaml_files=args.overlays,
output_file=setup_bzl,
repos_file = args.repos,
use_tar=args.tar)


def fetch_dependency_details(*, use_tar, type, **kwargs):
Expand Down
23 changes: 23 additions & 0 deletions repos/config/detail/test/test_repos_index_sha256.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

REPOS_INDEX_FILE="$1"
REPOS_SETUP_FILE="$2"

REPOS_SETUP_FILE_SHA256=$(grep "SHA256" "${REPOS_SETUP_FILE}" | cut -f 5 -d ' ')

if [[ -z "${REPOS_SETUP_FILE_SHA256}" ]]; then
echo "${REPOS_SETUP_FILE} DOES NOT HAVE A SHA256 COMMENT. TERMINATING"
exit -1
elif [[ "${REPOS_SETUP_FILE_SHA256}" =~ ^[a-f0-9]{65}$ ]]; then
echo "${REPOS_SETUP_FILE} INVALID SHA256 COMMENT of ${REPOS_SETUP_FILE_SHA256}. TERMINATING"
exit -1
fi

REPOS_INDEX_FILE_SHA256=$(sha256sum "${REPOS_INDEX_FILE}" | cut -f 1 -d ' ')

if [ "${REPOS_INDEX_FILE_SHA256}" != "${REPOS_SETUP_FILE_SHA256}" ]; then
echo "SHA256 MISMATCH. RUN 'bazel run @rules_ros//repos/config:repos_lock.update' THEN TRY AGAIN"
exit -1
fi

exit 0
1 change: 1 addition & 0 deletions repos/config/setup_dashing.lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
#
# SHA256 of external/ros2/ros2.repos: da16d26ba1c05ea20cedf2f01250ed859ee255565053dd9650c831ff80e1f6ea

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand Down
1 change: 1 addition & 0 deletions repos/config/setup_eloquent.lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
#
# SHA256 of external/ros2/ros2.repos: 71922db335c9a2092fb095e66b1e860f9713854bf704e0e00dc5910f7ec111a8

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand Down
1 change: 1 addition & 0 deletions repos/config/setup_foxy.lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
#
# SHA256 of external/ros2/ros2.repos: 3097c84026e1c9c07e457fe7aadaa10f08b8c24354633f742d7579add58b8782

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand Down
1 change: 1 addition & 0 deletions repos/config/setup_humble.lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
#
# SHA256 of external/ros2/ros2.repos: 09a14ede568810d8120e3f3228af03a35c192cff5c718422cb2d88c5cd4b2824

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand Down
1 change: 1 addition & 0 deletions repos/config/setup_iron.lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# To update, call `bazel run @rules_ros//repos/config:repos_lock.update` with the right distro set in the WORKSPACE
#
# SHA256 of external/ros2/ros2.repos: 208a8f0618b3f5a90b7301ca07a2f3b1f918d3531cd3acab0c9ca62ff8a5d19d

load("@bazel_tools//tools/build_defs/repo:utils.bzl", _maybe = "maybe")
load("@rules_ros//repos/config/detail:git_repository.bzl", "git_repository")
Expand Down
Loading