| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 | 875 |
| 876 def SaveConfig(self): | 876 def SaveConfig(self): |
| 877 gclient_utils.FileWrite(os.path.join(self.root_dir, | 877 gclient_utils.FileWrite(os.path.join(self.root_dir, |
| 878 self._options.config_filename), | 878 self._options.config_filename), |
| 879 self.config_content) | 879 self.config_content) |
| 880 | 880 |
| 881 @staticmethod | 881 @staticmethod |
| 882 def LoadCurrentConfig(options): | 882 def LoadCurrentConfig(options): |
| 883 """Searches for and loads a .gclient file relative to the current working | 883 """Searches for and loads a .gclient file relative to the current working |
| 884 dir. Returns a GClient object.""" | 884 dir. Returns a GClient object.""" |
| 885 path = gclient_utils.FindGclientRoot(os.getcwd(), options.config_filename) | 885 if options.spec: |
| 886 if not path: | 886 client = GClient('.', options) |
| 887 return None | 887 client.SetConfig(options.spec) |
| 888 client = GClient(path, options) | 888 else: |
| 889 client.SetConfig(gclient_utils.FileRead( | 889 path = gclient_utils.FindGclientRoot(os.getcwd(), options.config_filename) |
| 890 os.path.join(path, options.config_filename))) | 890 if not path: |
| 891 return None |
| 892 client = GClient(path, options) |
| 893 client.SetConfig(gclient_utils.FileRead( |
| 894 os.path.join(path, options.config_filename))) |
| 891 | 895 |
| 892 if (options.revisions and | 896 if (options.revisions and |
| 893 len(client.dependencies) > 1 and | 897 len(client.dependencies) > 1 and |
| 894 any('@' not in r for r in options.revisions)): | 898 any('@' not in r for r in options.revisions)): |
| 895 print >> sys.stderr, ( | 899 print >> sys.stderr, ( |
| 896 'You must specify the full solution name like --revision %s@%s\n' | 900 'You must specify the full solution name like --revision %s@%s\n' |
| 897 'when you have multiple solutions setup in your .gclient file.\n' | 901 'when you have multiple solutions setup in your .gclient file.\n' |
| 898 'Other solutions present are: %s.') % ( | 902 'Other solutions present are: %s.') % ( |
| 899 client.dependencies[0].name, | 903 client.dependencies[0].name, |
| 900 options.revisions[0], | 904 options.revisions[0], |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 @attr('usage', '[url] [safesync url]') | 1218 @attr('usage', '[url] [safesync url]') |
| 1215 def CMDconfig(parser, args): | 1219 def CMDconfig(parser, args): |
| 1216 """Create a .gclient file in the current directory. | 1220 """Create a .gclient file in the current directory. |
| 1217 | 1221 |
| 1218 This specifies the configuration for further commands. After update/sync, | 1222 This specifies the configuration for further commands. After update/sync, |
| 1219 top-level DEPS files in each module are read to determine dependent | 1223 top-level DEPS files in each module are read to determine dependent |
| 1220 modules to operate on as well. If optional [url] parameter is | 1224 modules to operate on as well. If optional [url] parameter is |
| 1221 provided, then configuration is read from a specified Subversion server | 1225 provided, then configuration is read from a specified Subversion server |
| 1222 URL. | 1226 URL. |
| 1223 """ | 1227 """ |
| 1224 parser.add_option('--spec', | 1228 |
| 1225 help='create a gclient file containing the provided ' | 1229 # We do a little dance with the --gclientfile option. 'gclient config' is the |
| 1226 'string. Due to Cygwin/Python brokenness, it ' | 1230 # only command where it's acceptable to have both '--gclientfile' and '--spec' |
| 1227 'probably can\'t contain any newlines.') | 1231 # arguments. So, we temporarily stash any --gclientfile parameter into |
| 1232 # options.output_config_file until after the (gclientfile xor spec) error |
| 1233 # check. |
| 1234 parser.remove_option('--gclientfile') |
| 1235 parser.add_option('--gclientfile', dest='output_config_file', |
| 1236 help='Specify an alternate .gclient file') |
| 1228 parser.add_option('--name', | 1237 parser.add_option('--name', |
| 1229 help='overrides the default name for the solution') | 1238 help='overrides the default name for the solution') |
| 1230 parser.add_option('--deps-file', default='DEPS', | 1239 parser.add_option('--deps-file', default='DEPS', |
| 1231 help='overrides the default name for the DEPS file for the' | 1240 help='overrides the default name for the DEPS file for the' |
| 1232 'main solutions and all sub-dependencies') | 1241 'main solutions and all sub-dependencies') |
| 1233 parser.add_option('--unmanaged', action='store_true', default=False, | 1242 parser.add_option('--unmanaged', action='store_true', default=False, |
| 1234 help='overrides the default behavior to make it possible ' | 1243 help='overrides the default behavior to make it possible ' |
| 1235 'to have the main solution untouched by gclient ' | 1244 'to have the main solution untouched by gclient ' |
| 1236 '(gclient will check out unmanaged dependencies but ' | 1245 '(gclient will check out unmanaged dependencies but ' |
| 1237 'will never sync them)') | 1246 'will never sync them)') |
| 1238 parser.add_option('--git-deps', action='store_true', | 1247 parser.add_option('--git-deps', action='store_true', |
| 1239 help='sets the deps file to ".DEPS.git" instead of "DEPS"') | 1248 help='sets the deps file to ".DEPS.git" instead of "DEPS"') |
| 1249 parser.set_defaults(config_filename=None) |
| 1240 (options, args) = parser.parse_args(args) | 1250 (options, args) = parser.parse_args(args) |
| 1251 if options.output_config_file: |
| 1252 setattr(options, 'config_filename', getattr(options, 'output_config_file')) |
| 1241 if ((options.spec and args) or len(args) > 2 or | 1253 if ((options.spec and args) or len(args) > 2 or |
| 1242 (not options.spec and not args)): | 1254 (not options.spec and not args)): |
| 1243 parser.error('Inconsistent arguments. Use either --spec or one or 2 args') | 1255 parser.error('Inconsistent arguments. Use either --spec or one or 2 args') |
| 1244 | 1256 |
| 1245 client = GClient('.', options) | 1257 client = GClient('.', options) |
| 1246 if options.spec: | 1258 if options.spec: |
| 1247 client.SetConfig(options.spec) | 1259 client.SetConfig(options.spec) |
| 1248 else: | 1260 else: |
| 1249 base_url = args[0].rstrip('/') | 1261 base_url = args[0].rstrip('/') |
| 1250 if not options.name: | 1262 if not options.name: |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 | 1525 |
| 1514 | 1526 |
| 1515 def Parser(): | 1527 def Parser(): |
| 1516 """Returns the default parser.""" | 1528 """Returns the default parser.""" |
| 1517 parser = optparse.OptionParser(version='%prog ' + __version__) | 1529 parser = optparse.OptionParser(version='%prog ' + __version__) |
| 1518 # some arm boards have issues with parallel sync. | 1530 # some arm boards have issues with parallel sync. |
| 1519 if platform.machine().startswith('arm'): | 1531 if platform.machine().startswith('arm'): |
| 1520 jobs = 1 | 1532 jobs = 1 |
| 1521 else: | 1533 else: |
| 1522 jobs = 8 | 1534 jobs = 8 |
| 1535 gclientfile_default = os.environ.get('GCLIENT_FILE', '.gclient') |
| 1523 parser.add_option('-j', '--jobs', default=jobs, type='int', | 1536 parser.add_option('-j', '--jobs', default=jobs, type='int', |
| 1524 help='Specify how many SCM commands can run in parallel; ' | 1537 help='Specify how many SCM commands can run in parallel; ' |
| 1525 'default=%default') | 1538 'default=%default') |
| 1526 parser.add_option('-v', '--verbose', action='count', default=0, | 1539 parser.add_option('-v', '--verbose', action='count', default=0, |
| 1527 help='Produces additional output for diagnostics. Can be ' | 1540 help='Produces additional output for diagnostics. Can be ' |
| 1528 'used up to three times for more logging info.') | 1541 'used up to three times for more logging info.') |
| 1529 parser.add_option('--gclientfile', dest='config_filename', | 1542 parser.add_option('--gclientfile', dest='config_filename', |
| 1530 default=os.environ.get('GCLIENT_FILE', '.gclient'), | 1543 default=None, |
| 1531 help='Specify an alternate %default file') | 1544 help='Specify an alternate %s file' % gclientfile_default) |
| 1545 parser.add_option('--spec', |
| 1546 default=None, |
| 1547 help='create a gclient file containing the provided ' |
| 1548 'string. Due to Cygwin/Python brokenness, it ' |
| 1549 'probably can\'t contain any newlines.') |
| 1532 # Integrate standard options processing. | 1550 # Integrate standard options processing. |
| 1533 old_parser = parser.parse_args | 1551 old_parser = parser.parse_args |
| 1534 def Parse(args): | 1552 def Parse(args): |
| 1535 (options, args) = old_parser(args) | 1553 (options, args) = old_parser(args) |
| 1536 level = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 1554 level = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ |
| 1537 min(options.verbose, 3)] | 1555 min(options.verbose, 3)] |
| 1538 logging.basicConfig(level=level, | 1556 logging.basicConfig(level=level, |
| 1539 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') | 1557 format='%(module)s(%(lineno)d) %(funcName)s:%(message)s') |
| 1558 if options.config_filename and options.spec: |
| 1559 parser.error('Cannot specifiy both --gclientfile and --spec') |
| 1560 if not options.config_filename: |
| 1561 options.config_filename = gclientfile_default |
| 1540 options.entries_filename = options.config_filename + '_entries' | 1562 options.entries_filename = options.config_filename + '_entries' |
| 1541 if options.jobs < 1: | 1563 if options.jobs < 1: |
| 1542 parser.error('--jobs must be 1 or higher') | 1564 parser.error('--jobs must be 1 or higher') |
| 1543 | 1565 |
| 1544 # These hacks need to die. | 1566 # These hacks need to die. |
| 1545 if not hasattr(options, 'revisions'): | 1567 if not hasattr(options, 'revisions'): |
| 1546 # GClient.RunOnDeps expects it even if not applicable. | 1568 # GClient.RunOnDeps expects it even if not applicable. |
| 1547 options.revisions = [] | 1569 options.revisions = [] |
| 1548 if not hasattr(options, 'head'): | 1570 if not hasattr(options, 'head'): |
| 1549 options.head = None | 1571 options.head = None |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1623 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 1602 print >> sys.stderr, 'Error: %s' % str(e) | 1624 print >> sys.stderr, 'Error: %s' % str(e) |
| 1603 return 1 | 1625 return 1 |
| 1604 | 1626 |
| 1605 | 1627 |
| 1606 if '__main__' == __name__: | 1628 if '__main__' == __name__: |
| 1607 fix_encoding.fix_encoding() | 1629 fix_encoding.fix_encoding() |
| 1608 sys.exit(Main(sys.argv[1:])) | 1630 sys.exit(Main(sys.argv[1:])) |
| 1609 | 1631 |
| 1610 # vim: ts=2:sw=2:tw=80:et: | 1632 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |