diff options
author | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 23:30:02 +0000 |
---|---|---|
committer | iancottrell@chromium.org <iancottrell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 23:30:02 +0000 |
commit | 7f4db39671a1e34f55ee13332f37d3434aca3ab4 (patch) | |
tree | c87f0f7cec42aad6c2f0f0f2aa789ab4aa708383 /tools/cr | |
parent | 19d6392443ee414c172e27e3bb11df4c1aa7dddb (diff) | |
download | chromium_src-7f4db39671a1e34f55ee13332f37d3434aca3ab4.zip chromium_src-7f4db39671a1e34f55ee13332f37d3434aca3ab4.tar.gz chromium_src-7f4db39671a1e34f55ee13332f37d3434aca3ab4.tar.bz2 |
[cr tool] Improving init hooks
Change init fixups to proper init hooks that can detect fixups instead, change version to something with natural order so you can test for earlier versions.
This will enable init hooks to deal with non android clients.
BUG=311092
Review URL: https://codereview.chromium.org/111563004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r-- | tools/cr/cr/base/client.py | 2 | ||||
-rw-r--r-- | tools/cr/cr/commands/init.py | 40 | ||||
-rw-r--r-- | tools/cr/cr/fixups/arch.py | 12 |
3 files changed, 35 insertions, 19 deletions
diff --git a/tools/cr/cr/base/client.py b/tools/cr/cr/base/client.py index ef4fa23..d8eef12 100644 --- a/tools/cr/cr/base/client.py +++ b/tools/cr/cr/base/client.py @@ -18,7 +18,7 @@ import cr.auto.build import cr.auto.client # The config version currently supported. -VERSION = '0.4' +VERSION = 0.5 # The default directory name to store config inside CLIENT_CONFIG_PATH = '.cr' # The partial filename to add to a directory to get it's config file. diff --git a/tools/cr/cr/commands/init.py b/tools/cr/cr/commands/init.py index 8e24c33b..adcb4a1 100644 --- a/tools/cr/cr/commands/init.py +++ b/tools/cr/cr/commands/init.py @@ -107,6 +107,13 @@ class InitCommand(cr.Command): # This will only be missing if we are creating a brand new output # directory build_package = cr.auto.build + + # Collect the old version (and float convert) + old_version = context.Find('CR_VERSION') + try: + old_version = float(old_version) + except (ValueError, TypeError): + old_version = 0.0 is_new = not hasattr(build_package, 'config') if is_new: @@ -116,12 +123,12 @@ class InitCommand(cr.Command): def __init__(self): self.__name__ = 'config' + old_version = None config = FakeModule() setattr(build_package, 'config', config) cr.plugin.ChainModuleConfigs(config) # Force override the version - old_version = context.Find('CR_VERSION') build_package.config.OVERRIDES.Set(CR_VERSION=cr.base.client.VERSION) # Add all the variables that we always want to have for name in OUT_CONFIG_VARS: @@ -137,12 +144,11 @@ class InitCommand(cr.Command): value = cr.Config.ParseValue(value.strip()) build_package.config.OVERRIDES[name] = value - if not is_new: - # Run all the output directory fixup tasks - for fixup in InitFixup.Plugins(): - fixup.Fixup(context, old_version, build_package.config) - # Redo activations, they might have changed - cr.plugin.Activate(context) + # Run all the output directory init hooks + for hook in InitHook.Plugins(): + hook.Run(context, old_version, build_package.config) + # Redo activations, they might have changed + cr.plugin.Activate(context) # Write out the new configuration, and select it as the default cr.base.client.WriteConfig(context, context.Get('CR_BUILD_DIR'), @@ -152,13 +158,23 @@ class InitCommand(cr.Command): cr.SelectCommand.Select(context) -class InitFixup(cr.Plugin, cr.Plugin.Type): - """Base class for output directory initialization fixups. +class InitHook(cr.Plugin, cr.Plugin.Type): + """Base class for output directory initialization hooks. - These are invoked to upgrade an old output directory to an up to date form. - They normally live in the cr.fixups package. + Implementations used to fix from old version to new ones live in the + cr.fixups package. """ - def Fixup(self, context, old_version, config): + def Run(self, context, old_version, config): + """Run the initialization hook. + + This is invoked once per init invocation. + Args: + context: The context of the init command. + old_version: The old version, + 0.0 if the old version was bad or missing, + None if building a new output direcory. + config: The mutable config that will be written. + """ raise NotImplementedError('Must be overridden.') diff --git a/tools/cr/cr/fixups/arch.py b/tools/cr/cr/fixups/arch.py index 0b250c8b..e6ac81c 100644 --- a/tools/cr/cr/fixups/arch.py +++ b/tools/cr/cr/fixups/arch.py @@ -7,7 +7,7 @@ import cr -class _ArchFixupHelper(cr.InitFixup): +class _ArchInitHookHelper(cr.InitHook): """Base class helper for CR_ARCH value fixups.""" def _VersionTest(self, old_version): @@ -17,8 +17,8 @@ class _ArchFixupHelper(cr.InitFixup): def _ArchConvert(self, old_arch): return old_arch - def Fixup(self, context, old_version, config): - if not self._VersionTest(old_version): + def Run(self, context, old_version, config): + if old_version is None or not self._VersionTest(old_version): return old_arch = config.OVERRIDES.Find(cr.Arch.SELECTOR) new_arch = self._ArchConvert(old_arch) @@ -27,7 +27,7 @@ class _ArchFixupHelper(cr.InitFixup): config.OVERRIDES[cr.Arch.SELECTOR] = new_arch -class WrongArchDefaultInitFixup(_ArchFixupHelper): +class WrongArchDefaultInitHook(_ArchInitHookHelper): """Fixes bad initial defaults. In the initial versions of cr before output directories were versioned @@ -36,13 +36,13 @@ class WrongArchDefaultInitFixup(_ArchFixupHelper): """ def _VersionTest(self, old_version): - return old_version is None + return old_version <= 0.0 def _ArchConvert(self, _): return cr.Arch.default.name -class MipsAndArmRenameInitFixup(_ArchFixupHelper): +class MipsAndArmRenameInitHook(_ArchInitHookHelper): """Fixes rename of Mips and Arm to Mips32 and Arm32.""" def _ArchConvert(self, old_arch): |