[banshee] [build] rework the profile/package loading, fix uglies



commit 61e9a4efa5c9b14704f5e43d1937eb190667665a
Author: Aaron Bockover <abockover novell com>
Date:   Sun Dec 20 14:27:12 2009 -0500

    [build] rework the profile/package loading, fix uglies
    
    The build profile is now accessible from packages, each
    profile has a name and a host property, so conditional
    things can be done on packages. An example of this in flac.

 build/bundle/build.py         |   71 ++++++++++++++++-------------------------
 build/bundle/packages/flac.py |   11 +++++--
 build/bundle/profile.osx.py   |   15 +++++----
 3 files changed, 44 insertions(+), 53 deletions(-)
---
diff --git a/build/bundle/build.py b/build/bundle/build.py
index f336c0a..b686aab 100755
--- a/build/bundle/build.py
+++ b/build/bundle/build.py
@@ -8,22 +8,22 @@ import shutil
 import urllib
 import subprocess
 
-def build_package (package, vars):
+def build_package (profile, (package, vars)):
 	package_dir = os.path.dirname (package['_path'])
-	package_build_dir = os.path.join (config['build_root'],
+	package_build_dir = os.path.join (profile['build_root'],
 		'%s-%s' % (package['name'], package['version']))
-	build_success_file = os.path.join (config['build_root'],
+	build_success_file = os.path.join (profile['build_root'],
 		'%s-%s.success' % (package['name'], package['version']))
 
 	if os.path.exists (build_success_file):
 		print 'Skipping %s - already built' % package['name']
 		return
 
-	print 'Building %s on %s (%s CPU)' % (package['name'], get_host (), get_cpu_count ())
+	print 'Building %s on %s (%s CPU)' % (package['name'], profile['host'], get_cpu_count ())
 
 	# Set up the directories
-	if not os.path.exists (config['build_root']) or not os.path.isdir (config['build_root']):
-		os.makedirs (config['build_root'], 0755)
+	if not os.path.exists (profile['build_root']) or not os.path.isdir (profile['build_root']):
+		os.makedirs (profile['build_root'], 0755)
 
 	shutil.rmtree (package_build_dir, ignore_errors = True)
 	os.makedirs (package_build_dir)
@@ -63,9 +63,9 @@ def build_package (package, vars):
 
 	open (build_success_file, 'w').close ()
 
-def load_package_defaults (config, package):
+def load_package_defaults (profile, package):
 	# path macros
-	package['_build_root'] = os.path.join (config['build_root'], '_install')
+	package['_build_root'] = os.path.join (profile['build_root'], '_install')
 	package['_prefix'] = package['_build_root']
 
 	# tool macros
@@ -85,8 +85,8 @@ def load_package_defaults (config, package):
 # Package file parsing
 #--------------------------------------
 
-def parse_package (package):
-	load_package_defaults (config, package)
+def parse_package (profile, package):
+	load_package_defaults (profile, package)
 
 	# walk the top level to collect and save variable tree
 	vars = {}
@@ -199,44 +199,29 @@ def log (level, message):
 # Main Program
 #--------------------------------------
 
-__packages = []
-config = {
-	'build_root': os.path.join (os.getcwd (), 'build-root')
-}
-
-def load_file (path):
-	package = None
-	packages = None
-	build_env = None
-	if not os.path.isfile (path):
-		sys.exit ('Error: %s is not a file' % path)
-	exec open (path).read ()
-	if isinstance (package, dict):
-		package['_path'] = path
-		__packages.append (parse_package (package))
-	elif isinstance (packages, (list, tuple)):
-		pass
-		for package in packages:
-			load_file (package)
-	if isinstance (build_env, dict):
-		print '%s is overriding build_env config' % path
-		globals ()['config'] = build_env 
-
 if __name__ == '__main__':
-	for arg in sys.argv[1:]:
-		load_file (arg)
+	packages_to_build = sys.argv[2:]
+	exec open (sys.argv[1]).read ()
 	
-	config_vars = {}
-	for d in [config, config['environ']]:
+	profile_vars = {}
+	for d in [profile, profile['environ']]:
 		for k, v in d.iteritems ():
-			config_vars[k] = v
-	config = expand_macros (config, config_vars, False)
+			profile_vars[k] = v
+
+	profile = expand_macros (profile, profile_vars, False)
+	profile.setdefault ('host', get_host ())
 
-	if config['environ']:
+	log (0, 'Loaded profile \'%s\' (%s)' % (profile['name'], profile['host']))
+
+	if 'environ' in profile:
 		log (0, 'Setting environment variables')
-		for k, v in config['environ'].iteritems ():
+		for k, v in profile['environ'].iteritems ():
 			os.environ[k] = v
 			log (1, '%s = %s' % (k, os.getenv (k)))
 
-	for package, vars in __packages:
-		build_package (package, vars)
+	for path in profile['packages']:
+		exec open (path).read ()
+		if not packages_to_build == [] and package['name'] not in packages_to_build:
+			continue
+		package['_path'] = path
+		build_package (profile, parse_package (profile, package))
diff --git a/build/bundle/packages/flac.py b/build/bundle/packages/flac.py
index 15caf07..f63312b 100644
--- a/build/bundle/packages/flac.py
+++ b/build/bundle/packages/flac.py
@@ -1,3 +1,10 @@
+configure_flags = [
+	'--disable-cpplibs'
+]
+
+if profile['name'] == 'osx':
+	configure_flags.append ('--disable-asm-optimizations')
+
 package = {
 	'name':    'flac',
 	'version': '1.2.1',
@@ -5,9 +12,7 @@ package = {
 		'http://downloads.xiph.org/releases/%{name}/%{name}-%{version}.tar.gz'
 	],
 	'build': [
-		'%{__configure}' \
-			' --disable-asm-optimizations' \
-			' --disable-cpplibs',
+		'%{__configure}' + ' '.join (configure_flags),
 		'%{__make}'
 	]
 }
diff --git a/build/bundle/profile.osx.py b/build/bundle/profile.osx.py
index b0b5bd8..f3a9817 100644
--- a/build/bundle/profile.osx.py
+++ b/build/bundle/profile.osx.py
@@ -1,4 +1,5 @@
-build_env = {
+profile = {
+	'name': 'osx',
 	'build_root': os.path.join (os.getcwd (), 'build-root'),
 	'prefix': '%{build_root}/_install',
 	'mac_sdk_path': '/Developer/SDKs/MacOSX10.5.sdk',
@@ -20,7 +21,7 @@ gcc_flags = [
 ]
 gcc_flags.extend (['-I' + os.path.join (p, 'include') for p in search_paths])
 
-build_env['environ'] = {
+profile['environ'] = {
 	'PATH': ':'.join (bin_paths),
 	'CFLAGS': ' '.join (gcc_flags),
 	'CXXFLAGS': '%{CFLAGS}',
@@ -34,7 +35,7 @@ build_env['environ'] = {
 	])
 }
 
-packages = [
+profile['packages'] = [
 	# Base dependencies
 	'packages/libxml2.py',
 	'packages/libproxy.py',
@@ -67,9 +68,9 @@ packages = [
 	'packages/ige-mac-integration-sharp.py'
 ]
 
-if not os.path.isdir (build_env['mac_sdk_path']):
-	sys.exit ('Mac OS X SDK does not exist: %s' % build_env['mac_sdk_path'])
+if not os.path.isdir (profile['mac_sdk_path']):
+	sys.exit ('Mac OS X SDK does not exist: %s' % profile['mac_sdk_path'])
 
-if not os.path.isdir (build_env['mono_sdk_path']):
-	sys.exit ('Mono SDK does not exist: %s' % build_env['mono_sdk_path'])
+if not os.path.isdir (profile['mono_sdk_path']):
+	sys.exit ('Mono SDK does not exist: %s' % profile['mono_sdk_path'])
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]