-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_source_packages
executable file
·189 lines (143 loc) · 5.03 KB
/
install_source_packages
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python3
#
# Install source packages to ~/opt/local.
#
# This script assumes that all source package dependencies are already
# installed.
import sys
import os
import subprocess
import filecmp
import shutil
b2 = shutil.which('b2')
if not b2:
b2 = shutil.which('bjam')
if not b2:
print('warning: Boost.Build was not found, skipping source packages that require it.')
def emulate_backtick(args):
try:
output = subprocess.check_output(args, universal_newlines=True).rstrip('\n')
except Exception:
output = ''
return output
def git_clone_update_pull_ff_only(url, directory):
"""Clone, update, and pull --ff-only the given url to the given
directory.
"""
if not os.path.exists(directory):
command = ['git', 'clone', '--recurse-submodules', url, directory]
subprocess.check_call(command)
command = ['git', '-C', directory, 'pull', '--ff-only', '--recurse-submodules', '--prune', '--all']
subprocess.check_call(command)
command = ['git', '-C', directory, 'submodule', 'init']
subprocess.check_call(command)
command = ['git', '-C', directory, 'submodule', 'update', '--init', '--recursive']
subprocess.check_call(command)
def install_tee3_c_style(basedir):
git_clone_update_pull_ff_only(
'https://github.com/tee3/tee3-c-style.git',
os.path.join(basedir, 'src', 'tee3-c-style'))
def install_msvc_c_style(basedir):
git_clone_update_pull_ff_only(
'https://github.com/tee3/msvc-c-style.git',
os.path.join(basedir, 'src', 'msvc-c-style'))
def install_b2_mode(basedir):
git_clone_update_pull_ff_only(
'https://github.com/tee3/b2-mode.git',
os.path.join(basedir, 'src', 'b2-mode'))
def install_objj_mode(basedir):
git_clone_update_pull_ff_only(
'https://github.com/tee3/objj-mode.git',
os.path.join(basedir, 'src', 'objj-mode'))
def install_git_svn_update_externals(basedir):
git_clone_update_pull_ff_only(
'https://github.com/tee3/git-svn-update-externals.git',
os.path.join(basedir, 'src', 'git-svn-update-externals'))
source = os.path.join(basedir, 'src', 'git-svn-update-externals', 'git-svn-update-externals')
target = os.path.join(basedir, 'bin', 'git-svn-update-externals')
if os.path.exists(target):
if not filecmp.cmp(target, source, False):
yn = input('%s is different than %s. Overwrite anyway? (y/n): ' % (source, target))
if yn == 'y':
os.remove(target)
if not os.path.exists(target):
if hasattr(os, 'symlink'):
os.symlink(source, target)
else:
shutil.copyfile(source, target)
def install_boost(basedir):
boostdir = os.path.join(basedir, 'src', 'boost', 'boost.git')
git_clone_update_pull_ff_only(
'https://github.com/boostorg/boost.git',
boostdir)
command = ['git', '-C', boostdir, 'clean', '-d', '-x', '-f']
subprocess.check_call(command)
if sys.platform.startswith('win32'):
command = [os.path.join(boostdir, 'bootstrap.bat')]
else:
command = [os.path.join(boostdir, 'bootstrap.sh')]
subprocess.check_call(command, cwd=boostdir)
def install_commands_to_compilation_database(basedir):
if not b2:
return
sourcedir = os.path.join(basedir, 'src', 'commands_to_compilation_database')
git_clone_update_pull_ff_only(
'https://github.com/tee3/commands_to_compilation_database.git',
sourcedir)
command = [
b2,
'install',
'--prefix=' + basedir
]
subprocess.check_call(command, cwd=sourcedir)
def install_tree_sitter(basedir):
sourcedir = os.path.join(basedir, 'src', 'tree-sitter')
major = 0
minor = 20
patch = 7
version = f'{major}.{minor}.{patch}'
if os.path.exists(sourcedir):
command = [
'git',
'checkout',
'master',
]
subprocess.check_call(command, cwd=sourcedir)
git_clone_update_pull_ff_only(
'https://github.com/tree-sitter/tree-sitter.git',
sourcedir)
command = [
'git',
'checkout',
f'v{version}',
]
subprocess.check_call(command, cwd=sourcedir)
command = [
'make',
f'VERSION={version}'
f'SONAME_MAJOR={major}',
f'SONAME_MINOR={minor}',
'install',
]
env = os.environ
env['PREFIX'] = basedir
subprocess.check_call(command, cwd=sourcedir, env=env)
# requires HOME.
if 'HOME' not in os.environ or os.environ['HOME'] == '':
print('error: HOME is not set, aborting.')
sys.exit(1)
HOME = os.environ['HOME']
# default the prefix to ~/opt/local
prefix = os.path.join(HOME, 'opt', 'local')
if __name__ == '__main__':
r = 0
# install desired source packages
install_tee3_c_style(prefix)
install_msvc_c_style(prefix)
install_b2_mode(prefix)
install_objj_mode(prefix)
install_commands_to_compilation_database(prefix)
install_git_svn_update_externals(prefix)
install_boost(prefix)
install_tree_sitter(prefix)
sys.exit(r)