2020-08-21 09:59:40 +03:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from string import Template
|
|
|
|
|
2020-09-06 09:29:31 +03:00
|
|
|
from config import Config, Target
|
2020-08-21 09:59:40 +03:00
|
|
|
from utils.shell import shell
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
class Builder:
|
|
|
|
config: Config
|
2020-09-06 09:29:31 +03:00
|
|
|
|
2020-08-21 09:59:40 +03:00
|
|
|
download_command: Template
|
2020-09-06 09:29:31 +03:00
|
|
|
extract_command: Template
|
2020-08-21 09:59:40 +03:00
|
|
|
make_command: Template
|
2020-09-06 09:29:31 +03:00
|
|
|
build_universal_and_install_command: Template
|
2020-08-21 09:59:40 +03:00
|
|
|
|
|
|
|
def download(self):
|
|
|
|
cmd = self.download_command.substitute(dict(version=self.config.version))
|
|
|
|
print(cmd)
|
|
|
|
shell(cmd, cwd=self.config.working_directory)
|
|
|
|
|
2020-09-06 09:29:31 +03:00
|
|
|
def extract(self, target: Target):
|
|
|
|
cmd = self.extract_command.substitute(
|
|
|
|
dict(
|
|
|
|
target=target.value,
|
|
|
|
version=self.config.version,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
print(cmd)
|
|
|
|
shell(cmd, cwd=self.config.working_directory)
|
|
|
|
|
|
|
|
def make(self, target: Target):
|
2020-08-21 09:59:40 +03:00
|
|
|
cmd = self.make_command.substitute(
|
|
|
|
dict(
|
2020-09-06 09:29:31 +03:00
|
|
|
target=target.value,
|
|
|
|
cflags=self.config.target_specific_full_cflags(target),
|
|
|
|
deployment_target=self.config.target_specific_deployment_target(target),
|
|
|
|
install_path=self.config.target_specific_install_path(target),
|
2020-11-15 11:24:07 +03:00
|
|
|
host=self.config.target_specific_host(target),
|
2020-08-21 09:59:40 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
print(cmd)
|
|
|
|
shell(cmd, cwd=self.config.working_directory)
|
|
|
|
|
2020-09-06 09:29:31 +03:00
|
|
|
def build_universal_and_install(self):
|
|
|
|
cmd = self.build_universal_and_install_command.substitute(
|
2020-08-21 09:59:40 +03:00
|
|
|
dict(
|
|
|
|
install_lib_path=self.config.install_path_lib,
|
2020-09-06 09:29:31 +03:00
|
|
|
install_include_path=self.config.install_path_include,
|
|
|
|
arm64_lib_path=self.config.target_specific_install_path(Target.arm64).joinpath(
|
|
|
|
"lib"
|
|
|
|
),
|
|
|
|
arm64_include_path=self.config.target_specific_install_path(Target.arm64).joinpath(
|
|
|
|
"include"
|
|
|
|
),
|
|
|
|
x86_64_lib_path=self.config.target_specific_install_path(Target.x86_64).joinpath(
|
|
|
|
"lib"
|
|
|
|
),
|
2020-08-21 09:59:40 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
print(cmd)
|
|
|
|
shell(cmd, cwd=self.config.working_directory)
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
self.config.clean_install_paths()
|
|
|
|
self.config.ensure_paths_exist()
|
|
|
|
|
|
|
|
self.download()
|
2020-09-06 09:29:31 +03:00
|
|
|
|
|
|
|
self.extract(Target.arm64)
|
|
|
|
self.make(Target.arm64)
|
|
|
|
|
|
|
|
self.extract(Target.x86_64)
|
|
|
|
self.make(Target.x86_64)
|
|
|
|
|
|
|
|
self.build_universal_and_install()
|