Set the right env variable when necessary.
The `cross_path_only` option used in `cmake` and `meson` builder where mainly here to avoid kiwix-build to set the env with `CC` and `CXX` variable set. This is needed as `cmake` and `meson` will find the correct compiler from the cross-config file. However, even for them, we need to set some environment variables (especially PKG_CONFIG_LIBDIR) So we need another level a configuration to be able to set a cross_env without setting the compiler's env variables.
This commit is contained in:
parent
6026daf3dd
commit
4f0b2ec376
|
@ -297,7 +297,7 @@ class CMakeBuilder(MakeBuilder):
|
||||||
v = v.format(buildEnv=self.buildEnv, env=env)
|
v = v.format(buildEnv=self.buildEnv, env=env)
|
||||||
self.configure_env[k[8:]] = v
|
self.configure_env[k[8:]] = v
|
||||||
env.update(self.configure_env)
|
env.update(self.configure_env)
|
||||||
self.buildEnv.run_command(command, self.build_path, context, env=env, cross_path_only=True)
|
self.buildEnv.run_command(command, self.build_path, context, env=env, cross_env_only=True)
|
||||||
|
|
||||||
|
|
||||||
class MesonBuilder(Builder):
|
class MesonBuilder(Builder):
|
||||||
|
@ -327,7 +327,7 @@ class MesonBuilder(Builder):
|
||||||
buildEnv=self.buildEnv,
|
buildEnv=self.buildEnv,
|
||||||
cross_option="--cross-file {}".format(self.buildEnv.meson_crossfile) if self.buildEnv.meson_crossfile else ""
|
cross_option="--cross-file {}".format(self.buildEnv.meson_crossfile) if self.buildEnv.meson_crossfile else ""
|
||||||
)
|
)
|
||||||
self.buildEnv.run_command(command, self.source_path, context, cross_path_only=True)
|
self.buildEnv.run_command(command, self.source_path, context, cross_env_only=True)
|
||||||
|
|
||||||
def _compile(self, context):
|
def _compile(self, context):
|
||||||
command = "{} -v".format(self.buildEnv.ninja_command)
|
command = "{} -v".format(self.buildEnv.ninja_command)
|
||||||
|
|
|
@ -355,7 +355,7 @@ class BuildEnv:
|
||||||
cmake_options = [tlc.cmake_option for tlc in self.toolchains]
|
cmake_options = [tlc.cmake_option for tlc in self.toolchains]
|
||||||
return " ".join(cmake_options)
|
return " ".join(cmake_options)
|
||||||
|
|
||||||
def _set_env(self, env, cross_compile_env, cross_compile_path):
|
def _set_env(self, env, cross_compile_env, cross_compile_compiler, cross_compile_path):
|
||||||
if env is None:
|
if env is None:
|
||||||
env = Defaultdict(str, os.environ)
|
env = Defaultdict(str, os.environ)
|
||||||
|
|
||||||
|
@ -368,6 +368,9 @@ class BuildEnv:
|
||||||
env[k] = v
|
env[k] = v
|
||||||
for toolchain in self.toolchains:
|
for toolchain in self.toolchains:
|
||||||
toolchain.set_env(env)
|
toolchain.set_env(env)
|
||||||
|
if cross_compile_compiler:
|
||||||
|
for toolchain in self.toolchains:
|
||||||
|
toolchain.set_compiler(env)
|
||||||
if cross_compile_path:
|
if cross_compile_path:
|
||||||
for tlc in self.toolchains:
|
for tlc in self.toolchains:
|
||||||
bin_dirs += tlc.get_bin_dir()
|
bin_dirs += tlc.get_bin_dir()
|
||||||
|
@ -398,16 +401,18 @@ class BuildEnv:
|
||||||
env['LDFLAGS']])
|
env['LDFLAGS']])
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def run_command(self, command, cwd, context, env=None, input=None, cross_path_only=False):
|
def run_command(self, command, cwd, context, env=None, input=None, cross_env_only=False):
|
||||||
os.makedirs(cwd, exist_ok=True)
|
os.makedirs(cwd, exist_ok=True)
|
||||||
cross_compile_env = True
|
cross_compile_env = True
|
||||||
|
cross_compile_compiler = True
|
||||||
cross_compile_path = True
|
cross_compile_path = True
|
||||||
if context.force_native_build:
|
if context.force_native_build:
|
||||||
cross_compile_env = False
|
cross_compile_env = False
|
||||||
|
cross_compile_compiler = False
|
||||||
cross_compile_path = False
|
cross_compile_path = False
|
||||||
if cross_path_only:
|
if cross_env_only:
|
||||||
cross_compile_env = False
|
cross_compile_compiler = False
|
||||||
env = self._set_env(env, cross_compile_env, cross_compile_path)
|
env = self._set_env(env, cross_compile_env, cross_compile_compiler, cross_compile_path)
|
||||||
log = None
|
log = None
|
||||||
try:
|
try:
|
||||||
if not self.options.verbose:
|
if not self.options.verbose:
|
||||||
|
@ -528,6 +533,9 @@ class Toolchain(metaclass=_MetaToolchain):
|
||||||
def set_env(self, env):
|
def set_env(self, env):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def set_compiler(self, env):
|
||||||
|
pass
|
||||||
|
|
||||||
def command(self, name, function, *args):
|
def command(self, name, function, *args):
|
||||||
print(" {} {} : ".format(name, self.name), end="", flush=True)
|
print(" {} {} : ".format(name, self.name), end="", flush=True)
|
||||||
log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name))
|
log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name))
|
||||||
|
@ -579,12 +587,13 @@ class mingw32_toolchain(Toolchain):
|
||||||
return [pj(self.root_path, 'bin')]
|
return [pj(self.root_path, 'bin')]
|
||||||
|
|
||||||
def set_env(self, env):
|
def set_env(self, env):
|
||||||
for k, v in self.binaries.items():
|
|
||||||
env[k] = v
|
|
||||||
|
|
||||||
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
||||||
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']
|
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']
|
||||||
|
|
||||||
|
def set_compiler(self, env):
|
||||||
|
for k, v in self.binaries.items():
|
||||||
|
env[k] = v
|
||||||
|
|
||||||
|
|
||||||
class android_ndk(Toolchain):
|
class android_ndk(Toolchain):
|
||||||
name = 'android-ndk'
|
name = 'android-ndk'
|
||||||
|
@ -696,9 +705,6 @@ class android_ndk(Toolchain):
|
||||||
return [pj(self.builder.install_path, 'bin')]
|
return [pj(self.builder.install_path, 'bin')]
|
||||||
|
|
||||||
def set_env(self, env):
|
def set_env(self, env):
|
||||||
env['CC'] = self.binaries['CC']
|
|
||||||
env['CXX'] = self.binaries['CXX']
|
|
||||||
|
|
||||||
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
||||||
env['CFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CFLAGS']
|
env['CFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CFLAGS']
|
||||||
env['CXXFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CXXFLAGS']
|
env['CXXFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CXXFLAGS']
|
||||||
|
@ -710,6 +716,10 @@ class android_ndk(Toolchain):
|
||||||
# '-DU_HAVE_STD_STRING -DU_TIMEZONE=0 ')+env['CXXFLAGS']
|
# '-DU_HAVE_STD_STRING -DU_TIMEZONE=0 ')+env['CXXFLAGS']
|
||||||
env['NDK_DEBUG'] = '0'
|
env['NDK_DEBUG'] = '0'
|
||||||
|
|
||||||
|
def set_compiler(self, env):
|
||||||
|
env['CC'] = self.binaries['CC']
|
||||||
|
env['CXX'] = self.binaries['CXX']
|
||||||
|
|
||||||
|
|
||||||
class android_sdk(Toolchain):
|
class android_sdk(Toolchain):
|
||||||
name = 'android-sdk'
|
name = 'android-sdk'
|
||||||
|
@ -795,14 +805,15 @@ class armhf_toolchain(Toolchain):
|
||||||
return [pj(self.root_path, 'bin')]
|
return [pj(self.root_path, 'bin')]
|
||||||
|
|
||||||
def set_env(self, env):
|
def set_env(self, env):
|
||||||
env['CC'] = self.binaries['CC']
|
|
||||||
env['CXX'] = self.binaries['CXX']
|
|
||||||
|
|
||||||
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
|
||||||
env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS']
|
env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS']
|
||||||
env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS']
|
env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS']
|
||||||
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']
|
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']
|
||||||
|
|
||||||
|
def set_compiler(self, env):
|
||||||
|
env['CC'] = self.binaries['CC']
|
||||||
|
env['CXX'] = self.binaries['CXX']
|
||||||
|
|
||||||
|
|
||||||
class Builder:
|
class Builder:
|
||||||
def __init__(self, options):
|
def __init__(self, options):
|
||||||
|
|
Loading…
Reference in New Issue