Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine build tools & args based on yocto sdk env setup script #19369

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 87 additions & 14 deletions scripts/build/builders/imx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

import os
import re
import shlex
from enum import Enum, auto

from .gn import GnBuilder
Expand Down Expand Up @@ -74,30 +76,101 @@ def __init__(self,
self.release = release
self.app = app

def GnBuildEnv(self):
return {
'PKG_CONFIG_PATH': self.SysRootPath('IMX_SDK_ROOT') + '/sysroots/cortexa53-crypto-poky-linux/lib/aarch64-linux-gnu/pkgconfig',
}

def GnBuildArgs(self):
try:
entries = os.listdir(self.SysRootPath('IMX_SDK_ROOT'))
except FileNotFoundError:
if self.SysRootPath('IMX_SDK_ROOT') == 'IMX_SDK_ROOT':
# CI test, use default value
target_cpu = 'arm64'
arm_arch = 'armv8-a'
sdk_target_sysroot = os.path.join(self.SysRootPath('IMX_SDK_ROOT'), 'sysroots/cortexa53-crypto-poky-linux')
cross_compile = 'aarch64-poky-linux'
cc = 'aarch64-poky-linux-gcc'
cxx = 'aarch64-poky-linux-g++'
else:
raise Exception('the value of env IMX_SDK_ROOT is not a valid path.')
else:
for entry in entries:
if entry.startswith(r'environment-setup-'):
env_setup_script = entry
break

FaqiangZhu-nxp marked this conversation as resolved.
Show resolved Hide resolved
try:
env_setup_script
except NameError:
raise Exception('The SDK environment setup script is not found, make sure the env IMX_SDK_ROOT is correctly set.')
else:

with open(os.path.join(self.SysRootPath('IMX_SDK_ROOT'), env_setup_script), 'r') as env_setup_script_fd:
lines = env_setup_script_fd.readlines()
for line in lines:
line = line.strip('\n')
m = re.match(r'^\s*export\s+SDKTARGETSYSROOT=(.*)', line)
if m:
sdk_target_sysroot = shlex.split(m.group(1))[0]

m = re.match(r'^\s*export\s+CC=(.*)', line)
if m:
cc = shlex.split(m.group(1))[0]
m = re.match(r'^\s*export\s+CXX=(.*)', line)
if m:
cxx = shlex.split(m.group(1))[0]

m = re.match(r'^\s*export\s+ARCH=(.*)', line)
if m:
target_cpu = shlex.split(m.group(1))[0]
if target_cpu == 'arm64':
arm_arch = 'armv8-a'
elif target_cpu == 'arm':
arm_arch = 'armv7ve'
else:
raise Exception('ARCH should be arm64 or arm in the SDK environment setup script.')

m = re.match(r'^\s*export\s+CROSS_COMPILE=(.*)', line)
if m:
cross_compile = shlex.split(m.group(1))[0][:-1]

try:
sdk_target_sysroot
except NameError:
raise Exception('SDKTARGETSYSROOT is not found in the SDK environment setup script.')
else:
try:
cc
cxx
except NameError:
raise Exception('CC and/or CXX are not found in the SDK environment setup script.')
else:
cc = cc.replace('$SDKTARGETSYSROOT', sdk_target_sysroot)
cxx = cxx.replace('$SDKTARGETSYSROOT', sdk_target_sysroot)
try:
target_cpu
cross_compile
except NameError:
raise Exception('ARCH and/or CROSS_COMPILE are not found in the SDK environment setup script.')

args = [
'treat_warnings_as_errors=false',
'target_os="linux"',
'target_cpu="arm64"',
'arm_arch="armv8-a"',
'target_cpu="%s"' % target_cpu,
'arm_arch="%s"' % arm_arch,
'import(\"//build_overrides/build.gni\")',
'custom_toolchain=\"${build_root}/toolchain/custom\"',
'sysroot="%s/sysroots/cortexa53-crypto-poky-linux"' % self.SysRootPath('IMX_SDK_ROOT'),
'sysroot="%s"' % sdk_target_sysroot,
'target_cflags=[ "-DCHIP_DEVICE_CONFIG_WIFI_STATION_IF_NAME=\\"mlan0\\"", "-DCHIP_DEVICE_CONFIG_LINUX_DHCPC_CMD=\\"udhcpc -b -i %s \\"" ]',
'target_cc="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc"' % self.SysRootPath(
'IMX_SDK_ROOT'),
'target_cxx="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++"' % self.SysRootPath(
'IMX_SDK_ROOT'),
'target_ar="%s/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ar"' % self.SysRootPath(
'IMX_SDK_ROOT'),
'target_cc="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile,
cc),
'target_cxx="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile,
cxx),
'target_ar="%s/sysroots/x86_64-pokysdk-linux/usr/bin/%s/%s-ar"' % (self.SysRootPath('IMX_SDK_ROOT'), cross_compile,
cross_compile),
]

if self.release:
args.append('is_debug=false')
else:
args.append('optimize_debug=true')

return args

Expand Down
Loading