blob: e569b98b93bf74f740cc8671d95f2a3077906cb1 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import argparse
import sys
import shutil
import subprocess
import os
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.join(REPO_ROOT, 'infra', 'ci'))
from config import JOB_CONFIGS, SANDBOX_IMG
def main():
parser = argparse.ArgumentParser()
parser.add_argument('config', choices=JOB_CONFIGS.keys())
args = parser.parse_args()
# Check that the directory is clean.
git_cmd = ['git', '-C', REPO_ROOT, 'status', '--porcelain']
modified_files = subprocess.check_output(git_cmd)
if modified_files:
print('The current Git repo has modified/untracked files.')
print('The sandboxed VM will fetch the HEAD of your current git repo.')
print('This is probably not the state you want to be in.')
print('I suggest you press CTRL+C, commit and then re-run this script')
print('Modified files:\n' + modified_files)
raw_input('If you think you know what you are doing, press Enter instead')
env = {
'PERFETTO_TEST_GIT_REF': 'file:///ci/source',
}
env.update(JOB_CONFIGS[args.config])
workdir = os.path.join(REPO_ROOT, 'out', 'tmp.ci')
cmd = [
'sudo', '--', 'docker', 'run', '-it', '--name', 'perfetto_ci',
'--cap-add', 'SYS_PTRACE', '--rm', '--volume',
'%s:/ci/ramdisk' % workdir, '--tmpfs', '/tmp:exec',
'--volume=%s:/ci/source:ro' % REPO_ROOT
]
for kv in env.items():
cmd += ['--env', '%s=%s' % kv]
cmd += [SANDBOX_IMG]
cmd += [
'bash', '-c',
'cd /ci/ramdisk; bash /ci/init.sh || sudo -u perfetto -EH bash -i'
]
print('About to run\n', ' '.join(cmd))
print('')
print('The VM will have read-only acess to: %s, mounted as /ci/source' %
REPO_ROOT)
print('The VM workdir /ci/ramdisk will be mounted into: %s' % workdir)
print('The contents of %s will be deleted before starting the VM' % workdir)
raw_input('Press a key to continue')
shutil.rmtree(workdir, ignore_errors=True)
os.makedirs(workdir)
os.execvp(cmd[0], cmd[1:])
if __name__ == '__main__':
sys.exit(main())