Make the dependency responsible to set the compilation env.

Instead of having the run_command function setting the
env from the buildEnv, this is the dependency that create the
env and then pass it to the run_command function.

This way, each dependency will be able to set a specific env.
This commit is contained in:
Matthieu Gautier
2020-02-20 16:37:42 +01:00
parent e27ede80cc
commit 7b6c79482a
17 changed files with 213 additions and 118 deletions

View File

@ -63,7 +63,6 @@ class Source:
def _patch(self, context):
context.try_skip(self.source_path)
context.force_native_build = True
for p in self.patches:
with open(pj(SCRIPT_DIR, 'patches', p), 'r') as patch_input:
run_command("patch -p1", self.source_path, context, input=patch_input.read())
@ -312,6 +311,18 @@ class MakeBuilder(Builder):
)
return option
def set_configure_env(self, env):
dep_conf_env = self.configure_env
if not dep_conf_env:
return
for k in list(dep_conf_env):
if k.startswith('_format_'):
v = dep_conf_env.pop(k)
v = v.format(buildEnv=self.buildEnv, env=env)
dep_conf_env[k[8:]] = v
env.update(dep_conf_env)
def _configure(self, context):
context.try_skip(self.build_path)
command = "{configure_script} {configure_option}"
@ -319,19 +330,9 @@ class MakeBuilder(Builder):
configure_script=pj(self.source_path, self.configure_script),
configure_option=self.all_configure_option
)
env = Defaultdict(str, os.environ)
if self.buildEnv.platformInfo.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
env['CXXFLAGS'] = env['CXXFLAGS'] + ' -fPIC'
dep_conf_env = self.configure_env
if dep_conf_env:
for k in list(dep_conf_env):
if k.startswith('_format_'):
v = dep_conf_env.pop(k)
v = v.format(buildEnv=self.buildEnv, env=env)
dep_conf_env[k[8:]] = v
env.update(dep_conf_env)
run_command(command, self.build_path, context, buildEnv=self.buildEnv, env=env)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
self.set_configure_env(env)
run_command(command, self.build_path, context, env=env)
def _compile(self, context):
context.try_skip(self.build_path)
@ -339,7 +340,8 @@ class MakeBuilder(Builder):
make_target=self.make_target,
make_option=self.make_option
)
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
run_command(command, self.build_path, context, env=env)
def _install(self, context):
context.try_skip(self.build_path)
@ -347,12 +349,14 @@ class MakeBuilder(Builder):
make_install_target=self.make_install_target,
make_option=self.make_option
)
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
run_command(command, self.build_path, context, env=env)
def _make_dist(self, context):
context.try_skip(self.build_path)
command = "make dist"
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
run_command(command, self.build_path, context, env=env)
class CMakeBuilder(MakeBuilder):
@ -376,18 +380,9 @@ class CMakeBuilder(MakeBuilder):
source_path=self.source_path,
cross_option=cross_option
)
env = Defaultdict(str, os.environ)
if self.buildEnv.platformInfo.static:
env['CFLAGS'] = env['CFLAGS'] + ' -fPIC'
env['CXXFLAGS'] = env['CXXFLAGS'] + ' -fPIC'
if self.configure_env:
for k in self.configure_env:
if k.startswith('_format_'):
v = self.configure_env.pop(k)
v = v.format(buildEnv=self.buildEnv, env=env)
self.configure_env[k[8:]] = v
env.update(self.configure_env)
run_command(command, self.build_path, context, env=env, buildEnv=self.buildEnv, cross_env_only=True)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=False, cross_path=True)
self.set_configure_env(env)
run_command(command, self.build_path, context, env=env)
def set_flatpak_buildsystem(self, module):
super().set_flatpak_buildsystem( module)
@ -420,15 +415,9 @@ class QMakeBuilder(MakeBuilder):
source_path=self.source_path,
cross_option=cross_option
)
run_command(command, self.build_path, context, buildEnv=self.buildEnv, cross_env_only=True)
def _install(self, context):
context.try_skip(self.build_path)
command = "make {make_install_target} {make_option}".format(
make_install_target=self.make_install_target,
make_option=self.make_option
)
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=False, cross_path=True)
self.set_configure_env(env)
run_command(command, self.build_path, context, env=env)
def _make_dist(self, context):
command = "git archive -o {build_dir}/{name}.tar.gz --prefix={name}/ HEAD"
@ -436,7 +425,7 @@ class QMakeBuilder(MakeBuilder):
build_dir = self.build_path,
name = self.target.full_name()
)
run_command(command, self.source_path, context, buildEnv=self.buildEnv)
run_command(command, self.source_path, context)
@ -484,11 +473,13 @@ class MesonBuilder(Builder):
buildEnv=self.buildEnv,
cross_option=cross_option
)
run_command(command, self.source_path, context, buildEnv=self.buildEnv, cross_env_only=True)
env = self.buildEnv.get_env(cross_comp_flags=False, cross_compilers=False, cross_path=True)
run_command(command, self.source_path, context, env=env)
def _compile(self, context):
command = "{} -v".format(neutralEnv('ninja_command'))
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=False, cross_compilers=False, cross_path=True)
run_command(command, self.build_path, context, env=env)
def _test(self, context):
if ( self.buildEnv.platformInfo.build == 'android'
@ -497,15 +488,18 @@ class MesonBuilder(Builder):
):
raise SkipCommand()
command = "{} --verbose {}".format(neutralEnv('mesontest_command'), self.test_option)
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=False, cross_compilers=False, cross_path=True)
run_command(command, self.build_path, context, env=env)
def _install(self, context):
command = "{} -v install".format(neutralEnv('ninja_command'))
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=False, cross_compilers=False, cross_path=True)
run_command(command, self.build_path, context, env=env)
def _make_dist(self, context):
command = "{} -v dist".format(neutralEnv('ninja_command'))
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=False, cross_compilers=False, cross_path=True)
run_command(command, self.build_path, context, env=env)
class GradleBuilder(Builder):
@ -530,4 +524,5 @@ class GradleBuilder(Builder):
command = command.format(
gradle_target=self.gradle_target,
gradle_option=self.gradle_option)
run_command(command, self.build_path, context, buildEnv=self.buildEnv)
env = self.buildEnv.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
run_command(command, self.build_path, context, env=env)