blob: 3a94ef90e8c6f7be6946ebe7c3cfad6a7fb0d8a4 [file] [log] [blame]
Primiano Tuccif7647392019-10-04 00:42:11 +01001#!/usr/bin/env python
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from __future__ import print_function
17import argparse
18import sys
19import shutil
20import subprocess
21import os
22
23REPO_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
24sys.path.append(os.path.join(REPO_ROOT, 'infra', 'ci'))
25from config import JOB_CONFIGS, SANDBOX_IMG
26
27
28def main():
29 parser = argparse.ArgumentParser()
30 parser.add_argument('config', choices=JOB_CONFIGS.keys())
31 args = parser.parse_args()
32
33 # Check that the directory is clean.
34 git_cmd = ['git', '-C', REPO_ROOT, 'status', '--porcelain']
35 modified_files = subprocess.check_output(git_cmd)
36 if modified_files:
37 print('The current Git repo has modified/untracked files.')
38 print('The sandboxed VM will fetch the HEAD of your current git repo.')
39 print('This is probably not the state you want to be in.')
40 print('I suggest you press CTRL+C, commit and then re-run this script')
41 print('Modified files:\n' + modified_files)
42 raw_input('If you think you know what you are doing, press Enter instead')
43
44 env = {
45 'PERFETTO_TEST_GIT_REF': 'file:///ci/source',
46 }
47 env.update(JOB_CONFIGS[args.config])
48
49 workdir = os.path.join(REPO_ROOT, 'out', 'tmp.ci')
50 cmd = [
51 'sudo', '--', 'docker', 'run', '-it', '--name', 'perfetto_ci',
52 '--cap-add', 'SYS_PTRACE', '--rm', '--volume',
53 '%s:/ci/ramdisk' % workdir, '--tmpfs', '/tmp:exec',
54 '--volume=%s:/ci/source:ro' % REPO_ROOT
55 ]
56 for kv in env.items():
57 cmd += ['--env', '%s=%s' % kv]
58 cmd += [SANDBOX_IMG]
59 cmd += [
60 'bash', '-c',
61 'cd /ci/ramdisk; bash /ci/init.sh || sudo -u perfetto -EH bash -i'
62 ]
63
64 print('About to run\n', ' '.join(cmd))
65 print('')
66 print('The VM will have read-only acess to: %s, mounted as /ci/source' %
67 REPO_ROOT)
68 print('The VM workdir /ci/ramdisk will be mounted into: %s' % workdir)
69 print(
70 'The contents of %s will be deleted before starting the VM' % workdir)
71 raw_input('Press a key to continue')
72
73 shutil.rmtree(workdir, ignore_errors=True)
74 os.makedirs(workdir)
75 os.execvp(cmd[0], cmd[1:])
76
77
78if __name__ == '__main__':
79 sys.exit(main())