-
-
Notifications
You must be signed in to change notification settings - Fork 616
/
Copy pathbuild-gem5
executable file
·165 lines (154 loc) · 6.81 KB
/
build-gem5
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
#!/usr/bin/env python3
import os
import pathlib
import subprocess
import tempfile
import common
from shell_helpers import LF
class Main(common.BuildCliFunction):
def __init__(self):
super().__init__(
description='''\
Build gem5.
https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-buildroot-setup
'''
)
self.add_argument(
'--unit-test',
action='append',
default=[],
help='''\
Build and run the given unit test. Paths are relative to src/ without the .opt suffix.
If given multiple times, runs multiple unit tests. Ignore --unit-tests.
https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-tests
'''
)
self.add_argument(
'--unit-tests',
default=False,
help='''\
Build and run all the gem5 unit tests instead of the gem5 executable.
https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-tests
'''
)
self._add_argument('--ldflags')
self._add_argument('extra_make_args')
self.eclipse_tmpdir = None
def build(self):
build_dir = self.get_build_dir()
binaries_dir = self.env['gem5_system_binaries_dir']
disks_dir = os.path.join(self.env['gem5_system_dir'], 'disks')
os.makedirs(binaries_dir, exist_ok=True)
os.makedirs(disks_dir, exist_ok=True)
if not os.path.exists(os.path.join(self.env['gem5_source_dir'], '.git')):
if self.env['_args_given']['gem5_worktree']:
self.sh.run_cmd([
'git', LF,
'-C', self.env['gem5_default_source_dir'], LF,
'worktree', 'add', LF,
'-b', os.path.join('wt', self.env['gem5_worktree']), LF,
self.env['gem5_source_dir'], LF,
])
else:
if not self.env['dry_run']:
raise Exception('gem5 submodule not checked out')
if self.env['verbose']:
verbose = ['--verbose', LF]
else:
verbose = []
if self.env['is_arm']:
gem5_system_source_dir = os.path.join(self.env['gem5_source_dir'], 'system')
# dtb
dt_source_dir = os.path.join(gem5_system_source_dir, 'arm', 'dt')
dt_build_dir = os.path.join(self.env['gem5_system_dir'], 'arm', 'dt')
self.sh.run_cmd(['make', '-C', dt_source_dir, LF])
self.sh.copy_dir_if_update_non_recursive(
srcdir=dt_source_dir,
destdir=dt_build_dir,
filter_ext='.dtb',
)
# Bootloader 32.
arm_bootloader_dir = os.path.join(gem5_system_source_dir, 'arm', 'bootloader')
bootloader32_dir = os.path.join(arm_bootloader_dir, 'arm')
# TODO use the buildroot cross compiler here, and remove the dependencies from configure.
self.sh.run_cmd([
'make', LF,
'-C', bootloader32_dir, LF,
'CROSS_COMPILE=arm-linux-gnueabihf-', LF,
])
# bootloader
self.sh.cp(os.path.join(bootloader32_dir, 'boot.arm'), binaries_dir)
# Bootloader 64.
bootloader64_dir = os.path.join(arm_bootloader_dir, 'arm64')
# TODO cross_compile is ignored because the make does not use CC...
self.sh.run_cmd(['make', '-C', bootloader64_dir, LF])
self.sh.cp(os.path.join(bootloader64_dir, 'boot.arm64'), binaries_dir)
self.sh.cp(os.path.join(bootloader64_dir, 'boot_v2.arm64'), binaries_dir)
term_source_dir = os.path.join(self.env['gem5_source_dir'], 'util/term')
m5term_build = os.path.join(term_source_dir, 'm5term')
self.sh.run_cmd(['make', '-C', term_source_dir, LF])
if os.path.exists(self.env['gem5_m5term']):
# Otherwise self.sh.cp would fail with "Text file busy" if you
# tried to rebuild while running m5term:
# https://stackoverflow.com/questions/16764946/what-generates-the-text-file-busy-message-in-unix/52427512#52427512
self.sh.rmrf(self.env['gem5_m5term'])
self.sh.cp(m5term_build, self.env['gem5_m5term'])
if self.env['unit_test']:
targets = [self.get_gem5_target_path(self.env, test) for test in self.env['unit_test']]
elif self.env['unit_tests']:
targets = [self.env['gem5_unit_test_target']]
else:
targets = [self.env['gem5_executable']]
if self.env['gem5_clang']:
extra_env = {
'CC': 'clang',
'CXX': 'clang++',
}
else:
extra_env = {}
# https://cirosantilli.com/cirodown#benchmark-gem5-single-file-change-rebuild-time
ldflags_extra = ['-fuse-ld=lld'] + self.env['ldflags']
kwargs = {}
if self.env['ccache']:
kwargs['extra_paths'] = [self.env['ccache_dir']]
exit_status = self.sh.run_cmd(
(
[
'scons', LF,
'-j', str(self.env['nproc']), LF,
'--ignore-style', LF,
'LDFLAGS_EXTRA={}'.format(self.sh.cmd_to_string(ldflags_extra, force_oneline=True)), LF,
'USE_HDF5=1', LF,
] +
verbose +
[
# TODO reenable, broken, had enough of this.
# https://gem5.atlassian.net/browse/GEM5-357
# https://gem5.atlassian.net/browse/GEM5-656
# https://gem5.atlassian.net/browse/GEM5-778
#'SLICC_HTML=True', LF,
] +
self.sh.add_newlines(targets) +
self.sh.add_newlines(self.env['extra_make_args'])
),
cwd=self.env['gem5_source_dir'],
extra_env=extra_env,
raise_on_failure = False,
**kwargs
)
return exit_status
def clean_pre(self, builddir):
if os.path.exists(self.env['gem5_eclipse_cproject_path']):
self.eclipse_tmpdir = tempfile.mkdtemp()
self.sh.mv(self.env['gem5_eclipse_cproject_path'], self.eclipse_tmpdir)
self.sh.mv(self.env['gem5_eclipse_project_path'], self.eclipse_tmpdir)
def clean_post(self, builddir):
if self.eclipse_tmpdir is not None:
self.sh.mkdir_p(self.env['gem5_build_build_dir'])
self.sh.mv(os.path.join(self.eclipse_tmpdir, self.env['gem5_eclipse_cproject_basename']), self.env['gem5_build_build_dir'])
self.sh.mv(os.path.join(self.eclipse_tmpdir, self.env['gem5_eclipse_project_basename']), self.env['gem5_build_build_dir'])
self.sh.rmrf(self.eclipse_tmpdir)
def get_build_dir(self):
return self.env['gem5_build_dir']
if __name__ == '__main__':
Main().cli()