2021-01-14 08:34:20 +00:00
|
|
|
#
|
|
|
|
# Helper module to build macOS version of various source ports
|
2023-01-01 08:46:34 +00:00
|
|
|
# Copyright (C) 2020-2023 Alexey Lysiuk
|
2021-01-14 08:34:20 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2021-01-16 13:23:14 +00:00
|
|
|
import shlex
|
2021-06-27 12:24:47 +00:00
|
|
|
import shutil
|
2021-01-14 08:34:20 +00:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from ..state import BuildState
|
2023-03-21 10:52:54 +00:00
|
|
|
from . import base
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
|
2023-03-21 10:52:54 +00:00
|
|
|
class BuildPrefix(base.Target):
|
2022-07-20 08:05:43 +00:00
|
|
|
def __init__(self, name='build-prefix'):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
|
2023-03-21 10:52:54 +00:00
|
|
|
class CleanTarget(base.Target):
|
2021-01-14 08:34:20 +00:00
|
|
|
def __init__(self, name=None):
|
|
|
|
super().__init__(name)
|
|
|
|
self.args = ()
|
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
2021-01-17 10:27:52 +00:00
|
|
|
assert not state.xcode
|
|
|
|
|
2021-01-14 08:34:20 +00:00
|
|
|
args = ('git', 'clean') + self.args
|
2022-08-21 08:58:00 +00:00
|
|
|
subprocess.run(args, check=True, cwd=state.root_path, env=state.environment)
|
2021-01-14 08:34:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CleanAllTarget(CleanTarget):
|
|
|
|
def __init__(self, name='clean-all'):
|
|
|
|
super().__init__(name)
|
|
|
|
self.args = ('-dX', '--force')
|
|
|
|
|
|
|
|
|
|
|
|
class CleanDepsTarget(CleanAllTarget):
|
|
|
|
def __init__(self, name='clean-deps'):
|
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
def configure(self, state: BuildState):
|
|
|
|
self.args += (state.deps_path,)
|
2021-01-16 13:23:14 +00:00
|
|
|
|
|
|
|
|
2023-03-21 10:52:54 +00:00
|
|
|
class DownloadCMakeTarget(base.Target):
|
2021-07-25 09:39:48 +00:00
|
|
|
def __init__(self, name='download-cmake'):
|
2021-06-27 12:24:47 +00:00
|
|
|
super().__init__(name)
|
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
2021-07-31 08:00:23 +00:00
|
|
|
cmake_version = '3.21.1'
|
2021-07-25 09:52:47 +00:00
|
|
|
cmake_basename = f'cmake-{cmake_version}-macos10.10-universal'
|
|
|
|
cmake_url = f'https://github.com/Kitware/CMake/releases/download/v{cmake_version}/{cmake_basename}.tar.gz'
|
2021-07-31 08:00:23 +00:00
|
|
|
state.download_source(cmake_url, '20dbede1d80c1ac80be2966172f8838c3d899951ac4467372f806b386d42ad3c')
|
2021-06-27 12:24:47 +00:00
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
target_path = state.deps_path / 'cmake'
|
|
|
|
if target_path.exists():
|
2021-06-27 12:24:47 +00:00
|
|
|
shutil.rmtree(target_path)
|
2021-07-22 06:51:13 +00:00
|
|
|
target_path.mkdir()
|
2021-06-27 12:24:47 +00:00
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
source_path = state.source / 'CMake.app' / 'Contents'
|
|
|
|
shutil.move(str(source_path / 'bin'), target_path)
|
|
|
|
shutil.move(str(source_path / 'share'), target_path)
|
2021-06-27 12:24:47 +00:00
|
|
|
shutil.rmtree(state.source)
|
|
|
|
|
|
|
|
|
2023-03-21 10:52:54 +00:00
|
|
|
class TestDepsTarget(base.BuildTarget):
|
2021-01-16 13:23:14 +00:00
|
|
|
def __init__(self, name='test-deps'):
|
|
|
|
super().__init__(name)
|
|
|
|
self.multi_platform = False
|
|
|
|
|
|
|
|
def build(self, state: BuildState):
|
2021-01-17 10:27:52 +00:00
|
|
|
assert not state.xcode
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
test_path = state.root_path / 'test'
|
2021-01-16 13:23:14 +00:00
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
for entry in test_path.iterdir():
|
2021-01-16 13:23:14 +00:00
|
|
|
if not entry.name.endswith('.cpp'):
|
|
|
|
continue
|
|
|
|
|
2021-07-22 06:51:13 +00:00
|
|
|
test_name = entry.stem
|
2021-01-16 13:23:14 +00:00
|
|
|
pkg_config_output = state.run_pkg_config('--cflags', '--libs', test_name)
|
2022-09-18 07:14:53 +00:00
|
|
|
exe_path = state.build_path / test_name
|
2021-01-16 13:23:14 +00:00
|
|
|
|
2021-05-17 07:21:11 +00:00
|
|
|
print('Testing ' + test_name)
|
|
|
|
|
2022-09-18 07:14:53 +00:00
|
|
|
build_args = [
|
2022-09-11 12:48:48 +00:00
|
|
|
'clang++',
|
2021-01-16 13:23:14 +00:00
|
|
|
'-arch', 'x86_64',
|
|
|
|
'-arch', 'arm64',
|
2021-05-16 07:05:11 +00:00
|
|
|
'-std=c++17',
|
2021-07-22 06:51:13 +00:00
|
|
|
'-include', test_path / 'aedi.h',
|
2022-09-19 07:35:29 +00:00
|
|
|
'-g',
|
2022-09-18 07:14:53 +00:00
|
|
|
'-o', exe_path,
|
2021-07-22 06:51:13 +00:00
|
|
|
entry,
|
2021-01-16 13:23:14 +00:00
|
|
|
]
|
2022-09-18 07:14:53 +00:00
|
|
|
build_args += shlex.split(pkg_config_output)
|
2022-09-03 07:35:19 +00:00
|
|
|
|
|
|
|
if state.verbose:
|
2022-09-18 07:14:53 +00:00
|
|
|
print(' '.join(str(arg) for arg in build_args))
|
2022-09-03 07:35:19 +00:00
|
|
|
|
2022-09-18 07:14:53 +00:00
|
|
|
for args in (build_args, (exe_path,)):
|
|
|
|
subprocess.run(args, check=True, cwd=state.build_path, env=state.environment)
|