summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndoni Morales Alastruey <ylatuya@gmail.com>2012-06-28 14:12:52 +0200
committerAndoni Morales Alastruey <ylatuya@gmail.com>2012-08-08 13:02:28 +0200
commit3503ead66ac27e17fb8ae8345df1c79ac7b3367b (patch)
treedf4fa9fde1ad32805fa86916f2846fc3ebd0daae
parent5a795fcbeb8a08cce1e9ec5b1c3c1604991a1b0a (diff)
config: Add initial support for Universal builds in the config
-rw-r--r--cerbero/config.py50
-rw-r--r--cerbero/enums.py1
-rw-r--r--cerbero/main.py3
-rw-r--r--test/test_cerbero_config.py27
4 files changed, 50 insertions, 31 deletions
diff --git a/cerbero/config.py b/cerbero/config.py
index e2ba023..e9a065d 100644
--- a/cerbero/config.py
+++ b/cerbero/config.py
@@ -18,6 +18,7 @@
import os
import sys
+import copy
from cerbero import enums
from cerbero.errors import FatalError, ConfigurationError
@@ -56,17 +57,18 @@ class Config (object):
'install_dir', 'allow_parallel_build', 'num_of_cpus',
'use_configure_cache', 'packages_prefix', 'packager',
'data_dir', 'min_osx_sdk_version', 'external_recipes',
- 'external_packages', 'use_ccache', 'force_git_commit']
+ 'external_packages', 'use_ccache', 'force_git_commit',
+ 'universal_archs']
- def __init__(self, filename=None, load=True):
+ def __init__(self):
self._check_uninstalled()
for a in self._properties:
setattr(self, a, None)
- if not load:
- return
+ self.arch_config = {self.target_arch: self}
+ def load(self, filename=None):
# First load the default configuration
self.load_defaults()
@@ -77,6 +79,15 @@ class Config (object):
# from the main configuration file
self._load_cmd_config(filename)
+ # Create a copy of the config for each architecture in case we are
+ # building Universal binaries
+ if self.target_arch == Architecture.UNIVERSAL:
+ arch_config = {}
+ for arch in self.universal_archs:
+ arch_config[arch] = copy.deepcopy(self)
+ arch_config[arch].target_arch = arch
+ self.arch_config = arch_config
+
# Next, load the platform configuration
self._load_platform_config()
@@ -225,23 +236,26 @@ class Config (object):
else:
raise ConfigurationError(_("Configuration file %s doesn't "
"exists") % filename)
+
def _load_platform_config(self):
- platform_config = os.path.join(self.environ_dir, '%s.config' %
- self.target_platform)
- arch_config = os.path.join(self.environ_dir, '%s_%s.config' %
- (self.target_platform, self.target_arch))
+ for config in self.arch_config.values():
+ platform_config = os.path.join(config.environ_dir, '%s.config' %
+ config.target_platform)
+ arch_config = os.path.join(config.environ_dir, '%s_%s.config' %
+ (config.target_platform, config.target_arch))
- for config in [platform_config, arch_config]:
- if os.path.exists(config):
- self.parse(config, reset=False)
+ for config_path in [platform_config, arch_config]:
+ if os.path.exists(config_path):
+ config.parse(config_path, reset=False)
def _load_last_defaults(self):
- cerbero_home = os.path.expanduser('~/cerbero')
- self.set_property('prefix', os.path.join(cerbero_home, 'dist'))
- self.set_property('install_dir', self.prefix)
- self.set_property('sources', os.path.join(cerbero_home, 'sources'))
- self.set_property('local_sources',
- os.path.join(cerbero_home, 'sources', 'local'))
+ for config in self.arch_config.values() + [self]:
+ cerbero_home = os.path.expanduser('~/cerbero')
+ config.set_property('prefix', os.path.join(cerbero_home, 'dist'))
+ config.set_property('install_dir', config.prefix)
+ config.set_property('sources', os.path.join(cerbero_home, 'sources'))
+ config.set_property('local_sources',
+ os.path.join(cerbero_home, 'sources', 'local'))
def load_defaults(self):
self.set_property('cache_file', None)
@@ -277,6 +291,8 @@ class Config (object):
self.set_property('use_configure_cache', False)
self.set_property('external_recipes', {})
self.set_property('external_packages', {})
+ self.set_property('universal_archs',
+ [Architecture.X86, Architecture.X86_64])
def validate_properties(self):
if not validate_packager(self.packager):
diff --git a/cerbero/enums.py b/cerbero/enums.py
index 800ee87..6273b1b 100644
--- a/cerbero/enums.py
+++ b/cerbero/enums.py
@@ -29,6 +29,7 @@ class Architecture:
X86 = 'x86'
X86_64 = 'x86_64'
PPC = 'ppc'
+ UNIVERSAL = 'universal'
class Distro:
diff --git a/cerbero/main.py b/cerbero/main.py
index e55ac5f..1b1080f 100644
--- a/cerbero/main.py
+++ b/cerbero/main.py
@@ -85,7 +85,8 @@ class Main(object):
def load_config(self):
''' Load the configuration '''
try:
- self.config = config.Config(self.args.config)
+ self.config = config.Config()
+ self.config.load(self.args.config)
except ConfigurationError, exc:
traceback.print_exc()
self.log_error(exc, False)
diff --git a/test/test_cerbero_config.py b/test/test_cerbero_config.py
index e40f0e4..c9b4ed2 100644
--- a/test/test_cerbero_config.py
+++ b/test/test_cerbero_config.py
@@ -42,12 +42,12 @@ class LinuxPackagesTest(unittest.TestCase):
self.assertEquals(getattr(config, p), 'test')
def testAllPropsInitializedNone(self):
- config = Config(load=False)
+ config = Config()
for p in config._properties:
self.assertIsNone(getattr(config, p))
def testLoadDefaults(self):
- config = Config(load=False)
+ config = Config()
config.load_defaults()
platform, arch, distro, distro_version, num_of_cpus = system_info()
data_dir = os.path.join(os.path.dirname(__file__), '..', 'data')
@@ -90,13 +90,14 @@ class LinuxPackagesTest(unittest.TestCase):
'external_recipes': {},
'use_ccache': None,
'force_git_commit': None,
+ 'universal_archs': [cconfig.Architecture.X86, cconfig.Architecture.X86_64],
}
self.assertEquals(sorted(config._properties), sorted(props.keys()))
for p, v in props.iteritems():
self.assertEquals(getattr(config, p), v)
def testLoadMainConfig(self):
- config = Config(load=False)
+ config = Config()
tmpconfig = tempfile.NamedTemporaryFile()
cconfig.DEFAULT_CONFIG_FILE = tmpconfig.name
@@ -110,7 +111,7 @@ class LinuxPackagesTest(unittest.TestCase):
tmpconfig.name, config._properties)
def testLoadPlatformConfig(self):
- config = Config(load=False)
+ config = Config()
tmpdir = tempfile.mkdtemp()
config.environ_dir = tmpdir
config.load_defaults()
@@ -122,13 +123,13 @@ class LinuxPackagesTest(unittest.TestCase):
platform_config, config._properties)
def testFindDataDir(self):
- config = Config(load=False)
+ config = Config()
del os.environ[cconfig.CERBERO_UNINSTALLED]
config._check_uninstalled()
self.failUnlessRaises(FatalError, config.load_defaults)
def testCheckUninstalled(self):
- config = Config(load=False)
+ config = Config()
del os.environ[cconfig.CERBERO_UNINSTALLED]
config._check_uninstalled()
self.assertFalse(config.uninstalled)
@@ -137,7 +138,7 @@ class LinuxPackagesTest(unittest.TestCase):
self.assertTrue(config.uninstalled)
def testSetupEnv(self):
- config = Config(load=False)
+ config = Config()
tmpdir = tempfile.mkdtemp()
config.prefix = tmpdir
config.load_defaults()
@@ -148,21 +149,21 @@ class LinuxPackagesTest(unittest.TestCase):
self.assertEquals(os.environ[k], v)
def testParseBadConfigFile(self):
- config = Config(load=False)
+ config = Config()
tmpfile = tempfile.NamedTemporaryFile()
with open(tmpfile.name, 'w') as f:
f.write('nonsense line')
self.failUnlessRaises(ConfigurationError, config.parse, tmpfile.name)
def testJoinPath(self):
- config = Config(load=False)
+ config = Config()
config.platform = Platform.LINUX
self.assertEquals(config._join_path('/test1', '/test2'), '/test1:/test2')
config.platform = Platform.WINDOWS
self.assertEquals(config._join_path('/test1', '/test2'), '/test1;/test2')
def testLoadCommandConfig(self):
- config = Config(load=False)
+ config = Config()
config.filename = None
config._load_cmd_config(None)
self.assertIsNone(config.filename)
@@ -173,7 +174,7 @@ class LinuxPackagesTest(unittest.TestCase):
self.assertEquals(config.filename, cconfig.DEFAULT_CONFIG_FILE)
def testLastDefaults(self):
- config = Config(load=False)
+ config = Config()
config._load_last_defaults()
cerbero_home = os.path.expanduser('~/cerbero')
self.assertEquals(config.prefix, os.path.join(cerbero_home, 'dist'))
@@ -184,7 +185,7 @@ class LinuxPackagesTest(unittest.TestCase):
os.path.join(cerbero_home, 'sources', 'local'))
def testRecipesExternalRepositories(self):
- config = Config(load=False)
+ config = Config()
config.recipes_dir = 'test'
config.external_recipes = {'test1': ('/path/to/repo', 1),
'test2': ('/path/to/other/repo', 2)}
@@ -194,7 +195,7 @@ class LinuxPackagesTest(unittest.TestCase):
self.assertEquals(config.get_recipes_repos(), expected)
def testPakcagesExternalRepositories(self):
- config = Config(load=False)
+ config = Config()
config.packages_dir = 'test'
config.external_packages = {'test1': ('/path/to/repo', 1),
'test2': ('/path/to/other/repo', 2)}