Detect the command instead of hardcoding them.
This commit is contained in:
parent
c99a9bd91f
commit
985643089a
|
@ -21,16 +21,20 @@ class PlatformNeutralEnv:
|
||||||
self.log_dir):
|
self.log_dir):
|
||||||
os.makedirs(d, exist_ok=True)
|
os.makedirs(d, exist_ok=True)
|
||||||
self.detect_platform()
|
self.detect_platform()
|
||||||
self.ninja_command = self._detect_ninja()
|
self.ninja_command = self._detect_command(
|
||||||
if not self.ninja_command:
|
'ninja',
|
||||||
sys.exit("ERROR: ninja command not found.")
|
default=[['ninja'], ['ninja-build']])
|
||||||
self.meson_command = self._detect_meson()
|
self.meson_command = self._detect_command(
|
||||||
if not self.meson_command:
|
'meson',
|
||||||
sys.exit("ERROR: meson command not found.")
|
default= [['meson.py'], ['meson']])
|
||||||
self.qmake_command = self._detect_qmake()
|
|
||||||
if not self.qmake_command:
|
|
||||||
print("WARNING: qmake command not found.", file=sys.stderr)
|
|
||||||
self.mesontest_command = [*self.meson_command, "test"]
|
self.mesontest_command = [*self.meson_command, "test"]
|
||||||
|
self.patch_command = self._detect_command('patch')
|
||||||
|
self.git_command = self._detect_command('git')
|
||||||
|
self.svn_command = self._detect_command('svn')
|
||||||
|
self.make_command = self._detect_command('make')
|
||||||
|
self.cmake_command = self._detect_command('cmake')
|
||||||
|
self.qmake_command = self._detect_command('qmake', required=False)
|
||||||
|
|
||||||
|
|
||||||
def detect_platform(self):
|
def detect_platform(self):
|
||||||
_platform = platform.system()
|
_platform = platform.system()
|
||||||
|
@ -50,27 +54,28 @@ class PlatformNeutralEnv:
|
||||||
where = where or self.archive_dir
|
where = where or self.archive_dir
|
||||||
download_remote(what, where)
|
download_remote(what, where)
|
||||||
|
|
||||||
def _detect_binary(self, *bin_variants):
|
|
||||||
for n in bin_variants:
|
def _detect_command(self, name, default=None, options=['--version'], required=True):
|
||||||
|
if default is None:
|
||||||
|
default = [[name]]
|
||||||
|
env_key = 'KBUILD_{}_COMMAND'.format(name.upper())
|
||||||
|
if env_key in os.environ:
|
||||||
|
default = [os.environ[env_key].split()] + default
|
||||||
|
for command in default:
|
||||||
try:
|
try:
|
||||||
retcode = subprocess.check_call([n, '--version'],
|
retcode = subprocess.check_call(command + options,
|
||||||
stdout=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL)
|
||||||
except (FileNotFoundError, PermissionError):
|
except (FileNotFoundError, PermissionError, OSError):
|
||||||
# Doesn't exist in PATH or isn't executable
|
# Doesn't exist in PATH or isn't executable
|
||||||
continue
|
continue
|
||||||
if retcode == 0:
|
if retcode == 0:
|
||||||
return [n]
|
return command
|
||||||
|
else:
|
||||||
|
if required:
|
||||||
def _detect_ninja(self):
|
sys.exit("ERROR: {} command not found".format(name))
|
||||||
return self._detect_binary('ninja', 'ninja-build')
|
else:
|
||||||
|
print("WARNING: {} command not found".format(name))
|
||||||
def _detect_meson(self):
|
return ["{}_NOT_FOUND".format(name.upper())]
|
||||||
return self._detect_binary('meson.py', 'meson')
|
|
||||||
|
|
||||||
def _detect_qmake(self):
|
|
||||||
return self._detect_binary('qmake-qt5', 'qmake')
|
|
||||||
|
|
||||||
|
|
||||||
class BuildEnv:
|
class BuildEnv:
|
||||||
def __init__(self, platformInfo):
|
def __init__(self, platformInfo):
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Source:
|
||||||
context.try_skip(self.source_path)
|
context.try_skip(self.source_path)
|
||||||
for p in self.patches:
|
for p in self.patches:
|
||||||
patch_file_path = pj(SCRIPT_DIR, 'patches', p)
|
patch_file_path = pj(SCRIPT_DIR, 'patches', p)
|
||||||
patch_command = ["patch", "-p1", "-i", patch_file_path]
|
patch_command = [*neutralEnv('patch_command'), "-p1", "-i", patch_file_path]
|
||||||
run_command(patch_command, self.source_path, context)
|
run_command(patch_command, self.source_path, context)
|
||||||
|
|
||||||
def command(self, name, function, *args):
|
def command(self, name, function, *args):
|
||||||
|
@ -170,19 +170,19 @@ class GitClone(Source):
|
||||||
|
|
||||||
def _git_init(self, context):
|
def _git_init(self, context):
|
||||||
if option('fast_clone') and self.force_full_clone == False:
|
if option('fast_clone') and self.force_full_clone == False:
|
||||||
command = ["git", "clone" , "--depth=1", "--branch", self.git_ref, self.git_remote, self.source_dir]
|
command = [*neutralEnv('git_command'), "clone" , "--depth=1", "--branch", self.git_ref, self.git_remote, self.source_dir]
|
||||||
run_command(command, neutralEnv('source_dir'), context)
|
run_command(command, neutralEnv('source_dir'), context)
|
||||||
else:
|
else:
|
||||||
command = ["git", "clone", self.git_remote, self.source_dir]
|
command = [*neutralEnv('git_command'), "clone", self.git_remote, self.source_dir]
|
||||||
run_command(command, neutralEnv('source_dir'), context)
|
run_command(command, neutralEnv('source_dir'), context)
|
||||||
command = ["git", "checkout", self.git_ref]
|
command = [*neutralEnv('git_command'), "checkout", self.git_ref]
|
||||||
run_command(command, self.git_path, context)
|
run_command(command, self.git_path, context)
|
||||||
|
|
||||||
def _git_update(self, context):
|
def _git_update(self, context):
|
||||||
command = ["git", "fetch", "origin", self.git_ref]
|
command = [*neutralEnv('git_command'), "fetch", "origin", self.git_ref]
|
||||||
run_command(command, self.git_path, context)
|
run_command(command, self.git_path, context)
|
||||||
try:
|
try:
|
||||||
command = ["git", "merge", "--ff-only", f"origin/{self.git_ref}"]
|
command = [*neutralEnv('git_command'), "merge", "--ff-only", f"origin/{self.git_ref}"]
|
||||||
run_command(command, self.git_path, context)
|
run_command(command, self.git_path, context)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
raise WarningMessage("Cannot update, please check log for information")
|
raise WarningMessage("Cannot update, please check log for information")
|
||||||
|
@ -209,7 +209,7 @@ class SvnClone(Source):
|
||||||
if os.path.exists(self.svn_path):
|
if os.path.exists(self.svn_path):
|
||||||
raise SkipCommand()
|
raise SkipCommand()
|
||||||
command = [
|
command = [
|
||||||
"svn", "export",
|
*neutralEnv('svn_command'), "export",
|
||||||
self.svn_remote, self.svn_dir
|
self.svn_remote, self.svn_dir
|
||||||
]
|
]
|
||||||
run_command(command, neutralEnv('source_dir'), context)
|
run_command(command, neutralEnv('source_dir'), context)
|
||||||
|
@ -415,7 +415,8 @@ class MakeBuilder(Builder):
|
||||||
context.try_skip(self.build_path)
|
context.try_skip(self.build_path)
|
||||||
command = [
|
command = [
|
||||||
*self.buildEnv.make_wrapper,
|
*self.buildEnv.make_wrapper,
|
||||||
"make", "-j4",
|
*neutralEnv('make_command'),
|
||||||
|
"-j4",
|
||||||
*self.make_targets,
|
*self.make_targets,
|
||||||
*self.make_options
|
*self.make_options
|
||||||
]
|
]
|
||||||
|
@ -426,7 +427,7 @@ class MakeBuilder(Builder):
|
||||||
context.try_skip(self.build_path)
|
context.try_skip(self.build_path)
|
||||||
command = [
|
command = [
|
||||||
*self.buildEnv.make_wrapper,
|
*self.buildEnv.make_wrapper,
|
||||||
"make",
|
*neutralEnv('make_command'),
|
||||||
*self.make_install_targets,
|
*self.make_install_targets,
|
||||||
*self.make_options
|
*self.make_options
|
||||||
]
|
]
|
||||||
|
@ -437,7 +438,8 @@ class MakeBuilder(Builder):
|
||||||
context.try_skip(self.build_path)
|
context.try_skip(self.build_path)
|
||||||
command = [
|
command = [
|
||||||
*self.buildEnv.make_wrapper,
|
*self.buildEnv.make_wrapper,
|
||||||
"make", "dist"
|
*neutralEnv('make_command'),
|
||||||
|
"dist"
|
||||||
]
|
]
|
||||||
env = self.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
|
env = self.get_env(cross_comp_flags=True, cross_compilers=True, cross_path=True)
|
||||||
run_command(command, self.build_path, context, env=env)
|
run_command(command, self.build_path, context, env=env)
|
||||||
|
@ -452,7 +454,7 @@ class CMakeBuilder(MakeBuilder):
|
||||||
if not self.target.force_native_build and self.buildEnv.cmake_crossfile:
|
if not self.target.force_native_build and self.buildEnv.cmake_crossfile:
|
||||||
cross_options += [f"-DCMAKE_TOOLCHAIN_FILE={self.buildEnv.cmake_crossfile}"]
|
cross_options += [f"-DCMAKE_TOOLCHAIN_FILE={self.buildEnv.cmake_crossfile}"]
|
||||||
command = [
|
command = [
|
||||||
"cmake",
|
*neutralEnv('cmake_command'),
|
||||||
*self.configure_options,
|
*self.configure_options,
|
||||||
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
|
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
|
||||||
f"-DCMAKE_INSTALL_PREFIX={self.buildEnv.install_dir}",
|
f"-DCMAKE_INSTALL_PREFIX={self.buildEnv.install_dir}",
|
||||||
|
@ -483,10 +485,10 @@ class QMakeBuilder(MakeBuilder):
|
||||||
def _configure(self, context):
|
def _configure(self, context):
|
||||||
context.try_skip(self.build_path)
|
context.try_skip(self.build_path)
|
||||||
command = [
|
command = [
|
||||||
*neutralEnv('qmake_command'),
|
"qmake",
|
||||||
*self.configure_options,
|
*self.configure_options,
|
||||||
*self.env_options,
|
*self.env_options,
|
||||||
self.source_path,
|
self.source_path
|
||||||
]
|
]
|
||||||
env = self.get_env(cross_comp_flags=True, cross_compilers=False, cross_path=True)
|
env = self.get_env(cross_comp_flags=True, cross_compilers=False, cross_path=True)
|
||||||
self.set_configure_env(env)
|
self.set_configure_env(env)
|
||||||
|
@ -494,7 +496,7 @@ class QMakeBuilder(MakeBuilder):
|
||||||
|
|
||||||
def _make_dist(self, context):
|
def _make_dist(self, context):
|
||||||
command = [
|
command = [
|
||||||
"git", "archive",
|
*neutralEnv('git_command'), "archive",
|
||||||
"-o", f"{self.build_path}/{self.target_full_name()}.tar.gz",
|
"-o", f"{self.build_path}/{self.target_full_name()}.tar.gz",
|
||||||
f"--prefix={self.target_full_name()}/",
|
f"--prefix={self.target_full_name()}/",
|
||||||
"HEAD"
|
"HEAD"
|
||||||
|
|
Loading…
Reference in New Issue