[buildj] tool name for C++ changed from cxx to c++, added support for options



commit dc89524954de7238e554e71c9bd96f5ae4aa0552
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun Mar 14 16:01:05 2010 +0000

    tool name for C++ changed from cxx to c++, added support for options

 README                        |    5 +++
 buildj.py                     |   66 +++++++++++++++++++++++++++++++++++++----
 cpprogram.cpp                 |   10 ++++++
 buildj.svg => data/buildj.svg |    0
 project.js                    |   14 +++++++--
 waf                           |  Bin 90082 -> 89767 bytes
 wscript                       |    9 +++++-
 7 files changed, 94 insertions(+), 10 deletions(-)
---
diff --git a/README b/README
new file mode 100644
index 0000000..ceaad1c
--- /dev/null
+++ b/README
@@ -0,0 +1,5 @@
+= Project Creation =
+
+To create a buildj project, copy the waf and buildj.py files and create a
+project.js file following the examples in the project.js file in the repository
+and the spec at http://live.gnome.org/BuilDj/Spec
diff --git a/buildj.py b/buildj.py
index c4bb4a4..203ae6b 100644
--- a/buildj.py
+++ b/buildj.py
@@ -2,16 +2,16 @@ import json
 import re
 
 WAF_TOOLS = {'cc':   'compiler_cc',
-             'cxx':  'compiler_cxx',
+             'c++':  'compiler_cxx',
              'vala': 'compiler_cc vala'}
 
 # (Tool,Type) -> Waf features map
 FEATURES_MAP = {('cc', 'program'):     'cc cprogram',
                 ('cc', 'sharedlib'):   'cc cshlib',
                 ('cc', 'staticlib'):   'cc cstaticlib',
-                ('cxx', 'program'):    'cxx cprogram',
-                ('cxx', 'sharedlib'):  'cxx cshlib',
-                ('cxx', 'staticlib'):  'cxx cstaticlib',
+                ('c++', 'program'):    'cxx cprogram',
+                ('c++', 'sharedlib'):  'cxx cshlib',
+                ('c++', 'staticlib'):  'cxx cstaticlib',
                 ('vala', 'program'):   'cc cprogram',
                 ('vala', 'sharedlib'): 'cc cshlib',
                 ('vala', 'staticlib'): 'cc cstaticlib'}
@@ -72,11 +72,21 @@ class ProjectFile:
 
 		return  str(project_node["name"])
 		
+	def get_options (self):
+		project = self._project
+		if not "options" in project:
+			return []
+
+		option_list = []
+		for option_name in project["options"]:
+			option_list.append (ProjectOption (str(option_name),
+			                                   project["options"][option_name]))
+		return option_list
 		
 	def get_targets (self):
 		project = self._project
 		if not "targets" in project:
-			return
+			return []
 		
 		project_list = []
 		for target_name in project["targets"]:
@@ -111,10 +121,12 @@ class ProjectFile:
 		          for require in project["requires"]]
 	
 	def get_packages_required (self):
+		"List of pkg-config packages required"
 		requires = self.get_requires ()
 		return [require for require in requires if require.get_type () == "package"]
 	
 	def get_check_pkg_arg_list (self):
+		"WAF check_pkg arguments dictionary of all packages"
 		return [package.get_check_pkg_args ()
 		          for package in self.get_packages_required ()]
 
@@ -187,6 +199,7 @@ class ProjectTarget:
 		return self._get_string_list ("defines")
 	
 	def get_build_arguments (self):
+		"WAF bld arguments dictionary"
 		args = {"features": self.get_features (),
             "source":   self.get_input (),
             "target":   self.get_name ()}
@@ -230,6 +243,7 @@ class ValaTarget (CcTarget):
 		return None
 
 	def get_build_arguments (self):
+			"WAF bld arguments dictionary"
 			args = CcTarget.get_build_arguments (self)
 
 			packages = self.get_packages ()
@@ -284,6 +298,7 @@ class ProjectRequirement:
 		
 		
 	def get_check_pkg_args (self):
+		"WAF check_pkg arguments dictionary"
 		args = {"package": self.get_name ()}
 		
 		#Correctly sets the version
@@ -312,7 +327,46 @@ class ProjectRequirement:
 
 		return args
 
+class ProjectOption:
+	def __init__ (self, name, option):
+		self._name = str(name)
+		self._option = option
+	
+		if not "default" in option:
+				#TODO: Report lack of default value, default is mandatory
+				return
+			
+		if "description" not in option:
+			#TODO: Report lack of default description as a warning
+			pass
+
+		self._description = str(option["description"])
+		self._default = str(option["default"])
+		self._value = self._default
+
+	def get_name (self):
+		return self._name
+	
+	def get_description (self):
+		return self._description
+	
+	def get_default (self):
+		return self._default
+	
+	def get_value (self):
+		return self._value
+		
+	def set_value (self, value):
+		self._value = value
+		
+		
+	def get_option_arguments (self):
+		"WAF option arguments dictionary"
+		return {"default": self.get_default (),
+		        "action":  "store",
+		        "help":    self.get_description ()}
+
 #Mapping between tools and target classes
 TOOL_CLASS_MAP = {'cc':   CcTarget,
-                  'cxx':   CcTarget,
+                  'c++':  CcTarget,
                   'vala': ValaTarget}
diff --git a/cpprogram.cpp b/cpprogram.cpp
new file mode 100644
index 0000000..5a280a2
--- /dev/null
+++ b/cpprogram.cpp
@@ -0,0 +1,10 @@
+class Bleh {
+public:
+	Bleh () {return;}
+};
+
+int main (int argc, char** argv)
+{
+	Bleh bleh();
+	return 0;
+}
diff --git a/buildj.svg b/data/buildj.svg
similarity index 100%
rename from buildj.svg
rename to data/buildj.svg
diff --git a/project.js b/project.js
index 16ce6fc..c760eaa 100644
--- a/project.js
+++ b/project.js
@@ -5,17 +5,25 @@
 		"version": "0.0.1",
 		"url":     "http://www.codethink.co.uk";
 	},
+	"options":
+	{
+		"foo":
+		{
+			"description": "Sets the foo option",
+			"default":     "True"	
+		}
+	},
 	"requires":
 	{
 		"glib-2.0": {
-			"type": "package",
+			"type":      "package",
 			"mandatory": "True"
 		},
 		"gtk+-2.0": 
 		{
 			"type":      "package",
 			"version":   "2.14",
-			"mandatory": "True"
+			"mandatory": "${foo}"
 		}
 	},
 	"targets":
@@ -29,7 +37,7 @@
 		"my_cpp_program":
 		{
 			"type": "program",
-			"tool": "cxx",
+			"tool": "c++",
 			"input": ["cpprogram.cpp"],
 			"uses": ["my_static_lib"]
 		},
diff --git a/waf b/waf
index 7de776b..2f32b36 100755
Binary files a/waf and b/waf differ
diff --git a/wscript b/wscript
index 9d65c3a..3c47e55 100644
--- a/wscript
+++ b/wscript
@@ -29,7 +29,7 @@ def set_crosscompile_env (prefix, env={}):
 			env[tool] = prefix + "-" + CC_TOOLCHAIN[tool]
 		# Setup various target file patterns
 	
-	#Windows Prefix/suffix
+	#Windows Prefix/suffix (what about bcc and icc?)
 	if ('mingw'  in prefix or
 	    'msvc'   in prefix  or
 	    'cygwin' in prefix or
@@ -54,15 +54,22 @@ def set_crosscompile_env (prefix, env={}):
 def set_options (opt):
 	project = parse_project_file ()
 
+	#BuilDj options
 	opt.add_option('--buildj-file', action='store', default="project.js", help='Sets the BuilDj file.')	
 	opt.add_option('--target-platform', action='store', default=None, help='Sets the target platform tuple used as a prefix for the gcc toolchain.')
+
+  #Project options
+	for option in project.get_options ():
+		opt.add_option("--"+option.get_name (), **option.get_option_arguments ())
 	
+	#Infered options
 	included_tools = []
 	for tool in project.get_tools ():
 		tool = WAF_TOOLS[tool]
 		if tool not in included_tools:
 			opt.tool_options (tool)
 			included_tools.append (tool)
+			
 
 def configure (conf):
 	#Cross compile tests



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