mirror of
https://github.com/ZDoom/zdoom-macos-deps.git
synced 2024-11-21 19:41:15 +00:00
aedi: replace usages of legacy subprocess api
apply state's environment variables when running an external process
This commit is contained in:
parent
e410e3f7f4
commit
bda525b49a
5 changed files with 26 additions and 22 deletions
|
@ -89,11 +89,11 @@ class BuildState:
|
||||||
return
|
return
|
||||||
|
|
||||||
args = ('git', 'clone', '--recurse-submodules', url, self.source)
|
args = ('git', 'clone', '--recurse-submodules', url, self.source)
|
||||||
subprocess.run(args, cwd=self.root_path, check=True)
|
subprocess.run(args, check=True, cwd=self.root_path, env=self.environment)
|
||||||
|
|
||||||
if branch:
|
if branch:
|
||||||
args = ('git', 'checkout', '-b', branch, 'origin/' + branch)
|
args = ('git', 'checkout', '-b', branch, 'origin/' + branch)
|
||||||
subprocess.run(args, cwd=self.source, check=True)
|
subprocess.run(args, check=True, cwd=self.source, env=self.environment)
|
||||||
|
|
||||||
def download_source(self, url: str, checksum: str, patches: typing.Union[tuple, list, str] = None):
|
def download_source(self, url: str, checksum: str, patches: typing.Union[tuple, list, str] = None):
|
||||||
if self.external_source:
|
if self.external_source:
|
||||||
|
@ -156,7 +156,10 @@ class BuildState:
|
||||||
raise Exception(f'Checksum of {filepath} does not match, expected: {checksum}, actual: {file_checksum}')
|
raise Exception(f'Checksum of {filepath} does not match, expected: {checksum}, actual: {file_checksum}')
|
||||||
|
|
||||||
def _unpack_source_package(self, filepath: Path) -> typing.Tuple[str, Path]:
|
def _unpack_source_package(self, filepath: Path) -> typing.Tuple[str, Path]:
|
||||||
file_paths_str = subprocess.check_output(['tar', '-tf', filepath]).decode("utf-8")
|
args = ('tar', '-tf', filepath)
|
||||||
|
result = subprocess.run(args, check=True, env=self.environment, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
file_paths_str = result.stdout.decode("utf-8")
|
||||||
file_paths = file_paths_str.split('\n')
|
file_paths = file_paths_str.split('\n')
|
||||||
first_path_component = None
|
first_path_component = None
|
||||||
|
|
||||||
|
@ -173,7 +176,8 @@ class BuildState:
|
||||||
if not extract_path.exists():
|
if not extract_path.exists():
|
||||||
# Extract source code package
|
# Extract source code package
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(['tar', '-xf', filepath], cwd=self.source)
|
args = ('tar', '-xf', filepath)
|
||||||
|
subprocess.run(args, check=True, cwd=self.source, env=self.environment)
|
||||||
except (IOError, subprocess.CalledProcessError):
|
except (IOError, subprocess.CalledProcessError):
|
||||||
shutil.rmtree(extract_path, ignore_errors=True)
|
shutil.rmtree(extract_path, ignore_errors=True)
|
||||||
raise
|
raise
|
||||||
|
@ -188,18 +192,18 @@ class BuildState:
|
||||||
test_arg = '--dry-run'
|
test_arg = '--dry-run'
|
||||||
args = ['patch', test_arg, '--strip=1', '--input=' + str(patch_path)]
|
args = ['patch', test_arg, '--strip=1', '--input=' + str(patch_path)]
|
||||||
|
|
||||||
if subprocess.call(args, cwd=extract_path) == 0:
|
if subprocess.run(args, cwd=extract_path, env=self.environment) == 0:
|
||||||
# Patch wasn't applied yet, do it now
|
# Patch wasn't applied yet, do it now
|
||||||
args.remove(test_arg)
|
args.remove(test_arg)
|
||||||
subprocess.check_call(args, cwd=extract_path)
|
subprocess.run(args, check=True, cwd=extract_path, env=self.environment)
|
||||||
|
|
||||||
def run_pkg_config(self, *args) -> str:
|
def run_pkg_config(self, *args) -> str:
|
||||||
os.makedirs(self.build_path, exist_ok=True)
|
os.makedirs(self.build_path, exist_ok=True)
|
||||||
|
|
||||||
args = (self.bin_path / 'pkg-config',) + args
|
args = (self.bin_path / 'pkg-config',) + args
|
||||||
result = subprocess.check_output(args, cwd=self.build_path)
|
result = subprocess.run(args, check=True, cwd=self.build_path, env=self.environment, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
return result.decode('utf-8').rstrip('\n')
|
return result.stdout.decode('utf-8').rstrip('\n')
|
||||||
|
|
||||||
def has_source_file(self, path: typing.Union[str, Path]):
|
def has_source_file(self, path: typing.Union[str, Path]):
|
||||||
return (self.source / path).exists()
|
return (self.source / path).exists()
|
||||||
|
|
|
@ -136,7 +136,7 @@ class BuildTarget(Target):
|
||||||
args = [tool, 'install']
|
args = [tool, 'install']
|
||||||
args += options and options.to_list() or []
|
args += options and options.to_list() or []
|
||||||
|
|
||||||
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
|
|
||||||
self.update_pc_files(state)
|
self.update_pc_files(state)
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ class MakeTarget(BuildTarget):
|
||||||
args += state.options.to_list()
|
args += state.options.to_list()
|
||||||
|
|
||||||
work_path = state.build_path / self.src_root
|
work_path = state.build_path / self.src_root
|
||||||
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=work_path, env=state.environment)
|
||||||
|
|
||||||
|
|
||||||
class ConfigureMakeTarget(MakeTarget):
|
class ConfigureMakeTarget(MakeTarget):
|
||||||
|
@ -330,17 +330,17 @@ class ConfigureMakeTarget(MakeTarget):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Try with host and disabled dependency tracking first
|
# Try with host and disabled dependency tracking first
|
||||||
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=work_path, env=state.environment)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
# If it fails, try with disabled dependency tracking only
|
# If it fails, try with disabled dependency tracking only
|
||||||
args = copy.copy(common_args)
|
args = copy.copy(common_args)
|
||||||
args.append(disable_dependency_tracking)
|
args.append(disable_dependency_tracking)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(args, cwd=work_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=work_path, env=state.environment)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
# Use only common command line arguments
|
# Use only common command line arguments
|
||||||
subprocess.check_call(common_args, cwd=work_path, env=state.environment)
|
subprocess.run(common_args, check=True, cwd=work_path, env=state.environment)
|
||||||
|
|
||||||
def build(self, state: BuildState):
|
def build(self, state: BuildState):
|
||||||
# Clear configure script options
|
# Clear configure script options
|
||||||
|
@ -434,7 +434,7 @@ class CMakeTarget(BuildTarget):
|
||||||
args += state.options.to_list(CommandLineOptions.CMAKE_RULES)
|
args += state.options.to_list(CommandLineOptions.CMAKE_RULES)
|
||||||
args.append(state.source / self.src_root)
|
args.append(state.source / self.src_root)
|
||||||
|
|
||||||
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
|
|
||||||
def build(self, state: BuildState):
|
def build(self, state: BuildState):
|
||||||
if state.xcode:
|
if state.xcode:
|
||||||
|
@ -445,7 +445,7 @@ class CMakeTarget(BuildTarget):
|
||||||
if state.verbose:
|
if state.verbose:
|
||||||
args.append('VERBOSE=1')
|
args.append('VERBOSE=1')
|
||||||
|
|
||||||
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
|
|
||||||
|
|
||||||
class ConfigureMakeDependencyTarget(ConfigureMakeTarget):
|
class ConfigureMakeDependencyTarget(ConfigureMakeTarget):
|
||||||
|
|
|
@ -188,11 +188,11 @@ endian = 'little'
|
||||||
f'--cross-file={cross_file}',
|
f'--cross-file={cross_file}',
|
||||||
state.source
|
state.source
|
||||||
)
|
)
|
||||||
subprocess.check_call(args, cwd=state.build_path, env=environment)
|
subprocess.run(args, check=True, cwd=state.build_path, env=environment)
|
||||||
|
|
||||||
def build(self, state: BuildState):
|
def build(self, state: BuildState):
|
||||||
args = ('ninja',)
|
args = ('ninja',)
|
||||||
subprocess.check_call(args, cwd=state.build_path, env=state.environment)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
|
|
||||||
def post_build(self, state: BuildState):
|
def post_build(self, state: BuildState):
|
||||||
self.install(state, tool='ninja')
|
self.install(state, tool='ninja')
|
||||||
|
|
|
@ -38,7 +38,7 @@ class CleanTarget(Target):
|
||||||
assert not state.xcode
|
assert not state.xcode
|
||||||
|
|
||||||
args = ('git', 'clean') + self.args
|
args = ('git', 'clean') + self.args
|
||||||
subprocess.check_call(args, cwd=state.root_path)
|
subprocess.run(args, check=True, cwd=state.root_path, env=state.environment)
|
||||||
|
|
||||||
|
|
||||||
class CleanAllTarget(CleanTarget):
|
class CleanAllTarget(CleanTarget):
|
||||||
|
@ -106,5 +106,5 @@ class TestDepsTarget(BuildTarget):
|
||||||
entry,
|
entry,
|
||||||
]
|
]
|
||||||
args += shlex.split(pkg_config_output)
|
args += shlex.split(pkg_config_output)
|
||||||
subprocess.run(args, cwd=state.build_path, check=True)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
subprocess.run((exe_name,), check=True)
|
subprocess.run((exe_name,), check=True, env=state.environment)
|
||||||
|
|
|
@ -43,7 +43,7 @@ class SingleExeCTarget(MakeTarget):
|
||||||
for var in ('CFLAGS', 'LDFLAGS'):
|
for var in ('CFLAGS', 'LDFLAGS'):
|
||||||
args += shlex.split(state.environment[var])
|
args += shlex.split(state.environment[var])
|
||||||
|
|
||||||
subprocess.run(args, check=True, cwd=state.build_path)
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|
||||||
|
|
||||||
def post_build(self, state: BuildState):
|
def post_build(self, state: BuildState):
|
||||||
self.copy_to_bin(state)
|
self.copy_to_bin(state)
|
||||||
|
@ -70,7 +70,7 @@ class BuildCMakeTarget(CMakeTarget):
|
||||||
os.makedirs(boostrap_path, exist_ok=True)
|
os.makedirs(boostrap_path, exist_ok=True)
|
||||||
|
|
||||||
args = (state.source / 'configure', '--parallel=' + state.jobs)
|
args = (state.source / 'configure', '--parallel=' + state.jobs)
|
||||||
subprocess.run(args, cwd=boostrap_path)
|
subprocess.run(args, check=True, cwd=boostrap_path, env=state.environment)
|
||||||
|
|
||||||
assert boostrap_cmake.exists()
|
assert boostrap_cmake.exists()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue