Repository navigation
Expand file tree
/
Copy pathdev_env_guard.sh
More file actions
executable file
·89 lines (83 loc) · 4.27 KB
/
Copy pathdev_env_guard.sh
File metadata and controls
executable file
·89 lines (83 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
#** *****************************************************************************
# *
# * If not stated otherwise in this file or this component's LICENSE file the
# * following copyright and licenses apply:
# *
# * Copyright 2026 RDK Management
# *
# * 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.
# *
#** ******************************************************************************
#
# Shared environment guard for the developer / architecture-team wrapper scripts
# (build_binder.sh, build_modules.sh, build_interfaces.sh).
#
# These wrappers assume a NATIVE host toolchain. They exist for the architecture
# team to test interfaces and cut releases on a developer machine — they are NOT
# part of the production build path. Production / cross builds (Yocto/BitBake)
# MUST invoke CMake directly with the correct variables; see
# docs/standards/build_integration.md (the third-party build contract).
#
# Run inside a sourced OpenEmbedded cross environment, a wrapper produces broken
# or empty output: the host AIDL tool gets cross-compiled (and can't run on the
# build host), and the binder CMake auto-enables BUILD_ENV_YOCTO from OECORE_*,
# which disables every install() rule — so out/target is silently never staged.
#
# This guard fails fast with a clear pointer instead. Override (not recommended)
# with BINDER_ALLOW_CROSS_ENV=1.
# Returns non-zero (with an explanatory message) when the current environment is
# a Yocto/cross environment unsuitable for these host wrappers.
halif_guard_dev_host_env() {
[ "${BINDER_ALLOW_CROSS_ENV:-0}" = "1" ] && return 0
local reasons=()
# The reliable Yocto signal: an OE shell exports these sysroots, and they are
# exactly what the binder CMake keys BUILD_ENV_YOCTO off.
if [ -n "${OECORE_NATIVE_SYSROOT:-}" ] || [ -n "${OECORE_TARGET_SYSROOT:-}" ]; then
reasons+=("OpenEmbedded/Yocto environment detected (OECORE_*_SYSROOT set)")
fi
# A cross CC set outside an OE shell: compare target triples. (Inside an OE
# shell PATH may already point cc at the cross compiler, so this can match
# the host triple — the OECORE check above is what catches that case.)
# Derive the host triple from a *fixed* /usr/bin compiler first, so a cross
# toolchain that prepends PATH can't mask the host triple; fall back to a
# PATH-resolved cc/gcc only when the fixed paths are absent.
if [ -n "${CC:-}" ]; then
local cc_machine host_machine
cc_machine="$(${CC} -dumpmachine 2>/dev/null || true)"
host_machine="$(/usr/bin/gcc -dumpmachine 2>/dev/null || /usr/bin/cc -dumpmachine 2>/dev/null || cc -dumpmachine 2>/dev/null || gcc -dumpmachine 2>/dev/null || true)"
if [ -n "$cc_machine" ] && [ -n "$host_machine" ] && [ "$cc_machine" != "$host_machine" ]; then
reasons+=("cross-compiler detected (CC -> ${cc_machine}, host ${host_machine})")
fi
fi
[ "${#reasons[@]}" -eq 0 ] && return 0
# Name the wrapper that sourced us. When a wrapper is *sourced*
# (e.g. `source ./build_binder.sh`), $0 is the interactive shell, so prefer
# the caller's BASH_SOURCE entry.
local self
self="$(basename "${BASH_SOURCE[1]:-${0:-this script}}")"
{
echo ""
echo "ERROR: ${self} is a developer/architecture wrapper and requires a native host toolchain."
local r
for r in "${reasons[@]}"; do echo " - ${r}"; done
echo ""
echo " Production / cross (Yocto/BitBake) builds MUST call CMake directly — these"
echo " wrappers are not for production recipes. See:"
echo " docs/standards/build_integration.md (Third-Party Build Integration)"
echo ""
echo " To proceed anyway (not recommended): BINDER_ALLOW_CROSS_ENV=1 ./${self} ..."
echo ""
} >&2
return 1
}