Home | History | Annotate | Download | only in fixups
      1 # Copyright 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """A module for architecture output directory fixups."""
      6 
      7 import cr
      8 
      9 
     10 class _ArchInitHookHelper(cr.InitHook):
     11   """Base class helper for CR_ARCH value fixups."""
     12 
     13   def _VersionTest(self, old_version):
     14     _ = old_version
     15     return True
     16 
     17   def _ArchConvert(self, old_arch):
     18     return old_arch
     19 
     20   def Run(self, old_version, config):
     21     if old_version is None or not self._VersionTest(old_version):
     22       return
     23     old_arch = config.OVERRIDES.Find(cr.Arch.SELECTOR)
     24     new_arch = self._ArchConvert(old_arch)
     25     if new_arch != old_arch:
     26       print '** Fixing architecture from {0} to {1}'.format(old_arch, new_arch)
     27       config.OVERRIDES[cr.Arch.SELECTOR] = new_arch
     28 
     29 
     30 class WrongArchDefaultInitHook(_ArchInitHookHelper):
     31   """Fixes bad initial defaults.
     32 
     33   In the initial versions of cr before output directories were versioned
     34   it was writing invalid architecture defaults. This detects that case and sets
     35   the architecture to the current default instead.
     36   """
     37 
     38   def _VersionTest(self, old_version):
     39     return old_version <= 0.0
     40 
     41   def _ArchConvert(self, _):
     42     return cr.Arch.default.name
     43 
     44 
     45 class MipsAndArmRenameInitHook(_ArchInitHookHelper):
     46   """Fixes rename of Mips and Arm to Mips32 and Arm32."""
     47 
     48   def _ArchConvert(self, old_arch):
     49     if old_arch == 'mips':
     50       return cr.Mips32Arch.GetInstance().name
     51     if old_arch == 'arm':
     52       return cr.Arm32Arch.GetInstance().name
     53     return old_arch
     54 
     55