summaryrefslogtreecommitdiffstats
path: root/tools/cr
diff options
context:
space:
mode:
authoriancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-14 13:38:24 +0000
committeriancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-14 13:38:24 +0000
commitee2179591e82f32d519690c3d209b9c4e38072e6 (patch)
treecef395f3850ce43f43ba7780778cc6663503e99d /tools/cr
parentefe3a2e5dc4592954e233cc950c0bd74a9adec82 (diff)
downloadchromium_src-ee2179591e82f32d519690c3d209b9c4e38072e6.zip
chromium_src-ee2179591e82f32d519690c3d209b9c4e38072e6.tar.gz
chromium_src-ee2179591e82f32d519690c3d209b9c4e38072e6.tar.bz2
[cr tool] Android client upgrade.
Moving android detection to an init hook, and adding upgrade behaviour BUG=311092 Review URL: https://codereview.chromium.org/101873009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244677 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r--tools/cr/cr/base/android.py57
-rw-r--r--tools/cr/cr/base/client.py23
-rw-r--r--tools/cr/cr/base/host.py17
-rw-r--r--tools/cr/cr/commands/sync.py6
-rw-r--r--tools/cr/cr/context.py4
5 files changed, 85 insertions, 22 deletions
diff --git a/tools/cr/cr/base/android.py b/tools/cr/cr/base/android.py
index cf61577..45fdc51 100644
--- a/tools/cr/cr/base/android.py
+++ b/tools/cr/cr/base/android.py
@@ -19,16 +19,6 @@ _IGNORE_ENV = [
'GYP_DEFINES', # Because it gets a special merge handler
]
-# The message to print when we detect use of an android output directory in a
-# client that cannot build android.
-_NOT_ANDROID_MESSAGE = """
-You are trying to build for the android platform in a client that is not
-android capable.
-Please get a new client using "fetch android".
-See https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for more
-details.
-"""
-
class AndroidPlatform(cr.Platform):
"""The implementation of Platform for the android target."""
@@ -64,16 +54,6 @@ class AndroidPlatform(cr.Platform):
def Prepare(self, context):
"""Override Prepare from cr.Platform."""
super(AndroidPlatform, self).Prepare(context)
- # Check we are an android capable client
- is_android = 'android' in context.gclient.get('target_os', '')
- if not is_android:
- url = context.gclient.get('solutions', [{}])[0].get('url')
- is_android = (url.startswith(
- 'https://chrome-internal.googlesource.com/') and
- url.endswith('/internal/apps.git'))
- if not is_android:
- print _NOT_ANDROID_MESSAGE
- exit(1)
try:
# capture the result of env setup if we have not already done so
if not self._env_ready:
@@ -114,3 +94,40 @@ class AndroidPlatform(cr.Platform):
@property
def paths(self):
return self._env_paths
+
+
+class AndroidInitHook(cr.InitHook):
+ """Android output directory init hook.
+
+ This makes sure that your client is android capable when you try
+ to make and android output directory.
+ """
+
+ @property
+ def enabled(self):
+ return cr.AndroidPlatform.GetInstance().is_active
+
+ def Run(self, context, old_version, config):
+ _ = old_version, config # unused
+ # Check we are an android capable client
+ target_os = context.gclient.get('target_os', [])
+ if 'android' in target_os:
+ return
+ url = context.gclient.get('solutions', [{}])[0].get('url')
+ if (url.startswith('https://chrome-internal.googlesource.com/') and
+ url.endswith('/internal/apps.git')):
+ return
+ print 'This client is not android capable.'
+ print 'It can be made capable by adding android to the target_os list'
+ print 'in the .gclient file, and then syncing again.'
+ if not cr.Host.YesNo('Would you like to upgrade this client?'):
+ print 'Abandoning the creation of and android output directory.'
+ exit(1)
+ target_os.append('android')
+ context.gclient['target_os'] = target_os
+ context.WriteGClient()
+ print 'Client updated.'
+ print 'You may need to sync before an output directory can be made.'
+ if cr.Host.YesNo('Would you like to sync this client now?'):
+ cr.SyncCommand.Sync(context, ["--nohooks"])
+
diff --git a/tools/cr/cr/base/client.py b/tools/cr/cr/base/client.py
index 8a5955e..0b679ce 100644
--- a/tools/cr/cr/base/client.py
+++ b/tools/cr/cr/base/client.py
@@ -11,6 +11,7 @@ rest of the cr tool what the client is capable of.
"""
import os
+import pprint
import sys
import cr
@@ -112,7 +113,7 @@ def ReadGClient(context):
This will load from CR_CLIENT_PATH.
Args:
- context: The active context to load configuratin for.
+ context: The active context to load configuration for.
Returns:
The dict of values set in the .gclient file.
@@ -131,6 +132,26 @@ def ReadGClient(context):
return result
+def WriteGClient(context):
+ """Writes the .gclient configuration for the current client.
+
+ This will write to CR_CLIENT_PATH.
+
+ Args:
+ context: The active context to write the configuration for.
+
+ """
+ gclient_file = context.Substitute(
+ os.path.join('{CR_CLIENT_PATH}', GCLIENT_FILENAME))
+ spec = '\n'.join('%s = %s' % (key, pprint.pformat(value))
+ for key,value in context.gclient.items())
+ if context.dry_run:
+ print 'Write the following spec to', gclient_file
+ print spec
+ else:
+ with open(gclient_file, 'w') as spec_file:
+ spec_file.write(spec)
+
def LoadConfig(context):
"""Loads the client configuration for the given context.
diff --git a/tools/cr/cr/base/host.py b/tools/cr/cr/base/host.py
index c6cb212..745e15f 100644
--- a/tools/cr/cr/base/host.py
+++ b/tools/cr/cr/base/host.py
@@ -137,6 +137,23 @@ class Host(cr.Plugin, cr.Plugin.Type):
return self._Execute(context, command,
ignore_dry_run=True, return_status=True)
+ @cr.Plugin.activemethod
+ def YesNo(self, question, default=True):
+ """Ask the user a yes no question
+
+ This blocks until the user responds.
+ Args:
+ question: The question string to show the user
+ default: True if the default response is Yes
+ Returns:
+ True if the response was yes.
+ """
+ options = 'Y/n' if default else 'y/N'
+ result = raw_input(question + ' [' + options + '] ').lower()
+ if result == '':
+ return default
+ return result in ['y', 'yes']
+
@classmethod
def SearchPath(cls, name):
"""Searches the PATH for an executable.
diff --git a/tools/cr/cr/commands/sync.py b/tools/cr/cr/commands/sync.py
index 4f5232ab..c18187f 100644
--- a/tools/cr/cr/commands/sync.py
+++ b/tools/cr/cr/commands/sync.py
@@ -37,11 +37,15 @@ class SyncCommand(cr.Command):
return parser
def Run(self, context):
+ self.Sync(context, context.remains)
+
+ @staticmethod
+ def Sync(context, args):
# TODO(iancottrell): we should probably run the python directly,
# rather than the shell wrapper
# TODO(iancottrell): try to help out when the local state is not a good
# one to do a sync in
- cr.Host.Execute(context, '{GCLIENT_BINARY}', 'sync', *context.remains)
+ cr.Host.Execute(context, '{GCLIENT_BINARY}', 'sync', *args)
@classmethod
diff --git a/tools/cr/cr/context.py b/tools/cr/cr/context.py
index b171358..176961e 100644
--- a/tools/cr/cr/context.py
+++ b/tools/cr/cr/context.py
@@ -205,6 +205,10 @@ class Context(cr.config.Config, cr.loader.AutoExport):
self._gclient = cr.base.client.ReadGClient(self)
return self._gclient
+ def WriteGClient(self):
+ if self._gclient:
+ cr.base.client.WriteGClient(self)
+
def ParseArgs(self, speculative=False):
cr.plugin.DynamicChoices.only_active = not speculative
self._speculative = speculative