From 20ed5f73a6146f0477510cd8fc69c4072dd19a8e Mon Sep 17 00:00:00 2001 From: John Moon Date: Tue, 29 Nov 2022 13:30:24 -0800 Subject: [PATCH] build: Add logic to use default extensions if none are found Currently, the Bazel build may fail if symlinks to the Bazel extension files are not linked to the proper locations. To make sure the build always works (falling back on default extensions), configure the script to create the symlinks to the default files in case they don't exist or are broken symlinks. Change-Id: Ie385e4ede912d0f40026ef6c78a9c2fb60ca8924 Signed-off-by: John Moon --- build_with_bazel.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/build_with_bazel.py b/build_with_bazel.py index 6f384f12f7c7..40bc80ac6af5 100755 --- a/build_with_bazel.py +++ b/build_with_bazel.py @@ -3,6 +3,7 @@ # Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. import argparse +import errno import logging import os import re @@ -13,6 +14,10 @@ CPU = "aarch64" HOST_CROSSTOOL = "@bazel_tools//tools/cpp:toolchain" HOST_TARGETS = ["dtc"] DEFAULT_SKIP_LIST = ["abi", "test_mapping"] +MSM_EXTENSIONS = "build/msm_kernel_extensions.bzl" +ABL_EXTENSIONS = "build/abl_extensions.bzl" +DEFAULT_MSM_EXTENSIONS_SRC = "../msm-kernel/msm_kernel_extensions.bzl" +DEFAULT_ABL_EXTENSIONS_SRC = "../bootable/bootloader/edk2/abl_extensions.bzl" class BazelBuilder: @@ -33,6 +38,7 @@ class BazelBuilder: self.skip_list = skip_list self.user_opts = user_opts self.process_list = [] + self.setup_extensions() def __del__(self): for proc in self.process_list: @@ -48,6 +54,29 @@ class BazelBuilder: "--host_crosstool_top={}".format(HOST_CROSSTOOL), ] + def setup_extensions(self): + """Set up the extension files if needed""" + for (ext, def_src) in [ + (MSM_EXTENSIONS, DEFAULT_MSM_EXTENSIONS_SRC), + (ABL_EXTENSIONS, DEFAULT_ABL_EXTENSIONS_SRC), + ]: + ext_path = os.path.join(self.workspace, ext) + # If the file doesn't exist or is a dead link, link to the default + try: + os.stat(ext_path) + except OSError as e: + if e.errno == errno.ENOENT: + logging.info( + "%s does not exist or is a broken symlink... linking to default at %s", + ext, + def_src, + ) + if os.path.islink(ext_path): + os.unlink(ext_path) + os.symlink(def_src, ext_path) + else: + raise e + def get_build_targets(self): """Query for build targets""" logging.info("Querying build targets...")