blob: 5aabb2f52cce0258fa2387617636785e6d392bde [file] [log] [blame]
Aviv Keshetb1238c32013-04-01 11:42:13 -07001#!/usr/bin/python
2
3# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7
8"""
9Simple script to be run inside the chroot. Used as a fast approximation of
10emerge-$board autotest-all, by simply rsync'ing changes from trunk to sysroot.
11"""
12
13import os
14import sys
15
16from chromite.buildbot import constants
17from chromite.lib import cros_build_lib
18from chromite.lib import git
19
20import argparse
21
22INCLUDE_PATTERNS_FILENAME = 'autotest-quickmerge-includepatterns'
23AUTOTEST_PROJECT_NAME = 'chromiumos/third_party/autotest'
24
25def RsyncQuickmerge(source_path, sysroot_autotest_path,
26 include_pattern_file=None, pretend=False,
27 overwrite=False, quiet=False):
28 """Run rsync quickmerge command, with specified arguments.
29 Command will take form `rsync -a [options] --exclude=**.pyc
30 --exclude=**.pyo
31 [optional --include-from argument]
32 --exclude=* [source_path] [sysroot_autotest_path]`
33
34 Arguments:
35 pretend: True to use the '-n' option to rsync, to perform dry run.
36 overwrite: True to omit '-u' option, overwrite all files in sysroot,
37 not just older files.
38 quiet: True to omit the '-i' option, silence rsync change log.
39 """
40 command = ['rsync', '-a']
41
42 if pretend:
43 command += ['-n']
44
45 if not overwrite:
46 command += ['-u']
47
48 if not quiet:
49 command += ['-i']
50
51 command += ['--exclude=**.pyc']
52 command += ['--exclude=**.pyo']
53
54 if include_pattern_file:
55 command += ['--include-from=%s' % include_pattern_file]
56
57 command += ['--exclude=*']
58
59 command += [source_path, sysroot_autotest_path]
60
61 cros_build_lib.SudoRunCommand(command)
62
63
64def ParseArguments(argv):
65 """Parse command line arguments
66
67 Returns: parsed arguments.
68 """
69 parser = argparse.ArgumentParser(description='Perform a fast approximation '
70 'to emerge-$board autotest-all, by '
71 'rsyncing source tree to sysroot.')
72
73 parser.add_argument('--board', metavar='BOARD', default=None, required=True)
74 parser.add_argument('--pretend', action='store_true',
75 help='Dry run only, do not modify sysroot autotest.')
76 parser.add_argument('--overwrite', action='store_true',
77 help='Overwrite existing files even if newer.')
78 parser.add_argument('--quiet', action='store_true',
79 help='Suppress output of list of modified files.')
80
81 return parser.parse_args(argv)
82
83
84def main(argv):
85 cros_build_lib.AssertInsideChroot()
86
87 args = ParseArguments(argv)
88
89 if not args.board:
90 print "No board specified, and no default board. Aborting."
91 return 1
92
93 manifest = git.ManifestCheckout.Cached(constants.SOURCE_ROOT)
94 source_path = manifest.GetProjectPath(AUTOTEST_PROJECT_NAME, absolute=True)
95 source_path = os.path.join(source_path, '')
96
97 script_path = os.path.dirname(__file__)
98 include_pattern_file = os.path.join(script_path, INCLUDE_PATTERNS_FILENAME)
99
100 # TODO: Determine the following string programatically.
101 sysroot_autotest_path = os.path.join('/build', args.board, 'usr', 'local',
102 'autotest', '')
103
104 RsyncQuickmerge(source_path, sysroot_autotest_path, include_pattern_file,
105 args.pretend, args.overwrite, args.quiet)
106
107 print 'Done'
108
109
110if __name__ == '__main__':
111 sys.exit(main(sys.argv))