Skip to content

Commit

Permalink
Improve Bazel presubmit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
armandomontanez committed Oct 4, 2024
1 parent 5b86fed commit 5faed5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions tools/bazel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
override_picotool_arg,
parse_common_args,
print_framed_string,
print_to_stderr,
run_bazel,
setup_logging,
)
Expand Down Expand Up @@ -196,12 +197,12 @@ def build_all_configurations(picotool_dir):
)
if result.returncode != 0:
failed_builds.append(config["name"])
print()
print_to_stderr()

if failed_builds:
print_framed_string("ERROR: One or more builds failed.")
for build in failed_builds:
print(f" * FAILED: {build} build")
print_to_stderr(f" * FAILED: {build} build")
return 1

print_framed_string("All builds successfully passed!")
Expand Down
11 changes: 8 additions & 3 deletions tools/bazel_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import shlex
import shutil
import subprocess
import sys


_LOG = logging.getLogger(__file__)
Expand Down Expand Up @@ -93,12 +94,16 @@ def run_bazel(args, check=False, **kwargs):
return proc


def print_to_stderr(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


def print_framed_string(s):
"""Frames a string of text and prints it to highlight script steps."""
header_spacer = "#" * (len(s) + 12)
print(header_spacer)
print("### " + s + " ###")
print(header_spacer)
print_to_stderr(header_spacer)
print_to_stderr("### " + s + " ###")
print_to_stderr(header_spacer)


def setup_logging():
Expand Down
20 changes: 12 additions & 8 deletions tools/compare_build_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

from dataclasses import dataclass
import glob
import logging
import os
import re
import sys
from typing import Dict

from bazel_common import SDK_ROOT

_LOG = logging.getLogger(__file__)

CMAKE_FILE_TYPES = (
"**/CMakeLists.txt",
"**/*.cmake",
Expand Down Expand Up @@ -182,17 +185,17 @@ def OptionsAreEqual(bazel_option, cmake_option):
if bazel_option is None:
if cmake_option.name in CMAKE_ONLY_ALLOWLIST:
return True
print(f" {cmake_option.name} does not exist in Bazel")
_LOG.warning(f" {cmake_option.name} does not exist in Bazel")
return False
elif cmake_option is None:
if bazel_option.name in BAZEL_ONLY_ALLOWLIST:
return True
print(f" {bazel_option.name} does not exist in CMake")
_LOG.warning(f" {bazel_option.name} does not exist in CMake")
return False
elif not bazel_option.matches(cmake_option):
print(" Bazel and CMAKE definitions do not match:")
print(f" [CMAKE] {bazel_option}")
print(f" [BAZEL] {cmake_option}")
_LOG.error(" Bazel and CMAKE definitions do not match:")
_LOG.error(f" [CMAKE] {bazel_option}")
_LOG.error(f" [BAZEL] {cmake_option}")
return False

return True
Expand Down Expand Up @@ -224,22 +227,23 @@ def compare_build_systems():
for f in glob.glob(os.path.join(SDK_ROOT, p), recursive=True)
]

print("[1/2] Checking build system configuration flags...")
_LOG.info("[1/2] Checking build system configuration flags...")
build_options_ok = CompareOptions(
"PICO_BAZEL_CONFIG", bazel_files, "PICO_CMAKE_CONFIG", cmake_files
)

print("[2/2] Checking build system defines...")
_LOG.info("[2/2] Checking build system defines...")
build_defines_ok = CompareOptions(
"PICO_BUILD_DEFINE", bazel_files, "PICO_BUILD_DEFINE", cmake_files
)

if build_options_ok and build_defines_ok:
print("OK")
_LOG.info("OK")
return 0

return 1


if __name__ == "__main__":
setup_logging()
sys.exit(compare_build_systems())

0 comments on commit 5faed5a

Please sign in to comment.