OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2008 Google Inc. All Rights Reserved. | 3 # Copyright 2008 Google Inc. All Rights Reserved. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with the License. | 6 # you may not use this file except in compliance with the License. |
7 # You may obtain a copy of the License at | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 the .gclient file doesn't exist. | 963 the .gclient file doesn't exist. |
964 """ | 964 """ |
965 if not from_dir: | 965 if not from_dir: |
966 from_dir = os.curdir | 966 from_dir = os.curdir |
967 path = os.path.realpath(from_dir) | 967 path = os.path.realpath(from_dir) |
968 while not os.path.exists(os.path.join(path, options.config_filename)): | 968 while not os.path.exists(os.path.join(path, options.config_filename)): |
969 next = os.path.split(path) | 969 next = os.path.split(path) |
970 if not next[1]: | 970 if not next[1]: |
971 return None | 971 return None |
972 path = next[0] | 972 path = next[0] |
973 client = options.gclient(path, options) | 973 client = GClient(path, options) |
974 client._LoadConfig() | 974 client._LoadConfig() |
975 return client | 975 return client |
976 | 976 |
977 def SetDefaultConfig(self, solution_name, solution_url, safesync_url): | 977 def SetDefaultConfig(self, solution_name, solution_url, safesync_url): |
978 self.SetConfig(DEFAULT_CLIENT_FILE_TEXT % ( | 978 self.SetConfig(DEFAULT_CLIENT_FILE_TEXT % ( |
979 solution_name, solution_url, safesync_url | 979 solution_name, solution_url, safesync_url |
980 )) | 980 )) |
981 | 981 |
982 def _SaveEntries(self, entries): | 982 def _SaveEntries(self, entries): |
983 """Creates a .gclient_entries file to record the list of unique checkouts. | 983 """Creates a .gclient_entries file to record the list of unique checkouts. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 else: | 1161 else: |
1162 parsed_url = urlparse.urlparse(url) | 1162 parsed_url = urlparse.urlparse(url) |
1163 scheme = parsed_url[0] | 1163 scheme = parsed_url[0] |
1164 if not scheme: | 1164 if not scheme: |
1165 # A relative url. Fetch the real base. | 1165 # A relative url. Fetch the real base. |
1166 path = parsed_url[2] | 1166 path = parsed_url[2] |
1167 if path[0] != "/": | 1167 if path[0] != "/": |
1168 raise Error( | 1168 raise Error( |
1169 "relative DEPS entry \"%s\" must begin with a slash" % d) | 1169 "relative DEPS entry \"%s\" must begin with a slash" % d) |
1170 # Create a scm just to query the full url. | 1170 # Create a scm just to query the full url. |
1171 scm = self._options.scm_wrapper(solution["url"], self._root_dir, | 1171 scm = SCMWrapper(solution["url"], self._root_dir, None) |
1172 None) | |
1173 url = scm.FullUrlForRelativeUrl(url) | 1172 url = scm.FullUrlForRelativeUrl(url) |
1174 if d in deps and deps[d] != url: | 1173 if d in deps and deps[d] != url: |
1175 raise Error( | 1174 raise Error( |
1176 "Solutions have conflicting versions of dependency \"%s\"" % d) | 1175 "Solutions have conflicting versions of dependency \"%s\"" % d) |
1177 if d in solution_urls and solution_urls[d] != url: | 1176 if d in solution_urls and solution_urls[d] != url: |
1178 raise Error( | 1177 raise Error( |
1179 "Dependency \"%s\" conflicts with specified solution" % d) | 1178 "Dependency \"%s\" conflicts with specified solution" % d) |
1180 # Grab the dependency. | 1179 # Grab the dependency. |
1181 deps[d] = url | 1180 deps[d] = url |
1182 return deps | 1181 return deps |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 file_list = [] | 1272 file_list = [] |
1274 # Run on the base solutions first. | 1273 # Run on the base solutions first. |
1275 for solution in solutions: | 1274 for solution in solutions: |
1276 name = solution["name"] | 1275 name = solution["name"] |
1277 if name in entries: | 1276 if name in entries: |
1278 raise Error("solution %s specified more than once" % name) | 1277 raise Error("solution %s specified more than once" % name) |
1279 url = solution["url"] | 1278 url = solution["url"] |
1280 entries[name] = url | 1279 entries[name] = url |
1281 if run_scm: | 1280 if run_scm: |
1282 self._options.revision = revision_overrides.get(name) | 1281 self._options.revision = revision_overrides.get(name) |
1283 scm = self._options.scm_wrapper(url, self._root_dir, name) | 1282 scm = SCMWrapper(url, self._root_dir, name) |
1284 scm.RunCommand(command, self._options, args, file_list) | 1283 scm.RunCommand(command, self._options, args, file_list) |
1285 self._options.revision = None | 1284 self._options.revision = None |
1286 try: | 1285 try: |
1287 deps_content = FileRead(os.path.join(self._root_dir, name, | 1286 deps_content = FileRead(os.path.join(self._root_dir, name, |
1288 self._options.deps_file)) | 1287 self._options.deps_file)) |
1289 except IOError, e: | 1288 except IOError, e: |
1290 if e.errno != errno.ENOENT: | 1289 if e.errno != errno.ENOENT: |
1291 raise | 1290 raise |
1292 deps_content = "" | 1291 deps_content = "" |
1293 entries_deps_content[name] = deps_content | 1292 entries_deps_content[name] = deps_content |
1294 | 1293 |
1295 # Process the dependencies next (sort alphanumerically to ensure that | 1294 # Process the dependencies next (sort alphanumerically to ensure that |
1296 # containing directories get populated first and for readability) | 1295 # containing directories get populated first and for readability) |
1297 deps = self._ParseAllDeps(entries, entries_deps_content) | 1296 deps = self._ParseAllDeps(entries, entries_deps_content) |
1298 deps_to_process = deps.keys() | 1297 deps_to_process = deps.keys() |
1299 deps_to_process.sort() | 1298 deps_to_process.sort() |
1300 | 1299 |
1301 # First pass for direct dependencies. | 1300 # First pass for direct dependencies. |
1302 for d in deps_to_process: | 1301 for d in deps_to_process: |
1303 if type(deps[d]) == str: | 1302 if type(deps[d]) == str: |
1304 url = deps[d] | 1303 url = deps[d] |
1305 entries[d] = url | 1304 entries[d] = url |
1306 if run_scm: | 1305 if run_scm: |
1307 self._options.revision = revision_overrides.get(d) | 1306 self._options.revision = revision_overrides.get(d) |
1308 scm = self._options.scm_wrapper(url, self._root_dir, d) | 1307 scm = SCMWrapper(url, self._root_dir, d) |
1309 scm.RunCommand(command, self._options, args, file_list) | 1308 scm.RunCommand(command, self._options, args, file_list) |
1310 self._options.revision = None | 1309 self._options.revision = None |
1311 | 1310 |
1312 # Second pass for inherited deps (via the From keyword) | 1311 # Second pass for inherited deps (via the From keyword) |
1313 for d in deps_to_process: | 1312 for d in deps_to_process: |
1314 if type(deps[d]) != str: | 1313 if type(deps[d]) != str: |
1315 sub_deps = self._ParseSolutionDeps( | 1314 sub_deps = self._ParseSolutionDeps( |
1316 deps[d].module_name, | 1315 deps[d].module_name, |
1317 FileRead(os.path.join(self._root_dir, | 1316 FileRead(os.path.join(self._root_dir, |
1318 deps[d].module_name, | 1317 deps[d].module_name, |
1319 self._options.deps_file)), | 1318 self._options.deps_file)), |
1320 {}) | 1319 {}) |
1321 url = sub_deps[d] | 1320 url = sub_deps[d] |
1322 entries[d] = url | 1321 entries[d] = url |
1323 if run_scm: | 1322 if run_scm: |
1324 self._options.revision = revision_overrides.get(d) | 1323 self._options.revision = revision_overrides.get(d) |
1325 scm = self._options.scm_wrapper(url, self._root_dir, d) | 1324 scm = SCMWrapper(url, self._root_dir, d) |
1326 scm.RunCommand(command, self._options, args, file_list) | 1325 scm.RunCommand(command, self._options, args, file_list) |
1327 self._options.revision = None | 1326 self._options.revision = None |
1328 | 1327 |
1329 is_using_git = IsUsingGit(self._root_dir, entries.keys()) | 1328 is_using_git = IsUsingGit(self._root_dir, entries.keys()) |
1330 self._RunHooks(command, file_list, is_using_git) | 1329 self._RunHooks(command, file_list, is_using_git) |
1331 | 1330 |
1332 if command == 'update': | 1331 if command == 'update': |
1333 # notify the user if there is an orphaned entry in their working copy. | 1332 # notify the user if there is an orphaned entry in their working copy. |
1334 # TODO(darin): we should delete this directory manually if it doesn't | 1333 # TODO(darin): we should delete this directory manually if it doesn't |
1335 # have any changes in it. | 1334 # have any changes in it. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1456 |
1458 ## gclient commands. | 1457 ## gclient commands. |
1459 | 1458 |
1460 | 1459 |
1461 def DoCleanup(options, args): | 1460 def DoCleanup(options, args): |
1462 """Handle the cleanup subcommand. | 1461 """Handle the cleanup subcommand. |
1463 | 1462 |
1464 Raises: | 1463 Raises: |
1465 Error: if client isn't configured properly. | 1464 Error: if client isn't configured properly. |
1466 """ | 1465 """ |
1467 client = options.gclient.LoadCurrentConfig(options) | 1466 client = GClient.LoadCurrentConfig(options) |
1468 if not client: | 1467 if not client: |
1469 raise Error("client not configured; see 'gclient config'") | 1468 raise Error("client not configured; see 'gclient config'") |
1470 if options.verbose: | 1469 if options.verbose: |
1471 # Print out the .gclient file. This is longer than if we just printed the | 1470 # Print out the .gclient file. This is longer than if we just printed the |
1472 # client dict, but more legible, and it might contain helpful comments. | 1471 # client dict, but more legible, and it might contain helpful comments. |
1473 print(client.ConfigContent()) | 1472 print(client.ConfigContent()) |
1474 options.verbose = True | 1473 options.verbose = True |
1475 return client.RunOnDeps('cleanup', args) | 1474 return client.RunOnDeps('cleanup', args) |
1476 | 1475 |
1477 | 1476 |
1478 def DoConfig(options, args): | 1477 def DoConfig(options, args): |
1479 """Handle the config subcommand. | 1478 """Handle the config subcommand. |
1480 | 1479 |
1481 Args: | 1480 Args: |
1482 options: If options.spec set, a string providing contents of config file. | 1481 options: If options.spec set, a string providing contents of config file. |
1483 args: The command line args. If spec is not set, | 1482 args: The command line args. If spec is not set, |
1484 then args[0] is a string URL to get for config file. | 1483 then args[0] is a string URL to get for config file. |
1485 | 1484 |
1486 Raises: | 1485 Raises: |
1487 Error: on usage error | 1486 Error: on usage error |
1488 """ | 1487 """ |
1489 if len(args) < 1 and not options.spec: | 1488 if len(args) < 1 and not options.spec: |
1490 raise Error("required argument missing; see 'gclient help config'") | 1489 raise Error("required argument missing; see 'gclient help config'") |
1491 if os.path.exists(options.config_filename): | 1490 if os.path.exists(options.config_filename): |
1492 raise Error("%s file already exists in the current directory" % | 1491 raise Error("%s file already exists in the current directory" % |
1493 options.config_filename) | 1492 options.config_filename) |
1494 client = options.gclient('.', options) | 1493 client = GClient('.', options) |
1495 if options.spec: | 1494 if options.spec: |
1496 client.SetConfig(options.spec) | 1495 client.SetConfig(options.spec) |
1497 else: | 1496 else: |
1498 # TODO(darin): it would be nice to be able to specify an alternate relpath | 1497 # TODO(darin): it would be nice to be able to specify an alternate relpath |
1499 # for the given URL. | 1498 # for the given URL. |
1500 base_url = args[0] | 1499 base_url = args[0] |
1501 name = args[0].split("/")[-1] | 1500 name = args[0].split("/")[-1] |
1502 safesync_url = "" | 1501 safesync_url = "" |
1503 if len(args) > 1: | 1502 if len(args) > 1: |
1504 safesync_url = args[1] | 1503 safesync_url = args[1] |
(...skipping 12 matching lines...) Expand all Loading... |
1517 else: | 1516 else: |
1518 raise Error("unknown subcommand '%s'; see 'gclient help'" % args[0]) | 1517 raise Error("unknown subcommand '%s'; see 'gclient help'" % args[0]) |
1519 | 1518 |
1520 | 1519 |
1521 def DoStatus(options, args): | 1520 def DoStatus(options, args): |
1522 """Handle the status subcommand. | 1521 """Handle the status subcommand. |
1523 | 1522 |
1524 Raises: | 1523 Raises: |
1525 Error: if client isn't configured properly. | 1524 Error: if client isn't configured properly. |
1526 """ | 1525 """ |
1527 client = options.gclient.LoadCurrentConfig(options) | 1526 client = GClient.LoadCurrentConfig(options) |
1528 if not client: | 1527 if not client: |
1529 raise Error("client not configured; see 'gclient config'") | 1528 raise Error("client not configured; see 'gclient config'") |
1530 if options.verbose: | 1529 if options.verbose: |
1531 # Print out the .gclient file. This is longer than if we just printed the | 1530 # Print out the .gclient file. This is longer than if we just printed the |
1532 # client dict, but more legible, and it might contain helpful comments. | 1531 # client dict, but more legible, and it might contain helpful comments. |
1533 print(client.ConfigContent()) | 1532 print(client.ConfigContent()) |
1534 options.verbose = True | 1533 options.verbose = True |
1535 return client.RunOnDeps('status', args) | 1534 return client.RunOnDeps('status', args) |
1536 | 1535 |
1537 | 1536 |
1538 def DoUpdate(options, args): | 1537 def DoUpdate(options, args): |
1539 """Handle the update and sync subcommands. | 1538 """Handle the update and sync subcommands. |
1540 | 1539 |
1541 Raises: | 1540 Raises: |
1542 Error: if client isn't configured properly. | 1541 Error: if client isn't configured properly. |
1543 """ | 1542 """ |
1544 client = options.gclient.LoadCurrentConfig(options) | 1543 client = GClient.LoadCurrentConfig(options) |
1545 | 1544 |
1546 if not client: | 1545 if not client: |
1547 raise Error("client not configured; see 'gclient config'") | 1546 raise Error("client not configured; see 'gclient config'") |
1548 | 1547 |
1549 if not options.head: | 1548 if not options.head: |
1550 solutions = client.GetVar('solutions') | 1549 solutions = client.GetVar('solutions') |
1551 if solutions: | 1550 if solutions: |
1552 for s in solutions: | 1551 for s in solutions: |
1553 if s.get('safesync_url', ''): | 1552 if s.get('safesync_url', ''): |
1554 # rip through revisions and make sure we're not over-riding | 1553 # rip through revisions and make sure we're not over-riding |
(...skipping 17 matching lines...) Expand all Loading... |
1572 print(client.ConfigContent()) | 1571 print(client.ConfigContent()) |
1573 return client.RunOnDeps('update', args) | 1572 return client.RunOnDeps('update', args) |
1574 | 1573 |
1575 | 1574 |
1576 def DoDiff(options, args): | 1575 def DoDiff(options, args): |
1577 """Handle the diff subcommand. | 1576 """Handle the diff subcommand. |
1578 | 1577 |
1579 Raises: | 1578 Raises: |
1580 Error: if client isn't configured properly. | 1579 Error: if client isn't configured properly. |
1581 """ | 1580 """ |
1582 client = options.gclient.LoadCurrentConfig(options) | 1581 client = GClient.LoadCurrentConfig(options) |
1583 if not client: | 1582 if not client: |
1584 raise Error("client not configured; see 'gclient config'") | 1583 raise Error("client not configured; see 'gclient config'") |
1585 if options.verbose: | 1584 if options.verbose: |
1586 # Print out the .gclient file. This is longer than if we just printed the | 1585 # Print out the .gclient file. This is longer than if we just printed the |
1587 # client dict, but more legible, and it might contain helpful comments. | 1586 # client dict, but more legible, and it might contain helpful comments. |
1588 print(client.ConfigContent()) | 1587 print(client.ConfigContent()) |
1589 options.verbose = True | 1588 options.verbose = True |
1590 return client.RunOnDeps('diff', args) | 1589 return client.RunOnDeps('diff', args) |
1591 | 1590 |
1592 | 1591 |
1593 def DoRevert(options, args): | 1592 def DoRevert(options, args): |
1594 """Handle the revert subcommand. | 1593 """Handle the revert subcommand. |
1595 | 1594 |
1596 Raises: | 1595 Raises: |
1597 Error: if client isn't configured properly. | 1596 Error: if client isn't configured properly. |
1598 """ | 1597 """ |
1599 client = options.gclient.LoadCurrentConfig(options) | 1598 client = GClient.LoadCurrentConfig(options) |
1600 if not client: | 1599 if not client: |
1601 raise Error("client not configured; see 'gclient config'") | 1600 raise Error("client not configured; see 'gclient config'") |
1602 return client.RunOnDeps('revert', args) | 1601 return client.RunOnDeps('revert', args) |
1603 | 1602 |
1604 | 1603 |
1605 def DoRunHooks(options, args): | 1604 def DoRunHooks(options, args): |
1606 """Handle the runhooks subcommand. | 1605 """Handle the runhooks subcommand. |
1607 | 1606 |
1608 Raises: | 1607 Raises: |
1609 Error: if client isn't configured properly. | 1608 Error: if client isn't configured properly. |
1610 """ | 1609 """ |
1611 client = options.gclient.LoadCurrentConfig(options) | 1610 client = GClient.LoadCurrentConfig(options) |
1612 if not client: | 1611 if not client: |
1613 raise Error("client not configured; see 'gclient config'") | 1612 raise Error("client not configured; see 'gclient config'") |
1614 if options.verbose: | 1613 if options.verbose: |
1615 # Print out the .gclient file. This is longer than if we just printed the | 1614 # Print out the .gclient file. This is longer than if we just printed the |
1616 # client dict, but more legible, and it might contain helpful comments. | 1615 # client dict, but more legible, and it might contain helpful comments. |
1617 print(client.ConfigContent()) | 1616 print(client.ConfigContent()) |
1618 return client.RunOnDeps('runhooks', args) | 1617 return client.RunOnDeps('runhooks', args) |
1619 | 1618 |
1620 | 1619 |
1621 def DoRevInfo(options, args): | 1620 def DoRevInfo(options, args): |
1622 """Handle the revinfo subcommand. | 1621 """Handle the revinfo subcommand. |
1623 | 1622 |
1624 Raises: | 1623 Raises: |
1625 Error: if client isn't configured properly. | 1624 Error: if client isn't configured properly. |
1626 """ | 1625 """ |
1627 client = options.gclient.LoadCurrentConfig(options) | 1626 client = GClient.LoadCurrentConfig(options) |
1628 if not client: | 1627 if not client: |
1629 raise Error("client not configured; see 'gclient config'") | 1628 raise Error("client not configured; see 'gclient config'") |
1630 client.PrintRevInfo() | 1629 client.PrintRevInfo() |
1631 | 1630 |
1632 | 1631 |
1633 gclient_command_map = { | 1632 gclient_command_map = { |
1634 "cleanup": DoCleanup, | 1633 "cleanup": DoCleanup, |
1635 "config": DoConfig, | 1634 "config": DoConfig, |
1636 "diff": DoDiff, | 1635 "diff": DoDiff, |
1637 "help": DoHelp, | 1636 "help": DoHelp, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 | 1705 |
1707 if len(argv) < 3 and command == "help": | 1706 if len(argv) < 3 and command == "help": |
1708 option_parser.print_help() | 1707 option_parser.print_help() |
1709 return 0 | 1708 return 0 |
1710 | 1709 |
1711 # Files used for configuration and state saving. | 1710 # Files used for configuration and state saving. |
1712 options.config_filename = os.environ.get("GCLIENT_FILE", ".gclient") | 1711 options.config_filename = os.environ.get("GCLIENT_FILE", ".gclient") |
1713 options.entries_filename = ".gclient_entries" | 1712 options.entries_filename = ".gclient_entries" |
1714 options.deps_file = "DEPS" | 1713 options.deps_file = "DEPS" |
1715 | 1714 |
1716 options.gclient = GClient | |
1717 options.scm_wrapper = SCMWrapper | |
1718 options.platform = sys.platform | 1715 options.platform = sys.platform |
1719 return DispatchCommand(command, options, args) | 1716 return DispatchCommand(command, options, args) |
1720 | 1717 |
1721 | 1718 |
1722 if "__main__" == __name__: | 1719 if "__main__" == __name__: |
1723 try: | 1720 try: |
1724 result = Main(sys.argv) | 1721 result = Main(sys.argv) |
1725 except Error, e: | 1722 except Error, e: |
1726 print >> sys.stderr, "Error: %s" % str(e) | 1723 print >> sys.stderr, "Error: %s" % str(e) |
1727 result = 1 | 1724 result = 1 |
1728 sys.exit(result) | 1725 sys.exit(result) |
1729 | 1726 |
1730 # vim: ts=2:sw=2:tw=80:et: | 1727 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |