diff options
author | Yifan Hong <elsk@google.com> | 2024-03-20 11:50:10 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2024-03-21 19:17:32 +0000 |
commit | 4cc6d5e5f8c75c7f1db927eab9eb94b87ef6918e (patch) | |
tree | ade52ed754ae228f8e1592e0adbc2fba95e7efdd | |
parent | 396464d6068021d8ddc52733ef82e327358c3adc (diff) | |
download | build-4cc6d5e5f8c75c7f1db927eab9eb94b87ef6918e.tar.gz |
kleaf: kernel_env sets KLEAF_REPO_WORKSPACE_ROOT for the default case.
This is so that, when building DDKv2 module against
a kernel from source, KLEAF_REPO_WORKSPACE_ROOT is automatically
set to external/kleaf~.
Fix a few other bugs that were previously hidden because
KLEAF_REPO_WORKSPACE_ROOT was unset.
After this change:
- When building kernel with @kleaf as the root module,
KLEAF_REPO_WORKSPACE_ROOT remains empty, and
KLEAF_BIN_DIR_AND_WORKSPACE_ROOT is just ctx.bin_dir.
- When building kernel with @kleaf as a dependent module,
KLEAF_REPO_WORKSPACE_ROOT becomes external/kleaf~, and
KLEAF_BIN_DIR_AND_WORKSPACE_ROOT is <ctx.bin_dir>/external/kleaf~.
Test: build kernel normally
Test: build kernel under @kleaf
Change-Id: I410e9117b6e2b3d785cd7d2f8f4887f39b87d8a0
-rw-r--r-- | kleaf/impl/kernel_env.bzl | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/kleaf/impl/kernel_env.bzl b/kleaf/impl/kernel_env.bzl index 7163c3d..522a925 100644 --- a/kleaf/impl/kernel_env.bzl +++ b/kleaf/impl/kernel_env.bzl @@ -15,6 +15,7 @@ """Source-able build environment for kernel build.""" load("@bazel_skylib//lib:dicts.bzl", "dicts") +load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:shell.bzl", "shell") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@kernel_toolchain_info//:dict.bzl", "VARS") @@ -215,6 +216,12 @@ def _kernel_env_impl(ctx): ctx.actions.write(post_env_script, env_setup_cmds.post_env) inputs += [pre_env_script, post_env_script] + kleaf_repo_workspace_root = Label(":kernel_env.bzl").workspace_root + if kleaf_repo_workspace_root: + bin_dir_and_workspace_root = paths.join(ctx.bin_dir.path, kleaf_repo_workspace_root) + else: + bin_dir_and_workspace_root = ctx.bin_dir.path + command += """ # create a build environment source {build_utils_sh} @@ -248,8 +255,8 @@ def _kernel_env_impl(ctx): sed "s|${{PWD}}|\\$PWD|g" | \\ # Drop reference to bin_dir and replace with variable; # Replace $PWD/<not out> with $KLEAF_REPO_DIR/$1 - sed "s|\\$PWD/{bin_dir}|\\$PWD/\\$KLEAF_BIN_DIR|g" | \\ - sed "s|{bin_dir}|\\$KLEAF_BIN_DIR|g" | \\ + sed "s|\\$PWD/{bin_dir_and_workspace_root}|\\$PWD/\\$KLEAF_BIN_DIR_AND_WORKSPACE_ROOT|g" | \\ + sed "s|{bin_dir_and_workspace_root}|\\$KLEAF_BIN_DIR_AND_WORKSPACE_ROOT|g" | \\ # List of packages that //build/kernel/... depends on. This excludes # external/ because they are in different Bazel repositories. sed "s|\\$PWD/build|\\$KLEAF_REPO_DIR/build|g" | \\ @@ -271,7 +278,7 @@ def _kernel_env_impl(ctx): config_tags_comment_file = config_tags_out.env.path, pre_env_script = pre_env_script.path, post_env_script = post_env_script.path, - bin_dir = ctx.bin_dir.path, + bin_dir_and_workspace_root = bin_dir_and_workspace_root, ) progress_message_note = kernel_config_settings.get_progress_message_note(ctx, defconfig_fragments) @@ -352,20 +359,31 @@ def _get_env_setup_cmds(ctx): if ctx.attr._debug_annotate_scripts[BuildSettingInfo].value: pre_env += debug.trap() + kleaf_repo_workspace_root = Label(":kernel_env.bzl").workspace_root + pre_env += """ # KLEAF_REPO_WORKSPACE_ROOT: workspace_root of the Kleaf repository. See Label.workspace_root. - # This should either be an empty string or (usually) external/kleaf. - # This needs to be defined by the user. + # This should be: + # - Either an empty string if @kleaf is the root module; + # - or external/kleaf (or some variations of it) if @kleaf is a dependent module + # This may be overridden by kernel_filegroup. + KLEAF_REPO_WORKSPACE_ROOT=${{KLEAF_REPO_WORKSPACE_ROOT:-{kleaf_repo_workspace_root}}} # bin_dir for Kleaf repository, relative to execroot - # This is either bazel-out/k8-fastbuild/bin or bazel-out/k8-fastbuild/bin/external/kleaf. - KLEAF_BIN_DIR="{bin_dir}${{KLEAF_REPO_WORKSPACE_ROOT:+/$KLEAF_REPO_WORKSPACE_ROOT}}" + # This is: + # - either bazel-out/k8-fastbuild/bin if @kleaf is the root module; + # - or bazel-out/k8-fastbuild/bin/external/kleaf (or some variations of it) + # if @kleaf is a dependent module + KLEAF_BIN_DIR_AND_WORKSPACE_ROOT="{bin_dir}${{KLEAF_REPO_WORKSPACE_ROOT:+/$KLEAF_REPO_WORKSPACE_ROOT}}" # Root of Kleaf repository (under execroot aka PWD) - # This is either $PWD or $PWD/external/kleaf. + # This is: + # - either $PWD if @kleaf is the root module + # - or $PWD/external/kleaf (or some variations of it) if @kleaf is a dependent module KLEAF_REPO_DIR="$PWD${{KLEAF_REPO_WORKSPACE_ROOT:+/$KLEAF_REPO_WORKSPACE_ROOT}}" """.format( bin_dir = ctx.bin_dir.path, + kleaf_repo_workspace_root = kleaf_repo_workspace_root, ) post_env = """ |