forked from irods/irods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirods_consortium_continuous_integration_build_hook.py
185 lines (161 loc) · 8.94 KB
/
irods_consortium_continuous_integration_build_hook.py
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
from __future__ import print_function
import glob
import itertools
import logging
import multiprocessing
import optparse
import os
import sys
import tempfile
import time
import irods_python_ci_utilities
def build(icommands_git_repository, icommands_git_commitish, debug_build, output_root_directory, externals_directory):
install_building_dependencies(externals_directory)
irods_build_dir = build_irods(debug_build)
install_irods_dev_and_runtime(irods_build_dir)
icommands_build_dir = build_icommands(icommands_git_repository, icommands_git_commitish, debug_build)
if output_root_directory:
copy_output_packages(irods_build_dir, icommands_build_dir, output_root_directory)
def install_building_dependencies(externals_directory):
externals_list = [
'irods-externals-cmake3.21.4-0',
'irods-externals-avro1.11.0-0',
'irods-externals-boost1.77.0-1',
'irods-externals-catch22.13.7-1',
'irods-externals-clang-runtime13.0.0-0',
'irods-externals-clang13.0.0-0',
'irods-externals-cppzmq4.8.1-1',
'irods-externals-fmt8.0.1-0',
'irods-externals-json3.10.4-0',
'irods-externals-libarchive3.5.2-1',
'irods-externals-nanodbc2.13.0-1',
'irods-externals-spdlog1.9.2-1',
'irods-externals-zeromq4-14.1.8-0'
]
if externals_directory is None or externals_directory == 'None':
irods_python_ci_utilities.install_irods_core_dev_repository()
irods_python_ci_utilities.install_os_packages(externals_list)
else:
package_suffix = irods_python_ci_utilities.get_package_suffix()
os_specific_directory = irods_python_ci_utilities.append_os_specific_directory(externals_directory)
externals = []
for irods_externals in externals_list:
externals.append(glob.glob(os.path.join(os_specific_directory, irods_externals + '*.{0}'.format(package_suffix)))[0])
irods_python_ci_utilities.install_os_packages_from_files(externals)
add_cmake_to_front_of_path()
install_os_specific_dependencies()
def add_cmake_to_front_of_path():
cmake_path = '/opt/irods-externals/cmake3.21.4-0/bin'
os.environ['PATH'] = os.pathsep.join([cmake_path, os.environ['PATH']])
def install_os_specific_dependencies():
dispatch_map = {
'Ubuntu': install_os_specific_dependencies_apt,
'Centos': install_os_specific_dependencies_yum,
'Centos linux': install_os_specific_dependencies_yum,
}
try:
return dispatch_map[irods_python_ci_utilities.get_distribution()]()
except KeyError:
irods_python_ci_utilities.raise_not_implemented_for_distribution()
def install_os_specific_dependencies_apt():
if irods_python_ci_utilities.get_distribution() == 'Ubuntu': # cmake from externals requires newer libstdc++ on ub12
if irods_python_ci_utilities.get_distribution_version_major() == '12':
irods_python_ci_utilities.install_os_packages(['python-software-properties'])
irods_python_ci_utilities.subprocess_get_output(['sudo', 'add-apt-repository', '-y', 'ppa:ubuntu-toolchain-r/test'], check_rc=True)
irods_python_ci_utilities.install_os_packages(['libstdc++6'])
irods_python_ci_utilities.install_os_packages([
'fakeroot', 'help2man', 'libbz2-dev', 'libcurl4-gnutls-dev', 'libkrb5-dev', 'libpam0g-dev',
'libssl-dev', 'make', 'python-dev', 'unixodbc', 'unixodbc-dev', 'zlib1g-dev',
])
def install_os_specific_dependencies_yum():
packages_to_install = [
'bzip2-devel', 'curl-devel', 'fakeroot', 'help2man', 'openssl-devel',
'pam-devel', 'python-devel', 'unixODBC', 'unixODBC-devel', 'zlib-devel', # TODO python3-devel for AlmaLinux 8 (maybe Rocky Linux 8 too).
]
if irods_python_ci_utilities.get_distribution_version_major() == '7':
packages_to_install.append('mysql++-devel')
irods_python_ci_utilities.install_os_packages(packages_to_install)
def build_irods(debug_build):
irods_source_dir = os.path.dirname(os.path.realpath(__file__))
irods_build_dir = tempfile.mkdtemp(prefix='irods_build_dir')
logging.getLogger(__name__).info('Using iRODS build directory: %s', irods_build_dir)
if debug_build:
cmake_build_type = 'Debug'
else:
cmake_build_type = 'Release'
irods_python_ci_utilities.subprocess_get_output('cmake -DCMAKE_BUILD_TYPE={0} -DIRODS_UNIT_TESTS_BUILD=YES {1} > cmake.output'.format(cmake_build_type, irods_source_dir), shell=True, cwd=irods_build_dir, check_rc=True)
irods_python_ci_utilities.subprocess_get_output('make -j{0} > make.output'.format(str(multiprocessing.cpu_count())), shell=True, cwd=irods_build_dir, check_rc=True)
irods_python_ci_utilities.subprocess_get_output('fakeroot make package >> make.output', shell=True, cwd=irods_build_dir, check_rc=True)
return irods_build_dir
def install_irods_dev_and_runtime(irods_build_dir):
irods_python_ci_utilities.install_os_packages_from_files(
itertools.chain(
glob.glob(os.path.join(irods_build_dir, 'irods-runtime*.{0}'.format(irods_python_ci_utilities.get_package_suffix()))),
glob.glob(os.path.join(irods_build_dir, 'irods-dev*.{0}'.format(irods_python_ci_utilities.get_package_suffix())))))
def build_icommands(icommands_git_repository, icommands_git_commitish, debug_build):
icommands_source_dir = irods_python_ci_utilities.git_clone(icommands_git_repository, icommands_git_commitish)
logging.getLogger(__name__).info('Using icommands source directory: %s', icommands_source_dir)
icommands_build_dir = tempfile.mkdtemp(prefix='icommands_build_dir')
logging.getLogger(__name__).info('Using icommands build directory: %s', icommands_build_dir)
if debug_build:
cmake_build_type = 'Debug'
else:
cmake_build_type = 'Release'
irods_python_ci_utilities.subprocess_get_output('cmake {0} -DCMAKE_BUILD_TYPE={1} > cmake.output'.format(icommands_source_dir, cmake_build_type), shell=True, cwd=icommands_build_dir, check_rc=True)
irods_python_ci_utilities.subprocess_get_output('make -j{0} > make.output'.format(str(multiprocessing.cpu_count())), shell=True, cwd=icommands_build_dir, check_rc=True)
irods_python_ci_utilities.subprocess_get_output('fakeroot make package >> make.output', shell=True, cwd=icommands_build_dir, check_rc=True)
return icommands_build_dir
def copy_output_packages(irods_build_dir, icommands_build_dir, output_root_directory):
# Packages
irods_python_ci_utilities.gather_files_satisfying_predicate(
irods_build_dir,
irods_python_ci_utilities.append_os_specific_directory(output_root_directory),
lambda s: s.endswith(irods_python_ci_utilities.get_package_suffix()))
# Unit-test binaries
irods_python_ci_utilities.gather_files_satisfying_predicate(
os.path.join(irods_build_dir, 'unit_tests'),
irods_python_ci_utilities.append_os_specific_directory(output_root_directory),
lambda s: os.path.basename(s).startswith('irods_'))
# iCommands
irods_python_ci_utilities.gather_files_satisfying_predicate(
icommands_build_dir,
irods_python_ci_utilities.append_os_specific_directory(output_root_directory),
lambda s: s.endswith(irods_python_ci_utilities.get_package_suffix()))
def register_log_handler():
logging.getLogger().setLevel(logging.INFO)
logging_handler = logging.StreamHandler(sys.stdout)
logging_handler.setFormatter(logging.Formatter(
'%(asctime)s - %(levelname)7s - %(filename)30s:%(lineno)4d - %(message)s',
'%Y-%m-%dT%H:%M:%SZ'))
logging_handler.formatter.converter = time.gmtime
logging_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(logging_handler)
def main():
parser = optparse.OptionParser()
parser.add_option('--debug_build', default='false')
parser.add_option('--icommands_git_commitish')
parser.add_option('--icommands_git_repository')
parser.add_option('--externals_packages_directory')
parser.add_option('--output_root_directory')
parser.add_option('--just_install_dependencies', action='store_true', default=False)
parser.add_option('--verbose', action='store_true', default=False)
options, _ = parser.parse_args()
if options.verbose:
register_log_handler()
if options.just_install_dependencies:
install_building_dependencies(options.externals_packages_directory)
return
if options.debug_build not in ['false', 'true']:
print('--debug_build must be either "false" or "true"', file=sys.stderr)
sys.exit(1)
if not options.icommands_git_repository:
print('--icommands_git_repository must be provided', file=sys.stderr)
sys.exit(1)
if not options.icommands_git_commitish:
print('--icommands_git_commitish must be provided', file=sys.stderr)
sys.exit(1)
build(
options.icommands_git_repository, options.icommands_git_commitish,
options.debug_build == 'true', options.output_root_directory, options.externals_packages_directory)
if __name__ == '__main__':
main()