-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfetch
executable file
·132 lines (111 loc) · 3.73 KB
/
fetch
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
#! /usr/bin/env -S python3 -u
# Copyright (c) 2023, Eugene Gershnik
# SPDX-License-Identifier: GPL-3.0-or-later
import sys
import shutil
import subprocess
from pathlib import Path
from urllib.request import urlretrieve
components = {
'objc-helpers': {
'ver': '3.0',
'url': 'https://github.com/gershnik/objc-helpers/releases/download/v{ver}/objc-helpers-{ver}.tar.gz',
'unpacker': {
'type': 'tar'
},
'dir': 'objc-helpers',
'verFile': 'VERSION',
'generateVerFile': True
}
}
mydir = Path(sys.argv[0]).parent
externalDir = mydir / 'External'
externalDir.mkdir(parents=True, exist_ok=True)
def verToList(ver):
return [int(i) for i in ver.split('.')]
def getVersionFromFile(path):
existingVer = None
if path.is_file():
existingVer = verToList(path.read_text().rstrip())
return existingVer
def checkUpToDate(name, component):
directory = externalDir / component['dir']
upToDate = False
if component.get('verFile'):
verFile = directory / component['verFile']
requiredVer = verToList(component['ver'])
existingVer = getVersionFromFile(verFile)
if existingVer == requiredVer:
upToDate = True
else:
print(f"Dont know how to detect version of {name}", file=sys.stderr)
sys.exit(1)
if not upToDate:
print(f'{name} not up to date, required {requiredVer}, existing {existingVer}')
else:
print(f'{name} is up to date')
return upToDate
def untar(name, component, archive):
directory = externalDir / component['dir']
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 not subst is None:
command += ['-s', subst]
subprocess.run(command, check=True)
def fetchUrl(name, component, unpacker):
directory = externalDir / 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, headers = urlretrieve(url)
try:
unpacker(name, component, Path(path))
print(f'Installed {name}')
finally:
Path(path).unlink()
generateVerFile = component.get('generateVerFile', False)
if generateVerFile:
verFile = directory / component['verFile']
verFile.write_text(component['ver'])
def getFetcher(name, component):
if component.get('url'):
return fetchUrl
else:
print(f"Dont know how to download {name}", file=sys.stderr)
sys.exit(1)
def getUnpacker(name, component):
type = component['unpacker']['type']
if type == 'tar':
return untar
else:
print(f"Dont know how to unpack {name}", file=sys.stderr)
sys.exit(1)
localXcconfig = mydir / 'Local.xcconfig'
if not localXcconfig.exists():
localXcconfig.write_text('''
// 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
'''.lstrip())
for name, component in components.items():
if checkUpToDate(name, component):
continue
fetcher = getFetcher(name, component)
unpacker = getUnpacker(name, component)
fetcher(name, component, unpacker)