Commit 3800182c authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

wscripts made python3 compatible

parent 524d57bb
......@@ -12,13 +12,16 @@
*.log
.lock-waf*
.waf-*
.waf3-*
build
waf_xcode.sh
exp
src/tests/combinations
params_*
benchmark_results
__pycache__
# Ignored folders for the documentation
_build
doxygen_doc
docs/defaults.rst
......@@ -52,6 +52,7 @@ import time
import threading
import params
import license
from waflib import Logs
from waflib.Tools import waf_unit_test
json_ok = True
......@@ -59,7 +60,7 @@ try:
import simplejson
except:
json_ok = False
print "WARNING simplejson not found some function may not work"
Logs.pprint('YELLOW', 'WARNING: simplejson not found some function may not work')
def add_create_options(opt):
opt.add_option('--dim_in', type='int', dest='dim_in', help='Number of dimensions for the function to optimize [default: 1]')
......@@ -99,7 +100,7 @@ def create_exp(name, opt):
if not os.path.exists('exp'):
os.makedirs('exp')
if os.path.exists('exp/' + name):
print 'ERROR: experiment ' + name + ' already exists. Please remove it if you want to re-create it from scratch.'
Logs.pprint('RED', 'ERROR: experiment \'%s\' already exists. Please remove it if you want to re-create it from scratch.' % name)
return
os.mkdir('exp/' + name)
......@@ -161,7 +162,7 @@ def _sub_script(tpl, conf_file):
ld_lib_path = os.environ['LD_LIBRARY_PATH']
else:
ld_lib_path = "''"
print 'LD_LIBRARY_PATH=' + ld_lib_path
Logs.pprint('NORMAL', 'LD_LIBRARY_PATH=%s' % ld_lib_path)
# parse conf
list_exps = simplejson.load(open(conf_file))
fnames = []
......@@ -200,7 +201,7 @@ def _sub_script(tpl, conf_file):
try:
os.makedirs(directory)
except:
print "WARNING, dir:" + directory + " not be created"
Logs.pprint('YELLOW', 'WARNING: directory \'%s\' could not be created' % directory)
subprocess.call('cp ' + bin_dir + '/' + e + ' ' + directory, shell=True)
src_dir = bin_dir.replace('build/', '')
subprocess.call('cp ' + src_dir + '/params_*.txt ' + directory, shell=True)
......@@ -225,7 +226,7 @@ def _sub_script_local(conf_file):
ld_lib_path = os.environ['LD_LIBRARY_PATH']
else:
ld_lib_path = "''"
print 'LD_LIBRARY_PATH=' + ld_lib_path
Logs.pprint('NORMAL', 'LD_LIBRARY_PATH=%s' % ld_lib_path)
# parse conf
list_exps = simplejson.load(open(conf_file))
fnames = []
......@@ -264,7 +265,7 @@ def _sub_script_local(conf_file):
try:
os.makedirs(directory)
except:
print "WARNING, dir:" + directory + " not be created"
Logs.pprint('YELLOW', 'WARNING: directory \'%s\' could not be created' % directory)
subprocess.call('cp ' + bin_dir + '/' + e + ' ' + '"' + directory + '"', shell=True)
src_dir = bin_dir.replace('build/', '')
subprocess.call('cp ' + src_dir + '/params_*.txt ' + directory, shell=True)
......@@ -282,7 +283,7 @@ def run_local(conf_file, serial = True):
threads = []
for (fname, directory) in fnames:
s = "cd " + '"' + directory + '"' + " && " + "./" + fname + ' ' + arguments
print "Executing " + s
Logs.pprint('NORMAL', "Executing: %s" % s)
if not serial:
t = threading.Thread(target=run_local_one, args=(directory,s,))
threads.append(t)
......@@ -315,9 +316,9 @@ exec @exec
fnames = _sub_script(tpl, conf_file)
for (fname, directory) in fnames:
s = "qsub -d " + directory + " " + fname
print "executing:" + s
Logs.pprint('NORMAL', 'executing: %s' % s)
retcode = subprocess.call(s, shell=True, env=None)
print "qsub returned:" + str(retcode)
Logs.pprint('NORMAL', 'qsub returned: %s' % str(retcode))
def oar(conf_file):
......@@ -329,13 +330,13 @@ def oar(conf_file):
export LD_LIBRARY_PATH=@ld_lib_path
exec @exec
"""
print 'WARNING [oar]: MPI not supported yet'
Logs.pprint('YELLOW', 'WARNING [oar]: MPI not supported yet')
fnames = _sub_script(tpl, conf_file)
for (fname, directory) in fnames:
s = "oarsub -d " + directory + " -S " + fname
print "executing:" + s
Logs.pprint('NORMAL', 'executing: %s' % s)
retcode = subprocess.call(s, shell=True, env=None)
print "oarsub returned:" + str(retcode)
Logs.pprint('NORMAL', 'oarsub returned: %s' % str(retcode))
def output_params(folder):
files = [each for each in os.listdir(folder) if each.endswith('.cpp')]
......
......@@ -101,7 +101,7 @@ def extract_params(fname):
if '}' in line:
level.pop(-1)
if '#if' in line:
ifdefs += [line]
ifdefs += [line]
if '#else' in line:
ifdefs[-1] = 'NOT ' + ifdefs[-1]
if '#elif' in line:
......
......@@ -53,7 +53,7 @@
Usage:
def options(opt):
opt.load('xcode')
opt.load('xcode')
$ waf configure xcode
"""
......@@ -66,221 +66,221 @@ import os, sys, random, time
HEADERS_GLOB = '**/(*.h|*.hpp|*.H|*.inl)'
MAP_EXT = {
'.h' : "sourcecode.c.h",
'.h' : "sourcecode.c.h",
'.hh': "sourcecode.cpp.h",
'.inl': "sourcecode.cpp.h",
'.hpp': "sourcecode.cpp.h",
'.hh': "sourcecode.cpp.h",
'.inl': "sourcecode.cpp.h",
'.hpp': "sourcecode.cpp.h",
'.c': "sourcecode.c.c",
'.c': "sourcecode.c.c",
'.m': "sourcecode.c.objc",
'.m': "sourcecode.c.objc",
'.mm': "sourcecode.cpp.objcpp",
'.mm': "sourcecode.cpp.objcpp",
'.cc': "sourcecode.cpp.cpp",
'.cc': "sourcecode.cpp.cpp",
'.cpp': "sourcecode.cpp.cpp",
'.C': "sourcecode.cpp.cpp",
'.cxx': "sourcecode.cpp.cpp",
'.c++': "sourcecode.cpp.cpp",
'.cpp': "sourcecode.cpp.cpp",
'.C': "sourcecode.cpp.cpp",
'.cxx': "sourcecode.cpp.cpp",
'.c++': "sourcecode.cpp.cpp",
'.l': "sourcecode.lex", # luthor
'.ll': "sourcecode.lex",
'.l': "sourcecode.lex", # luthor
'.ll': "sourcecode.lex",
'.y': "sourcecode.yacc",
'.yy': "sourcecode.yacc",
'.y': "sourcecode.yacc",
'.yy': "sourcecode.yacc",
'.plist': "text.plist.xml",
".nib": "wrapper.nib",
".xib": "text.xib",
'.plist': "text.plist.xml",
".nib": "wrapper.nib",
".xib": "text.xib",
}
def newid():
return "%04X%04X%04X%012d" % (random.randint(0, 32767), random.randint(0, 32767), random.randint(0, 32767), int(time.time()))
return "%04X%04X%04X%012d" % (random.randint(0, 32767), random.randint(0, 32767), random.randint(0, 32767), int(time.time()))
class XCodeNode:
def __init__(self):
self._id = newid()
def tostring(self, value):
if isinstance(value, dict):
result = "{\n"
for k,v in value.iteritems():
result = result + "\t\t\t%s = %s;\n" % (k, self.tostring(v))
result = result + "\t\t}"
return result
elif isinstance(value, str):
return "\"%s\"" % value
elif isinstance(value, list):
result = "(\n"
for i in value:
result = result + "\t\t\t%s,\n" % self.tostring(i)
result = result + "\t\t)"
return result
elif isinstance(value, XCodeNode):
return value._id
else:
return str(value)
def write_recursive(self, value, file):
if isinstance(value, dict):
for k,v in value.iteritems():
self.write_recursive(v, file)
elif isinstance(value, list):
for i in value:
self.write_recursive(i, file)
elif isinstance(value, XCodeNode):
value.write(file)
def write(self, file):
for attribute,value in self.__dict__.iteritems():
if attribute[0] != '_':
self.write_recursive(value, file)
w = file.write
w("\t%s = {\n" % self._id)
w("\t\tisa = %s;\n" % self.__class__.__name__)
for attribute,value in self.__dict__.iteritems():
if attribute[0] != '_':
w("\t\t%s = %s;\n" % (attribute, self.tostring(value)))
w("\t};\n\n")
def __init__(self):
self._id = newid()
def tostring(self, value):
if isinstance(value, dict):
result = "{\n"
for k,v in value.iteritems():
result = result + "\t\t\t%s = %s;\n" % (k, self.tostring(v))
result = result + "\t\t}"
return result
elif isinstance(value, str):
return "\"%s\"" % value
elif isinstance(value, list):
result = "(\n"
for i in value:
result = result + "\t\t\t%s,\n" % self.tostring(i)
result = result + "\t\t)"
return result
elif isinstance(value, XCodeNode):
return value._id
else:
return str(value)
def write_recursive(self, value, file):
if isinstance(value, dict):
for k,v in value.iteritems():
self.write_recursive(v, file)
elif isinstance(value, list):
for i in value:
self.write_recursive(i, file)
elif isinstance(value, XCodeNode):
value.write(file)
def write(self, file):
for attribute,value in self.__dict__.iteritems():
if attribute[0] != '_':
self.write_recursive(value, file)
w = file.write
w("\t%s = {\n" % self._id)
w("\t\tisa = %s;\n" % self.__class__.__name__)
for attribute,value in self.__dict__.iteritems():
if attribute[0] != '_':
w("\t\t%s = %s;\n" % (attribute, self.tostring(value)))
w("\t};\n\n")
# Configurations
class XCBuildConfiguration(XCodeNode):
def __init__(self, name, settings = {}):
XCodeNode.__init__(self)
self.baseConfigurationReference = ""
self.buildSettings = settings
self.name = name
def __init__(self, name, settings = {}):
XCodeNode.__init__(self)
self.baseConfigurationReference = ""
self.buildSettings = settings
self.name = name
class XCConfigurationList(XCodeNode):
def __init__(self, settings):
XCodeNode.__init__(self)
self.buildConfigurations = settings
self.defaultConfigurationIsVisible = 0
self.defaultConfigurationName = settings and settings[0].name or ""
def __init__(self, settings):
XCodeNode.__init__(self)
self.buildConfigurations = settings
self.defaultConfigurationIsVisible = 0
self.defaultConfigurationName = settings and settings[0].name or ""
# Group/Files
class PBXFileReference(XCodeNode):
def __init__(self, name, path, filetype = '', sourcetree = "SOURCE_ROOT"):
XCodeNode.__init__(self)
self.fileEncoding = 4
if not filetype:
_, ext = os.path.splitext(name)
filetype = MAP_EXT.get(ext, 'text')
self.lastKnownFileType = filetype
self.name = name
self.path = path
self.sourceTree = sourcetree
def __init__(self, name, path, filetype = '', sourcetree = "SOURCE_ROOT"):
XCodeNode.__init__(self)
self.fileEncoding = 4
if not filetype:
_, ext = os.path.splitext(name)
filetype = MAP_EXT.get(ext, 'text')
self.lastKnownFileType = filetype
self.name = name
self.path = path
self.sourceTree = sourcetree
class PBXGroup(XCodeNode):
def __init__(self, name, sourcetree = "<group>"):
XCodeNode.__init__(self)
self.children = []
self.name = name
self.sourceTree = sourcetree
def add(self, root, sources):
folders = {}
def folder(n):
if not n.is_child_of(root):
return self
try:
return folders[n]
except KeyError:
f = PBXGroup(n.name)
p = folder(n.parent)
folders[n] = f
p.children.append(f)
return f
for s in sources:
f = folder(s.parent)
source = PBXFileReference(s.name, s.abspath())
f.children.append(source)
def __init__(self, name, sourcetree = "<group>"):
XCodeNode.__init__(self)
self.children = []
self.name = name
self.sourceTree = sourcetree
def add(self, root, sources):
folders = {}
def folder(n):
if not n.is_child_of(root):
return self
try:
return folders[n]
except KeyError:
f = PBXGroup(n.name)
p = folder(n.parent)
folders[n] = f
p.children.append(f)
return f
for s in sources:
f = folder(s.parent)
source = PBXFileReference(s.name, s.abspath())
f.children.append(source)
# Targets
class PBXLegacyTarget(XCodeNode):
def __init__(self, action, target=''):
XCodeNode.__init__(self)
self.buildConfigurationList = XCConfigurationList([XCBuildConfiguration('waf', {})])
if not target:
self.buildArgumentsString = "%s %s" % ("waf_xcode.sh")
else:
self.buildArgumentsString = "%s --targets=%s" % ("waf_xcode.sh", target)
self.buildPhases = []
self.buildToolPath = "/bin/bash" #sys.executable
self.buildWorkingDirectory = ""
self.dependencies = []
self.name = target or action
self.productName = target or action
self.passBuildSettingsInEnvironment = 0
def __init__(self, action, target=''):
XCodeNode.__init__(self)
self.buildConfigurationList = XCConfigurationList([XCBuildConfiguration('waf', {})])
if not target:
self.buildArgumentsString = "%s %s" % ("waf_xcode.sh")
else:
self.buildArgumentsString = "%s --targets=%s" % ("waf_xcode.sh", target)
self.buildPhases = []
self.buildToolPath = "/bin/bash" #sys.executable
self.buildWorkingDirectory = ""
self.dependencies = []
self.name = target or action
self.productName = target or action
self.passBuildSettingsInEnvironment = 0
class PBXShellScriptBuildPhase(XCodeNode):
def __init__(self, action, target):
XCodeNode.__init__(self)
self.buildActionMask = 2147483647
self.files = []
self.inputPaths = []
self.outputPaths = []
self.runOnlyForDeploymentPostProcessing = 0
self.shellPath = "/bin/sh"
self.shellScript = "%s %s %s --targets=%s" % (sys.executable, sys.argv[0], action, target)
def __init__(self, action, target):
XCodeNode.__init__(self)
self.buildActionMask = 2147483647
self.files = []
self.inputPaths = []
self.outputPaths = []
self.runOnlyForDeploymentPostProcessing = 0
self.shellPath = "/bin/sh"
self.shellScript = "%s %s %s --targets=%s" % (sys.executable, sys.argv[0], action, target)
class PBXNativeTarget(XCodeNode):
def __init__(self, action, target, node):
XCodeNode.__init__(self)
conf = XCBuildConfiguration('waf', {'PRODUCT_NAME':target, 'CONFIGURATION_BUILD_DIR':node.parent.abspath()})
self.buildConfigurationList = XCConfigurationList([conf])
self.buildPhases = [PBXShellScriptBuildPhase(action, target)]
self.buildRules = []
self.dependencies = []
self.name = target
self.productName = target
self.productType = "com.apple.product-type.application"
self.productReference = PBXFileReference(target, node.abspath(), 'wrapper.application', 'BUILT_PRODUCTS_DIR')
def __init__(self, action, target, node):
XCodeNode.__init__(self)
conf = XCBuildConfiguration('waf', {'PRODUCT_NAME':target, 'CONFIGURATION_BUILD_DIR':node.parent.abspath()})
self.buildConfigurationList = XCConfigurationList([conf])
self.buildPhases = [PBXShellScriptBuildPhase(action, target)]
self.buildRules = []
self.dependencies = []
self.name = target
self.productName = target
self.productType = "com.apple.product-type.application"
self.productReference = PBXFileReference(target, node.abspath(), 'wrapper.application', 'BUILT_PRODUCTS_DIR')
# Root project object
class PBXProject(XCodeNode):
def __init__(self, name, version):
XCodeNode.__init__(self)
self.buildConfigurationList = XCConfigurationList([XCBuildConfiguration('waf', {})])
self.compatibilityVersion = version[0]
self.hasScannedForEncodings = 1;
self.mainGroup = PBXGroup(name)
self.projectRoot = ""
self.projectDirPath = ""
self.targets = []
self._objectVersion = version[1]
self._output = PBXGroup('out')
self.mainGroup.children.append(self._output)
def write(self, file):
w = file.write
w("// !$*UTF8*$!\n")
w("{\n")
w("\tarchiveVersion = 1;\n")
w("\tclasses = {\n")
w("\t};\n")
w("\tobjectVersion = %d;\n" % self._objectVersion)
w("\tobjects = {\n\n")
XCodeNode.write(self, file)
w("\t};\n")
w("\trootObject = %s;\n" % self._id)
w("}\n")
def add_task_gen(self, tg):
if not getattr(tg, 'mac_app', False):
self.targets.append(PBXLegacyTarget('build', tg.name))
else:
target = PBXNativeTarget('build', tg.name, tg.link_task.outputs[0].change_ext('.app'))
self.targets.append(target)
self._output.children.append(target.productReference)
def __init__(self, name, version):
XCodeNode.__init__(self)
self.buildConfigurationList = XCConfigurationList([XCBuildConfiguration('waf', {})])
self.compatibilityVersion = version[0]
self.hasScannedForEncodings = 1;
self.mainGroup = PBXGroup(name)
self.projectRoot = ""
self.projectDirPath = ""
self.targets = []
self._objectVersion = version[1]
self._output = PBXGroup('out')
self.mainGroup.children.append(self._output)
def write(self, file):
w = file.write
w("// !$*UTF8*$!\n")
w("{\n")
w("\tarchiveVersion = 1;\n")
w("\tclasses = {\n")
w("\t};\n")
w("\tobjectVersion = %d;\n" % self._objectVersion)
w("\tobjects = {\n\n")
XCodeNode.write(self, file)
w("\t};\n")
w("\trootObject = %s;\n" % self._id)
w("}\n")
def add_task_gen(self, tg):
if not getattr(tg, 'mac_app', False):
self.targets.append(PBXLegacyTarget('build', tg.name))
else:
target = PBXNativeTarget('build', tg.name, tg.link_task.outputs[0].change_ext('.app'))
self.targets.append(target)
self._output.children.append(target.productReference)
def create_shell_script():
......@@ -292,67 +292,66 @@ def create_shell_script():
f.close()
class xcode(Build.BuildContext):
cmd = 'xcode'
fun = 'build'
create_shell_script()
def collect_source(self, tg):
source_files = tg.to_nodes(getattr(tg, 'source', []))
plist_files = tg.to_nodes(getattr(tg, 'mac_plist', []))
resource_files = [tg.path.find_node(i) for i in Utils.to_list(getattr(tg, 'mac_resources', []))]
include_dirs = Utils.to_list(getattr(tg, 'includes', [])) + Utils.to_list(getattr(tg, 'export_dirs', []))
include_files = []
for x in include_dirs:
if not isinstance(x, str):
include_files.append(x)
continue
d = tg.path.find_node(x)
if d:
lst = [y for y in d.ant_glob(HEADERS_GLOB, flat=False)]
include_files.extend(lst)
# remove duplicates
source = list(set(source_files + plist_files + resource_files + include_files))
source.sort(key=lambda x: x.abspath())
return source
def execute(self):
"""
Entry point
"""
self.restore()
if not self.all_envs:
self.load_envs()
self.recurse([self.run_dir])
appname = getattr(Context.g_module, Context.APPNAME, os.path.basename(self.srcnode.abspath()))
p = PBXProject(appname, ('Xcode 3.2', 46))
for g in self.groups:
for tg in g:
if not isinstance(tg, TaskGen.task_gen):
continue
tg.post()
features = Utils.to_list(getattr(tg, 'features', ''))
group = PBXGroup(tg.name)
group.add(tg.path, self.collect_source(tg))
p.mainGroup.children.append(group)
if 'cprogram' or 'cxxprogram' in features:
p.add_task_gen(tg)
# targets that don't produce the executable but that you might want to run
p.targets.append(PBXLegacyTarget('configure'))
p.targets.append(PBXLegacyTarget('dist'))