Repository navigation
Expand file tree
/
Copy pathfetch
More file actions
executable file
·171 lines (142 loc) · 5.06 KB
/
Copy pathfetch
File metadata and controls
executable file
·171 lines (142 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#! /usr/bin/env -S python3 -u
# Copyright (c) 2023, Eugene Gershnik
# SPDX-License-Identifier: GPL-3.0-or-later
# pylint: disable=wrong-import-position
import sys
if sys.version_info < (3, 11):
raise RuntimeError('Python 3.11 or greater is required to build this project')
import shutil
import subprocess
import json
from pathlib import Path
from urllib.request import urlretrieve
components = {
'objc-helpers': {
'ver': 'v3.8.0',
'url': 'https://github.com/gershnik/objc-helpers/tarball/{ver}',
'unpacker': {
'type': 'tar',
'strip': 1
},
'dir': 'objc-helpers',
'verFile': 'VERSION',
'generateVerFile': True
},
'isptr': {
'ver': 'v1.13',
'url': 'https://github.com/gershnik/intrusive_shared_ptr/tarball/{ver}',
'unpacker': {
'type': 'tar',
'strip': 1
},
'dir': 'isptr',
'verFile': 'VERSION',
'generateVerFile': True
}
}
MYDIR = Path(__file__).parent
EXTERNAL_DIR = MYDIR / 'External'
def ver_to_list(ver):
return [i for i in ver.split('.')]
def get_version_from_file(path):
existing_ver = None
if path.is_file():
existing_ver = ver_to_list(path.read_text().rstrip())
return existing_ver
def check_up_to_date(name, component):
directory = EXTERNAL_DIR / component['dir']
up_to_date = False
if component.get('verFile'):
ver_file = directory / component['verFile']
required_ver = ver_to_list(component['ver'])
existing_ver = get_version_from_file(ver_file)
if existing_ver == required_ver:
up_to_date = True
else:
print(f"Dont know how to detect version of {name}", file=sys.stderr)
sys.exit(1)
if not up_to_date:
print(f'{name} not up to date, required {required_ver}, existing {existing_ver}')
else:
print(f'{name} is up to date')
return up_to_date
def untar(name, component, archive):
directory = EXTERNAL_DIR / component.get('dir', name)
if archive.suffix in ('.tgz', '.gz'):
comp = 'z'
elif archive.suffix in ('.tbz', '.bz'):
comp = 'j'
else:
comp = ''
command = ['/usr/bin/tar', '-C', directory, f'-x{comp}f', archive]
subst = component['unpacker'].get('subst')
if subst is not None:
command += ['-s', subst]
strip = component['unpacker'].get('strip')
if strip is not None:
command += ['--strip-components', str(strip)]
subprocess.run(command, check=True)
def fetch_url(name, component, unpacker):
directory = EXTERNAL_DIR / component['dir']
shutil.rmtree(directory, ignore_errors=True)
if directory.exists():
print(f'Unable to remove {name} directory', file=sys.stderr)
sys.exit(1)
directory.mkdir()
url = component['url'].format(ver = component['ver'])
path, _ = urlretrieve(url)
try:
unpacker(name, component, Path(path))
print(f'Installed {name}')
finally:
Path(path).unlink()
generate_ver_file = component.get('generateVerFile', False)
if generate_ver_file:
ver_file = directory / component['verFile']
ver_file.write_text(component['ver'])
def get_fetcher(name, component):
if component.get('url'):
return fetch_url
print(f"Dont know how to download {name}", file=sys.stderr)
sys.exit(1)
def get_unpacker(name, component):
component_type = component['unpacker']['type']
if component_type == 'tar':
return untar
print(f"Dont know how to unpack {name}", file=sys.stderr)
sys.exit(1)
def main():
local_xcconfig = MYDIR / 'Local.xcconfig'
if not local_xcconfig.exists():
min_ver = ''
try:
sdk = subprocess.run(['xcrun', '--sdk', 'macosx', '--show-sdk-path'], stdout=subprocess.PIPE,
encoding='utf-8', check=True).stdout.strip()
with open(f'{sdk}/SDKSettings.json', 'rb') as f:
data = json.load(f)
min_ver = str(data['SupportedTargets']['macosx']['MinimumDeploymentTarget'])
except (subprocess.SubprocessError, OSError, json.JSONDecodeError, UnicodeDecodeError, KeyError):
pass
local_xcconfig.write_text(f'''\
// Local configuration settings. Do not commit to source control
//
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974
//
// To create signed and notarized installer from Xcode do this:
//TRANSLIT_SIGN_PACKAGE=true
//NOTARIZE_USER=...
//NOTARIZE_PWD=...
//CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO
// Uncomment the following to set min supported macOS version different from the default
//MACOSX_DEPLOYMENT_TARGET = {min_ver}
''')
EXTERNAL_DIR.mkdir(parents=True, exist_ok=True)
for name, component in components.items():
if check_up_to_date(name, component):
continue
fetcher = get_fetcher(name, component)
unpacker = get_unpacker(name, component)
fetcher(name, component, unpacker)
if __name__ == '__main__':
main()