Skip to content

Commit

Permalink
envsetup: move envsetup.sh to _setup_env.sh and deprecate envsetup.sh
Browse files Browse the repository at this point in the history
envsetup.sh is an implementation detail of build.sh and friends and
should therefore not be sourced directly. Hence move its functionality
and just leave a warning in the original envsetup.sh along with some
documentation.

Change-Id: Ib0cfc56c7bbe4f2ce9d4cd01ea251e6982822c47
Signed-off-by: Matthias Maennich <[email protected]>
  • Loading branch information
metti committed Aug 16, 2019
1 parent ee7ef66 commit fbe5364
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 72 deletions.
78 changes: 78 additions & 0 deletions _setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is an implementation detail of build.sh and friends. Do not source
# directly as it will spoil your shell and make build.sh unusable. You have
# been warned! If you have a good reason to source the result of this file into
# a shell, please let [email protected] know and we are happy to help
# with your use case.

[ -n "$_SETUP_ENV_SH_INCLUDED" ] && return || _SETUP_ENV_SH_INCLUDED=1

# TODO: Use a $(gettop) style method.
export ROOT_DIR=$PWD

export BUILD_CONFIG=${BUILD_CONFIG:-build.config}
set -a
. ${ROOT_DIR}/${BUILD_CONFIG}
set +a

export COMMON_OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out/${BRANCH}})
export OUT_DIR=$(readlink -m ${COMMON_OUT_DIR}/${KERNEL_DIR})
export DIST_DIR=$(readlink -m ${DIST_DIR:-${COMMON_OUT_DIR}/dist})

echo "========================================================"
echo "= build config: ${ROOT_DIR}/${BUILD_CONFIG}"
cat ${ROOT_DIR}/${BUILD_CONFIG}

# List of prebuilt directories shell variables to incorporate into PATH
PREBUILTS_PATHS=(
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN
LINUX_GCC_CROSS_COMPILE_ARM32_PREBUILTS_BIN
CLANG_PREBUILT_BIN
LZ4_PREBUILTS_BIN
DTC_PREBUILTS_BIN
LIBUFDT_PREBUILTS_BIN
BUILDTOOLS_PREBUILT_BIN
)

for PREBUILT_BIN in "${PREBUILTS_PATHS[@]}"; do
PREBUILT_BIN=\${${PREBUILT_BIN}}
eval PREBUILT_BIN="${PREBUILT_BIN}"
if [ -n "${PREBUILT_BIN}" ]; then
# Mitigate dup paths
PATH=${PATH//"${ROOT_DIR}\/${PREBUILT_BIN}:"}
PATH=${ROOT_DIR}/${PREBUILT_BIN}:${PATH}
fi
done
export PATH

echo
echo "PATH=${PATH}"
echo

# verifies that defconfig matches the DEFCONFIG
function check_defconfig() {
(cd ${OUT_DIR} && \
make ${CC_LD_ARG} O=${OUT_DIR} savedefconfig)
[ "$ARCH" = "x86_64" -o "$ARCH" = "i386" ] && local ARCH=x86
echo Verifying that savedefconfig matches ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG}
RES=0
diff ${OUT_DIR}/defconfig ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG} ||
RES=$?
if [ ${RES} -ne 0 ]; then
echo ERROR: savedefconfig does not match ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG}
fi
return ${RES}
}
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ SIGN_ALGO=sha512
# BUILD_CONFIG.
CC_ARG=${CC}

source "${ROOT_DIR}/build/envsetup.sh"
source "${ROOT_DIR}/build/_setup_env.sh"

export MAKE_ARGS=$@
export MODULES_STAGING_DIR=$(readlink -m ${COMMON_OUT_DIR}/staging)
Expand Down
3 changes: 1 addition & 2 deletions build_abi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export ROOT_DIR=$(readlink -f $(dirname $0)/..)
set -e
set -a

source "${ROOT_DIR}/build/envsetup.sh"
export ENVSETUP_SH_INCLUDED=1
source "${ROOT_DIR}/build/_setup_env.sh"

# inject CONFIG_DEBUG_INFO=y
export POST_DEFCONFIG_CMDS="${POST_DEFCONFIG_CMDS} : && update_config_for_abi_dump"
Expand Down
2 changes: 1 addition & 1 deletion build_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export BUILD_CONFIG

test=all_tests.sh
set -e
source ${ROOT_DIR}/envsetup.sh
source ${ROOT_DIR}/_setup_env.sh
export OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out/${BRANCH}})
mkdir -p ${OUT_DIR}

Expand Down
92 changes: 26 additions & 66 deletions envsetup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# source this file. Don't run it.

# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,70 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# This is an implementation detail of build.sh and friends. Do not source
# directly as it will spoil your shell and make build.sh unusable. You have
# been warned! If you have a good reason to source the result of this file into
# a shell, please let [email protected] know and we are happy to help
# with your use case.

# Usage:
# $ build/build.sh
#
# Usage (deprecated):
# $ source build/envsetup.sh # to setup your path and cross compiler
# # so that a kernel build command is just:
# $ make -j24

[ -n "$ENVSETUP_SH_INCLUDED" ] && return

# TODO: Use a $(gettop) style method.
export ROOT_DIR=$PWD

export BUILD_CONFIG=${BUILD_CONFIG:-build.config}
set -a
. ${ROOT_DIR}/${BUILD_CONFIG}
set +a

export COMMON_OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out/${BRANCH}})
export OUT_DIR=$(readlink -m ${COMMON_OUT_DIR}/${KERNEL_DIR})
export DIST_DIR=$(readlink -m ${DIST_DIR:-${COMMON_OUT_DIR}/dist})

echo "========================================================"
echo "= build config: ${ROOT_DIR}/${BUILD_CONFIG}"
cat ${ROOT_DIR}/${BUILD_CONFIG}

# List of prebuilt directories shell variables to incorporate into PATH
PREBUILTS_PATHS=(
LINUX_GCC_CROSS_COMPILE_PREBUILTS_BIN
LINUX_GCC_CROSS_COMPILE_ARM32_PREBUILTS_BIN
CLANG_PREBUILT_BIN
LZ4_PREBUILTS_BIN
DTC_PREBUILTS_BIN
LIBUFDT_PREBUILTS_BIN
BUILDTOOLS_PREBUILT_BIN
)

for PREBUILT_BIN in "${PREBUILTS_PATHS[@]}"; do
PREBUILT_BIN=\${${PREBUILT_BIN}}
eval PREBUILT_BIN="${PREBUILT_BIN}"
if [ -n "${PREBUILT_BIN}" ]; then
# Mitigate dup paths
PATH=${PATH//"${ROOT_DIR}\/${PREBUILT_BIN}:"}
PATH=${ROOT_DIR}/${PREBUILT_BIN}:${PATH}
fi
done
export PATH

echo
echo "PATH=${PATH}"
echo
# This is a dummy to not break people that have a workflow that includes
# sourcing build/envsetup.sh into a shell when working with Android repo.
# The actual functionality of this script has been moved to _setup_env.sh.
#
# It turns out that build/envsetup.sh was sourced into the shell by a lot of
# people. Mostly due to the fact that old documentation asked people to do so
# (including this script itself). Unfortunately, this causes more harm than it
# does any good. Mostly it spoils the shell with environment variables that are
# only valid in the context of a very specific build configuration. To overcome
# this, the content of this file has been moved to _setup_env.sh and callers
# within this project have been adjusted. This script serves as a dummy to not
# break people sourcing it, but it will from now on emit a deprecation warning.
# That script might be removed at a later time.
#
# For further information on the Android Kernel build process with the tooling
# of this project, please refer to
# https://source.android.com/setup/build/building-kernels.
#
# For any questions or concerns, please contact [email protected].

# verifies that defconfig matches the DEFCONFIG
function check_defconfig() {
(cd ${OUT_DIR} && \
make ${CC_LD_ARG} O=${OUT_DIR} savedefconfig)
[ "$ARCH" = "x86_64" -o "$ARCH" = "i386" ] && local ARCH=x86
echo Verifying that savedefconfig matches ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG}
RES=0
diff ${OUT_DIR}/defconfig ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG} ||
RES=$?
if [ ${RES} -ne 0 ]; then
echo ERROR: savedefconfig does not match ${KERNEL_DIR}/arch/${ARCH}/configs/${DEFCONFIG}
fi
return ${RES}
}
echo "Sourcing 'build/envsetup.sh' for Android Kernels is deprecated and no longer valid!"
echo "Please refer to the documentation in said script for details."
2 changes: 1 addition & 1 deletion static_analysis/checkpatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export STATIC_ANALYSIS_SRC_DIR=$(dirname $(readlink -f $0))

ROOT_DIR="${STATIC_ANALYSIS_SRC_DIR}/../../"
pushd ${ROOT_DIR}
source ${STATIC_ANALYSIS_SRC_DIR}/../envsetup.sh
source ${STATIC_ANALYSIS_SRC_DIR}/../_setup_env.sh
export OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out/${BRANCH}})
export DIST_DIR=$(readlink -m ${DIST_DIR:-${OUT_DIR}/dist})
mkdir -p ${DIST_DIR}
Expand Down
2 changes: 1 addition & 1 deletion static_analysis/checkpatch_presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set -e

export STATIC_ANALYSIS_SRC_DIR=$(dirname $(readlink -f $0))

source ${STATIC_ANALYSIS_SRC_DIR}/../envsetup.sh
source ${STATIC_ANALYSIS_SRC_DIR}/../_setup_env.sh
export OUT_DIR=$(readlink -m ${OUT_DIR:-${ROOT_DIR}/out/${BRANCH}})
export DIST_DIR=$(readlink -m ${DIST_DIR:-${OUT_DIR}/dist})

Expand Down

0 comments on commit fbe5364

Please sign in to comment.