def generate_all_cpp(source): target=os.path.join("src") tools.mkdir(target) for module, g in tools.get_modules(source): sources= tools.get_glob([os.path.join(g, "src", "*.cpp")])\ +tools.get_glob([os.path.join(g, "src", "internal", "*.cpp")]) targetf=os.path.join(target, module+"_all.cpp") sources.sort() tools.rewrite(targetf, "\n".join(["#include <%s>"%os.path.abspath(s) for s in sources]) + '\n')
def generate_all_cpp(source): target = os.path.join("src") tools.mkdir(target) for module, g in tools.get_modules(source): sources = tools.get_glob([os.path.join(g, "src", "*.cpp")])\ + tools.get_glob([os.path.join(g, "src", "internal", "*.cpp")]) targetf = os.path.join(target, module + "_all.cpp") sources.sort() tools.rewrite( targetf, "\n".join(["#include <%s>" % os.path.abspath(s) for s in sources]) + '\n')
def generate_all_cpp(modules): target = os.path.join("src") tools.mkdir(target) gen = tools.CPPFileGenerator() for module in modules: sources = tools.get_glob([os.path.join(module.path, "src", "*.cpp")])\ + tools.get_glob([os.path.join(module.path, "src", "internal", "*.cpp")]) targetf = os.path.join(target, module.name + "_all.cpp") sources.sort() gen.write(targetf, "\n".join(["#include <%s>" % os.path.abspath(s) for s in sources]) + '\n')
def main(): (options, args) = parser.parse_args() if not os.path.exists( os.path.join(options.source, "modules", options.module)): print "Skipping alias as original module not found" return print "Setting up alias for module", options.module, "as", options.alias tools.mkdir("include/IMP/%s" % options.alias) tools.mkdir("include/IMP/%s/internal" % options.alias) var = {"module": options.module} if options.deprecate != "": var["deprecate"] = "IMP%s_DEPRECATED_HEADER(%s, \"%s\")" % ( options.module.upper(), options.deprecate, "Use the one in IMP/%s instead." % options.module) else: var["deprecate"] = "" if options.alias == "": var["namespacebegin"] = "namespace IMP {" var["namespaceend"] = "}" var["slashalias"] = "" else: var["namespacebegin"] = "namespace IMP { namespace %s {" % options.alias var["namespaceend"] = "} }" var["slashalias"] = "/" + options.alias for h in tools.get_glob( [os.path.join("include", "IMP", options.module, "*.h")]): if h.endswith("_config.h"): continue filename = os.path.split(h)[1] var["file"] = filename header = header_template % var tools.rewrite("include/IMP%s/%s" % (var["slashalias"], filename), header) # Remove aliased header if the source header is gone for h in glob.glob("include/IMP%s/*.h" % var["slashalias"]): filename = os.path.split(h)[1] orig_filename = os.path.join("include", "IMP", options.module, filename) if not os.path.exists(orig_filename) \ and not os.path.exists(h[:-2]): # Exclude all-module headers os.unlink(h) for h in tools.get_glob( [os.path.join("include", "IMP", options.module, "internal", "*.h")]): filename = os.path.split(h)[1] var["file"] = filename header = internal_header_template % var tools.rewrite("include/IMP/%s/internal/%s" % (options.alias, filename), header) allh = allh_template % var tools.rewrite("include/IMP%s.h" % var["slashalias"], allh)
def setup_module(module, source, datapath): sys.stdout.write("Configuring module %s ..." % module) data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print("Required dependency %s not found" % d) write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print("Required module IMP.%s not available" % d) write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) moddir = os.path.join('IMP', '' if module == 'kernel' else module) swig_includes = [os.path.split(x)[1] for x in tools.get_glob( [os.path.join(source, "modules", module, "pyext", "include", "*.i")])] \ + [os.path.join(moddir, os.path.split(x)[1]) for x in tools.get_glob( [os.path.join("include", moddir, "*_macros.h")])] swig_wrapper_includes = [os.path.join(moddir, "internal", os.path.split(x)[1]) for x in tools.get_glob( [os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def main(): (options, args) = parser.parse_args() if not os.path.exists(os.path.join(options.source, "modules", options.module)): print("Skipping alias as original module not found") return print("Setting up alias for module", options.module, "as", options.alias) tools.mkdir("include/IMP/%s" % options.alias) tools.mkdir("include/IMP/%s/internal" % options.alias) var = {"module": options.module} if options.deprecate != "": var["deprecate"] = "IMP%s_DEPRECATED_HEADER(%s, \"%s\")" % (options.module.upper(), options.deprecate, "Use the one in IMP/%s instead." % options.module) else: var["deprecate"] = "" if options.alias == "": var["namespacebegin"] = "namespace IMP {" var["namespaceend"] = "}" var["slashalias"] = "" else: var["namespacebegin"] = "namespace IMP { namespace %s {" % options.alias var["namespaceend"] = "} }" var["slashalias"] = "/" + options.alias for h in tools.get_glob([os.path.join("include", "IMP", options.module, "*.h")]): if h.endswith("_config.h"): continue filename = os.path.split(h)[1] var["file"] = filename header = header_template % var tools.rewrite( "include/IMP%s/%s" % (var["slashalias"], filename), header) # Remove aliased header if the source header is gone for h in glob.glob("include/IMP%s/*.h" % var["slashalias"]): filename = os.path.split(h)[1] orig_filename = os.path.join("include", "IMP", options.module, filename) if not os.path.exists(orig_filename) \ and not os.path.exists(h[:-2]): # Exclude all-module headers os.unlink(h) for h in tools.get_glob([os.path.join("include", "IMP", options.module, "internal", "*.h")]): filename = os.path.split(h)[1] var["file"] = filename header = internal_header_template % var tools.rewrite( "include/IMP/%s/internal/%s" % (options.alias, filename), header) allh = allh_template % var tools.rewrite("include/IMP%s.h" % var["slashalias"], allh)
def setup_module(module, finder): sys.stdout.write("Configuring module %s ..." % module.name) for d in module.required_dependencies: if not finder.get_dependency_info(d)["ok"]: print("Required dependency %s not found" % d) write_no_ok(module.name) return False, [] dependencies = module.required_dependencies[:] unfound_dependencies = [] for d in module.optional_dependencies: if finder.get_dependency_info(d)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in module.required_modules: if not d.configured.ok: print("Required module IMP.%s not available" % d.name) write_no_ok(module.name) return False, [] modules = module.required_modules[:] unfound_modules = [] for d in module.optional_modules: if d.configured.ok: modules.append(d) else: unfound_modules.append(d) all_modules = finder.get_dependent_modules(modules) moddir = os.path.join('IMP', '' if module.name == 'kernel' else module.name) swig_includes = [os.path.split(x)[1] for x in tools.get_glob( [os.path.join(module.path, "pyext", "include", "*.i")])] \ + [os.path.join(moddir, os.path.split(x)[1]) for x in tools.get_glob( [os.path.join("include", moddir, "*_macros.h")])] swig_wrapper_includes = [os.path.join(moddir, "internal", os.path.split(x)[1]) for x in tools.get_glob( [os.path.join(module.path, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module.name)) tools.mkdir(os.path.join("src", module.name + "_swig")) write_ok(module, all_modules, unfound_modules, finder.get_dependent_dependencies(all_modules, dependencies), unfound_dependencies, swig_includes, swig_wrapper_includes, module.python_only) return True, all_modules
def link_bin(options): path = os.path.join("module_bin", options.name) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): os.unlink(old) tools.link_dir(os.path.join(options.source, "modules", options.name, "bin"), path, clean=False, match=["*.py"])
def get_sources(module, path, subdir, pattern): matching = tools.get_glob([ os.path.join(path, subdir, pattern), os.path.join(path, subdir, "*", pattern) ]) return "\n".join( ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) for x in matching])
def link_benchmark(options, module): path = os.path.join("benchmark", options.name) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): os.unlink(old) tools.link_dir(os.path.join(module.path, "benchmark"), path, clean=False, match=["*.py"])
def generate_all_h(): globbed = tools.get_glob([os.path.join("include", "IMP", "*")]) for m in [d for d in globbed if (d.find("internal") == -1 and not d.endswith(".h"))]: headers= tools.get_glob([os.path.join(m, "*.h")]) module=os.path.split(m)[1] if module=="compatibility": # ick, maybe switch order and always do it here continue includepath="IMP/"+module+"/" headers.sort() headers= [x for x in headers if not x.endswith("_config.h")] contents=[] for h in headers: name= os.path.split(h)[1] contents.append("#include <"+includepath+name+">") tools.rewrite(m+".h", "\n".join(contents) + '\n')
def main(): # glob.glob(os.path.join("build", "doxygen", "xml", "*.xml")): if len(sys.argv) > 1: files = sys.argv[1:] else: files = tools.get_glob( [os.path.join("doxygen", "ref", "xml", "*.xml")]) for f in files: # for f in ["doxygen/xml/classIMP_1_1atom_1_1LennardJones.xml"]: #["doxygen/xml/namespacetiny.xml", # "doxygen/xml/classIMP_1_1display_1_1Color.xml"]: module = os.path.split(os.path.split(os.path.split(f)[0])[0])[1] try: et = ET.parse(f) except ET.ParseError: sys.stderr.write("ERROR parsing", f, "\n") fname = os.path.basename(f) if fname.startswith("namespaceIMP"): if verbose: print("namespace", fname) traverse_namespace(get_namespace_name(et.getroot()), et.getroot(), module) # elif fname.startswith("namespace"): # if verbose: # print "example 1", fname #traverse_example(get_example_name(et.getroot()), et.getroot()) elif fname.endswith("example.xml"): if verbose: print("example 2", fname) traverse_example_2(get_example_2_name(et.getroot()), et.getroot()) # skip structs for nwo elif fname.startswith("classIMP"): if verbose: print("class", fname) traverse_class(get_file_class_name(et.getroot()), et.getroot(), module) else: if verbose: print("skipping", fname) indexes = [("Factory Index", "factory_index"), ("Argument Index", "argument_index"), ("Class Examples", "class_example_index"), ("Function Examples", "function_example_index")] create_index(indexes[0][0], indexes[0][1], indexes[1:], "Functions that create objects of a given type:", creates, "doxygen/generated/factory_index.md", "Class", "Factories") create_index(indexes[1][0], indexes[1][1], indexes, "Functions that take objects of a given type as arguments:", takes, "doxygen/generated/argument_index.md", "Class", "Users") create_index(indexes[2][0], indexes[2][1], indexes, "Examples that use a given class:", examples_classes, "doxygen/generated/class_example_index.md", "Class", "Examples") create_index(indexes[3][0], indexes[3][1], indexes[:-1], "Examples that use a given function:", examples_functions, "doxygen/generated/function_example_index.md", "Function", "Examples")
def report_python_module(cov, modname, srcdir, outdir): mods = glob.glob('lib/IMP/%s/*.py' % modname) \ + glob.glob('lib/IMP/%s/*/*.py' % modname) mods = [x for x in mods if not x.endswith('_version_check.py')] bins = tools.get_glob( [os.path.join(srcdir, 'modules', modname, 'bin', '*')]) bins = [os.path.basename(x) for x in bins if tools.filter_pyapps(x)] bins = [os.path.join('bin', x) for x in bins if x != 'dependencies.py'] report_python_component(cov, mods + bins, modname, 'module', '', outdir)
def generate_applications_list(source): apps= tools.get_glob([os.path.join(source, "applications", "*")]) names=[] for a in apps: if os.path.isdir(a): name= os.path.split(a)[1] names.append(name) path=os.path.join("data", "build_info", "applications") tools.rewrite(path, "\n".join(names))
def generate_applications_list(source): apps = tools.get_glob([os.path.join(source, "applications", "*")]) names = [] for a in apps: if os.path.isdir(a): name = os.path.split(a)[1] names.append(name) path = os.path.join("data", "build_info", "applications") tools.rewrite(path, "\n".join(names))
def setup_module(module, source, datapath): sys.stdout.write("Configuring module %s ..." % module) data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print("Required dependency %s not found" % d) write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print("Required module IMP.%s not available" % d) write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) moddir = os.path.join('IMP', '' if module == 'kernel' else module) swig_includes = [os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + [os.path.join(moddir, os.path.split(x)[1]) for x in tools.get_glob([os.path.join("include", moddir, "*_macros.h")])] swig_wrapper_includes = [os.path.join(moddir, "internal", os.path.split(x)[1]) for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies( all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def main(): # glob.glob(os.path.join("build", "doxygen", "xml", "*.xml")): if len(sys.argv) > 1: files= sys.argv[1:] else: files=tools.get_glob([os.path.join("doxygen", "xml", "*.xml")]) for f in files: #for f in ["doxygen/xml/classIMP_1_1atom_1_1LennardJones.xml"]: #["doxygen/xml/namespacetiny.xml", # "doxygen/xml/classIMP_1_1display_1_1Color.xml"]: module = os.path.split(os.path.split(os.path.split(f)[0])[0])[1] try: et= ET.parse(f) except ET.ParseError: print >> sys.stderr, "ERROR parsing", f fname=os.path.basename(f) if fname.startswith("namespaceIMP"): if verbose: print "namespace", fname traverse_namespace(get_namespace_name(et.getroot()), et.getroot(), module) #elif fname.startswith("namespace"): #if verbose: # print "example 1", fname #traverse_example(get_example_name(et.getroot()), et.getroot()) elif fname.endswith("example.xml"): if verbose: print "example 2", fname traverse_example_2(get_example_2_name(et.getroot()), et.getroot()) # skip structs for nwo elif fname.startswith("classIMP"): if verbose: print "class", fname traverse_class(get_file_class_name(et.getroot()), et.getroot(), module) else: if verbose: print "skipping", fname indexes = [("Factory Index", "factory_index"), ("Argument Index", "argument_index"), ("Class Examples", "class_example_index"), ("Function Examples", "function_example_index")] create_index(indexes[0][0], indexes[0][1], indexes[1:], "Functions that create objects of a given type:", creates, "doxygen/generated/factory_index.md", "Class", "Factories") create_index(indexes[1][0], indexes[1][1], indexes, "Functions that take objects of a given type as arguments:", takes, "doxygen/generated/argument_index.md", "Class", "Users") create_index(indexes[2][0], indexes[2][1], indexes, "Examples that use a given class:", examples_classes, "doxygen/generated/class_example_index.md", "Class", "Examples") create_index(indexes[3][0], indexes[3][1], indexes[:-1], "Examples that use a given function:", examples_functions, "doxygen/generated/function_example_index.md", "Function", "Examples")
def setup_module(module, source, datapath): print "Configuring module", module, "...", data = tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print d, "not found" write_no_ok(module) return False, [] dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print "IMP." + d, "not found" write_no_ok(module) return False, [] modules = data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules = tools.get_dependent_modules(modules, datapath) swig_includes = [os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + ["IMP/" + module + "/" + os.path.split(x)[1] for x in tools.get_glob([os.path.join("include", "IMP", module, "*_macros.h")])] swig_wrapper_includes = ["IMP/" + module + "/internal/" + os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module + "_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies( all_modules, dependencies, datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True, all_modules
def setup_module(module, source, datapath): print "Configuring module", module, "...", data= tools.get_module_description(source, module, datapath) for d in data["required_dependencies"]: if not tools.get_dependency_info(d, datapath)["ok"]: print d, "not found" write_no_ok(module) return False dependencies = data["required_dependencies"] unfound_dependencies = [] for d in data["optional_dependencies"]: if tools.get_dependency_info(d, datapath)["ok"]: dependencies.append(d) else: unfound_dependencies.append(d) for d in data["required_modules"]: if not tools.get_module_info(d, datapath)["ok"]: print "IMP."+d, "not found" write_no_ok(module) return False modules= data["required_modules"] unfound_modules = [] for d in data["optional_modules"]: if tools.get_module_info(d, datapath)["ok"]: modules.append(d) else: unfound_modules.append(d) all_modules=tools.get_dependent_modules(modules, datapath) swig_includes=[os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "pyext", "include", "*.i")])]\ + ["IMP/"+module+"/"+os.path.split(x)[1] for x in tools.get_glob([os.path.join("include", "IMP", module, "*_macros.h")])] swig_wrapper_includes= ["IMP/"+module+"/internal/"+os.path.split(x)[1] for x in tools.get_glob([os.path.join(source, "modules", module, "include", "internal", "swig*.h")])] tools.mkdir(os.path.join("src", module)) tools.mkdir(os.path.join("src", module+"_swig")) write_ok(module, all_modules, unfound_modules, tools.get_dependent_dependencies(all_modules, dependencies,datapath), unfound_dependencies, swig_includes, swig_wrapper_includes) return True
def link_python(source): target=os.path.join("lib") tools.mkdir(target, clean=False) for module, g in tools.get_modules(source): path= os.path.join(target, "IMP", module) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): # don't unlink the generated file if os.path.split(old)[1] != "__init__.py" and os.path.split(old)[1] != "_version_check.py": os.unlink(old) #print "linking", path tools.link_dir(os.path.join(g, "pyext", "src"), path, clean=False)
def report_python_module(cov, modname, srcdir, outdir): if modname == 'kernel': mods = glob.glob('lib/IMP/*.py') else: mods = glob.glob('lib/IMP/%s/*.py' % modname) \ + glob.glob('lib/IMP/%s/*/*.py' % modname) mods = [x for x in mods if not x.endswith('_version_check.py')] bins = tools.get_glob([os.path.join(srcdir, 'modules', modname, 'bin', '*')]) bins = [os.path.basename(x) for x in bins if tools.filter_pyapps(x)] bins = [os.path.join('bin', x) for x in bins if x != 'dependencies.py'] report_python_component(cov, mods + bins, modname, 'module', '', outdir)
def link_python(source): target = os.path.join("lib") tools.mkdir(target, clean=False) for module, g in tools.get_modules(source): path = os.path.join(target, "IMP", module) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): # don't unlink the generated file if os.path.split(old)[1] != "__init__.py" and os.path.split( old)[1] != "_version_check.py": os.unlink(old) # print "linking", path tools.link_dir(os.path.join(g, "pyext", "src"), path, clean=False)
def link_benchmark(options): path = os.path.join("benchmark", options.name) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): os.unlink(old) tools.link_dir( os.path.join(options.source, "modules", options.name, "benchmark"), path, clean=False, match=["*.py"])
def main(): (options, args) = parser.parse_args() main = [] ordered = tools.compute_sorted_order(".", "") for m in ordered: """if m not in ["base", "kernel", "algebra", "cgal", "test", "statistics", "display", "core", "kmeans", "score_functor", "container", "atom", "rmf", "domino", "example"]: continue""" p = os.path.join("modules", m) main.append(setup_module(m, p, ordered)) for a in [x for x in tools.get_glob([os.path.join("applications", "*")]) if os.path.isdir(x)]: main.append(setup_application(options, os.path.split(a)[1], ordered))
def make_one(path, params, test=True): ( function_name, type_name, class_name, variable_type, argument_type, return_type, storage_type, plural_variable_type, plural_argument_type, plural_storage_type, index_type, plural_index_type, pass_index_type, ) = params multi = class_name plural_multi = multi + "s" cname = function_name inputs = tools.get_glob( [ os.path.join(path, "*", "*.h"), os.path.join(path, "*", "internal", "*.h"), os.path.join(path, "*", "*.cpp"), os.path.join(path, "*", "internal", "*.cpp"), ] ) files = [] for ip in inputs: p = ip[len(path) + 1 :] module = os.path.split(p)[0] rest = os.path.split(p)[1] if module.find("internal") != -1: module = os.path.split(module)[0] rest = os.path.join("internal", rest) name = filter(params, rest, rest) if p.endswith(".h"): out_path = os.path.join("include", "IMP", "" if module == "kernel" else module, name) else: out_path = os.path.join("src", module, name) files.append((out_path, ip)) if test: files.append(("test/container/test_" + cname + "_restraint.py", path + "/test.py")) files.append(("test/container/test_" + cname + "_state.py", path + "/test_state.py")) for p in files: g = ContainerFileGenerator(p[1]) g.write(p[0], params) all_outputs.append(p[0]) all_inputs.append(p[1])
def main(): (options, args) = parser.parse_args() main = [] ordered = tools.compute_sorted_order(".", "") for m in ordered: """if m not in ["base", "kernel", "algebra", "cgal", "test", "statistics", "display", "core", "kmeans", "score_functor", "container", "atom", "rmf", "domino", "example"]: continue""" p = os.path.join("modules", m) main.append(setup_module(m, p, ordered)) for a in [ x for x in tools.get_glob([os.path.join("applications", "*")]) if os.path.isdir(x) ]: main.append(setup_application(options, os.path.split(a)[1], ordered))
def link_python(modules): target = os.path.join("lib") tools.mkdir(target, clean=False) for module in modules: path = os.path.join(target, "IMP", '' if module.name == 'kernel' else module.name) tools.mkdir(path, clean=False) for old in tools.get_glob([os.path.join(path, "*.py")]): # don't unlink the generated file if os.path.split(old)[1] != "__init__.py" and os.path.split( old)[1] != "_version_check.py": os.unlink(old) # print "linking", path tools.link_dir(os.path.join(module.path, "pyext", "src"), path, clean=False, make_subdirs=True)
def make_one(path, params, test=True): (function_name, type_name, class_name, variable_type, argument_type, return_type, storage_type, plural_variable_type, plural_argument_type, plural_storage_type, index_type, plural_index_type, pass_index_type) = params multi = class_name plural_multi = multi + "s" cname = function_name inputs = tools.get_glob([ os.path.join(path, "*", "*.h"), os.path.join(path, "*", "internal", "*.h"), os.path.join(path, "*", "*.cpp"), os.path.join(path, "*", "internal", "*.cpp") ]) files = [] for ip in inputs: p = ip[len(path) + 1:] module = os.path.split(p)[0] rest = os.path.split(p)[1] if module.find("internal") != -1: module = os.path.split(module)[0] rest = os.path.join("internal", rest) name = filter(params, rest, rest) if p.endswith(".h"): out_path = os.path.join("include", "IMP", '' if module == 'kernel' else module, name) else: out_path = os.path.join("src", module, name) files.append((out_path, ip)) if test: files.append(("test/container/test_" + cname + "_restraint.py", path + "/test.py")) files.append(("test/container/test_" + cname + "_state.py", path + "/test_state.py")) for p in files: g = ContainerFileGenerator(p[1]) g.write(p[0], params) all_outputs.append(tools.to_cmake_path(p[0])) all_inputs.append(tools.to_cmake_path(p[1]))
def make_one(source, params, test=True): (function_name, type_name, class_name, variable_type, argument_type, return_type, storage_type, plural_variable_type, plural_argument_type, plural_storage_type, index_type, plural_index_type, pass_index_type)= params path= os.path.join(source, "tools", "build", "container_templates") multi= class_name plural_multi= multi+"s" cname=function_name inputs= tools.get_glob([os.path.join(path,"*", "*.h"), \ os.path.join(path,"*", "internal", "*.h"), \ os.path.join(path,"*", "*.cpp"), os.path.join(path,"*", "internal", "*.cpp")]) files=[] for ip in inputs: p= ip[len(path)+1:] module= os.path.split(p)[0] rest= os.path.split(p)[1] if module.find("internal") != -1: module=os.path.split(module)[0] rest=os.path.join("internal", rest) name=filter(params, rest, rest) if p.endswith(".h"): out_path= os.path.join("include", "IMP", module, name) else: out_path= os.path.join("src", module, name) files.append((out_path, ip)) if test: files.append(("test/container/test_"+cname + "_restraint.py", path+"/test.py")) files.append(("test/container/test_"+cname + "_state.py", path+"/test_state.py")) for p in files: contents = filter(params, open(p[1], 'r').read(), p[1]) tools.rewrite(p[0], contents)
def setup_module(module, path, ordered): checks = [] deps = [] contents = [] defines = [] for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]): ret = make_check(cc, module, path) checks.append(ret[0]) defines.append(ret[1]) for cc in tools.get_glob([os.path.join(path, "dependency", "*.description")]): ret = make_dependency_check(cc, module, path) if ret: deps.append(ret) g = tools.CMakeFileGenerator() if len(checks) > 0: g.write("modules/%s/compiler/CMakeLists.txt" % module, "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x) for x in checks])) contents.append( "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" % module) if len(deps) > 0: g.write("modules/%s/dependency/CMakeLists.txt" % module, "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x) for x in deps])) contents.append( "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" % module) local = os.path.join(path, "Setup.cmake") if os.path.exists(local): contents.append("include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(local)) values = {"name": module} if module == 'kernel': values['subdir'] = 'IMP' values['pymod'] = 'IMP' values['allh_header'] = 'IMP.h' else: values['subdir'] = 'IMP/' + module values['pymod'] = 'IMP.' + module values['allh_header'] = 'IMP/%s.h' % module values["NAME"] = module.upper() values["CPPNAME"] = module.upper().replace('_', '') data = tools.get_module_description(".", module, "") all_modules = tools.get_all_modules(".", [module], "", ordered) modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules] dependencies = ["${%s_LIBRARIES}" % s.upper() for s in tools.get_all_dependencies(".", [module], "", ordered)] values["modules"] = ";".join(modules) values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules]) values["other_pythons"] = "\n".join( ["${IMP_%s_PYTHON}" % m for m in all_modules]) values["dependencies"] = ";".join(dependencies) values["headers"] = get_sources(module, path, "include", "*.h") values["includepath"] = get_dep_merged([module], "include_path", ordered) values["libpath"] = get_dep_merged([module], "link_path", ordered) values["swigpath"] = get_dep_merged([module], "swig_path", ordered) values["defines"] = ":".join(defines) cppbins = tools.get_glob([os.path.join(path, "bin", "*.cpp")]) cppbins = [os.path.splitext(e)[0] for e in cppbins] pybins = get_app_sources(os.path.join(path, "bin"), ["*"], tools.filter_pyapps) values["pybins"] = "\n".join(pybins) values["bin_names"] = "\n".join([os.path.basename(x) \ for x in pybins + cppbins]) main = os.path.join(path, "src", "CMakeLists.txt") tests = os.path.join(path, "test", "CMakeLists.txt") swig = os.path.join(path, "pyext", "CMakeLists.txt") util = os.path.join(path, "utility", "CMakeLists.txt") bin = os.path.join(path, "bin", "CMakeLists.txt") benchmark = os.path.join(path, "benchmark", "CMakeLists.txt") examples = os.path.join(path, "examples", "CMakeLists.txt") lib_template.write(main, values) test_template.write(tests, values) swig_template.write(swig, values) util_template.write(util, values) bin_template.write(bin, values) benchmark_template.write(benchmark, values) examples_template.write(examples, values) values["tests"] = "\n".join(contents) values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/utility)""" % ((module,) * 6) out = os.path.join(path, "CMakeLists.txt") module_template.write(out, values) # at end so directories exist cmd = subprocess.Popen( ["python", os.path.join( "..", "..", "tools", "dev_tools", "setup_cmake.py")], cwd=path, universal_newlines=True) return out
def setup_module(module, path, ordered): checks = [] deps = [] contents = [] defines = [] for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]): ret = make_check(cc, module, path) checks.append(ret[0]) defines.append(ret[1]) for cc in tools.get_glob( [os.path.join(path, "dependency", "*.description")]): ret = make_dependency_check(cc, module, path) if ret: deps.append(ret) if len(checks) > 0: tools.rewrite( "modules/%s/compiler/CMakeLists.txt" % module, "\n".join([ "include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x) for x in checks ])) contents.append( "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" % module) if len(deps) > 0: tools.rewrite( "modules/%s/dependency/CMakeLists.txt" % module, "\n".join([ "include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x) for x in deps ])) contents.append( "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" % module) local = os.path.join(path, "Setup.cmake") if os.path.exists(local): contents.append("include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(local)) values = {"name": module} values["NAME"] = module.upper() values["CPPNAME"] = module.upper().replace('_', '') data = tools.get_module_description(".", module, "") all_modules = tools.get_all_modules(".", [module], "", ordered) modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules] dependencies = [ "${%s_LIBRARIES}" % s.upper() for s in tools.get_all_dependencies(".", [module], "", ordered) ] values["modules"] = ";".join(modules) values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules]) values["other_pythons"] = "\n".join( ["${IMP_%s_PYTHON}" % m for m in all_modules]) values["dependencies"] = ";".join(dependencies) values["headers"] = get_sources(module, path, "include", "*.h") values["includepath"] = get_dep_merged([module], "include_path", ordered) values["libpath"] = get_dep_merged([module], "link_path", ordered) values["swigpath"] = get_dep_merged([module], "swig_path", ordered) values["defines"] = ":".join(defines) cppbins = tools.get_glob([os.path.join(path, "bin", "*.cpp")]) cppbins = [os.path.splitext(e)[0] for e in cppbins] pybins = get_app_sources(os.path.join(path, "bin"), ["*"], tools.filter_pyapps) values["pybins"] = "\n".join(pybins) values["bin_names"] = "\n".join([os.path.basename(x) \ for x in pybins + cppbins]) main = os.path.join(path, "src", "CMakeLists.txt") tests = os.path.join(path, "test", "CMakeLists.txt") swig = os.path.join(path, "pyext", "CMakeLists.txt") util = os.path.join(path, "utility", "CMakeLists.txt") bin = os.path.join(path, "bin", "CMakeLists.txt") benchmark = os.path.join(path, "benchmark", "CMakeLists.txt") examples = os.path.join(path, "examples", "CMakeLists.txt") tools.rewrite(main, lib_template % values) tools.rewrite(tests, test_template % values) tools.rewrite(swig, swig_template % values) tools.rewrite(util, util_template % values) tools.rewrite(bin, bin_template % values) tools.rewrite(benchmark, benchmark_template % values) tools.rewrite(examples, examples_template % values) values["tests"] = "\n".join(contents) values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/utility)""" % ((module, ) * 6) out = os.path.join(path, "CMakeLists.txt") tools.rewrite(out, module_template % values) # at end so directories exist cmd = subprocess.Popen([ "python", os.path.join("..", "..", "tools", "dev_tools", "setup_cmake.py") ], cwd=path, universal_newlines=True) return out
def get_app_sources(path, patterns, filt=lambda x:True): matching = tools.get_glob([os.path.join(path, x) for x in patterns]) return ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) \ for x in matching if filt(x)]
def report_python_application(cov, app, srcdir, outdir): mods = tools.get_glob([os.path.join(srcdir, 'applications', app, '*')]) mods = [x for x in mods if tools.filter_pyapps(x)] mods = [os.path.basename(x) for x in mods] mods = [os.path.join('bin', x) for x in mods if x != 'dependencies.py'] report_python_component(cov, mods, app, 'application', '', outdir)
def get_app_sources(path, patterns, filt=lambda x: True): matching = tools.get_glob([os.path.join(path, x) for x in patterns]) return ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) \ for x in matching if filt(x)]
def get_path(self): modbin = [os.path.abspath(x) for x in tools.get_glob(["module_bin/*"])] if self.options.suffix: modbin += [os.path.join(x, self.options.suffix) for x in modbin] return (modbin + [self.get_abs_binary_path("bin")] + self.native_paths(self.options.path, True))
def report_python_application(cov, app, srcdir, outdir): mods = tools.get_glob([os.path.join(srcdir, 'applications', app, '*.py')]) mods = [os.path.join('bin', os.path.basename(x)) for x in mods] report_python_component(cov, mods, app, 'application', '', outdir)
def generate_tests(source, scons): template = """import IMP import IMP.test import %(module)s spelling_exceptions=%(spelling_exceptions)s class StandardsTest(IMP.test.TestCase): def test_value_objects(self): "Test that module classes are either values or objects" exceptions= %(value_object_exceptions)s return self.assertValueObjects(%(module)s,exceptions) def test_classes(self): "Test that module class names follow the standards" exceptions=%(value_object_exceptions)s return self.assertClassNames(%(module)s, exceptions, spelling_exceptions) def test_functions(self): "Test that module function names follow the standards" exceptions= %(function_name_exceptions)s return self.assertFunctionNames(%(module)s, exceptions, spelling_exceptions) def test_show(self): "Test all objects have show" exceptions=%(show_exceptions)s return self.assertShow(%(module)s, exceptions) if __name__ == '__main__': IMP.test.main() """ target = os.path.join("test") tools.mkdir(target) for module, g in tools.get_modules(source): targetdir = os.path.join(target, module) tools.mkdir(targetdir) exceptions = os.path.join(g, "test", "standards_exceptions") d = { 'plural_exceptions': [], 'show_exceptions': [], 'function_name_exceptions': [], 'value_object_exceptions': [], 'class_name_exceptions': [], 'spelling_exceptions': [] } try: exec(open(exceptions, "r").read(), d) except IOError: pass impmodule = "IMP" if module == 'kernel' else "IMP." + module test = template % ( { 'module': impmodule, 'plural_exceptions': str(d['plural_exceptions']), 'show_exceptions': str(d['show_exceptions']), 'function_name_exceptions': str(d['function_name_exceptions']), 'value_object_exceptions': str(d['value_object_exceptions']), 'class_name_exceptions': str(d['class_name_exceptions']), 'spelling_exceptions': str(d['spelling_exceptions']) }) gen = tools.PythonFileGenerator() gen.write(os.path.join("test", module, "medium_test_standards.py"), test, show_diff=False) cpptests = tools.get_glob([os.path.join(g, "test", "test_*.cpp")]) ecpptests = tools.get_glob( [os.path.join(g, "test", "expensive_test_*.cpp")]) cppexamples = tools.get_glob([os.path.join(g, "examples", "*.cpp")]) if len(cpptests) > 0 and scons: _make_test_driver(os.path.join(targetdir, "test_cpp_tests.py"), cpptests) if len(ecpptests) > 0 and scons: _make_test_driver( os.path.join(targetdir, "expensive_test_cpp_tests.py"), cpptests) if len(cppexamples) > 0 and scons: _make_test_driver(os.path.join(targetdir, "cpp_examples_test.py"), cppexamples)
def clean_pyc(dir): for root, dirnames, filenames in os.walk('.'): for d in dirnames: for f in tools.get_glob([os.path.join(d, "*.pyc")]): os.unlink(f)
def generate_tests(source, scons): template = """import IMP import IMP.test import %(module)s spelling_exceptions=%(spelling_exceptions)s class StandardsTest(IMP.test.TestCase): def test_value_objects(self): "Test that module classes are either values or objects" exceptions= %(value_object_exceptions)s return self.assertValueObjects(%(module)s,exceptions) def test_classes(self): "Test that module class names follow the standards" exceptions=%(value_object_exceptions)s return self.assertClassNames(%(module)s, exceptions, spelling_exceptions) def test_functions(self): "Test that module function names follow the standards" exceptions= %(function_name_exceptions)s return self.assertFunctionNames(%(module)s, exceptions, spelling_exceptions) def test_show(self): "Test all objects have show" exceptions=%(show_exceptions)s return self.assertShow(%(module)s, exceptions) if __name__ == '__main__': IMP.test.main() """ target = os.path.join("test") tools.mkdir(target) for module, g in tools.get_modules(source): targetdir = os.path.join(target, module) tools.mkdir(targetdir) exceptions = os.path.join(g, "test", "standards_exceptions") d = {'plural_exceptions': [], 'show_exceptions': [], 'function_name_exceptions': [], 'value_object_exceptions': [], 'class_name_exceptions': [], 'spelling_exceptions': []} try: exec(open(exceptions, "r").read(), d) except IOError: pass impmodule = "IMP." + module test = template % ({'module': impmodule, 'plural_exceptions': str(d['plural_exceptions']), 'show_exceptions': str(d['show_exceptions']), 'function_name_exceptions': str(d['function_name_exceptions']), 'value_object_exceptions': str(d['value_object_exceptions']), 'class_name_exceptions': str(d['class_name_exceptions']), 'spelling_exceptions': str(d['spelling_exceptions'])}) open( os.path.join("test", module, "medium_test_standards.py"), "w").write(test) cpptests = tools.get_glob([os.path.join(g, "test", "test_*.cpp")]) ecpptests = tools.get_glob( [os.path.join(g, "test", "expensive_test_*.cpp")]) cppexamples = tools.get_glob([os.path.join(g, "examples", "*.cpp")]) if len(cpptests) > 0 and scons: _make_test_driver( os.path.join( targetdir, "test_cpp_tests.py"), cpptests) if len(ecpptests) > 0 and scons: _make_test_driver( os.path.join(targetdir, "expensive_test_cpp_tests.py"), cpptests) if len(cppexamples) > 0 and scons: _make_test_driver( os.path.join(targetdir, "cpp_examples_test.py"), cppexamples)
def generate_tests(source, scons): template = """import IMP import IMP.test import %(module)s spelling_exceptions=%(spelling_exceptions)s class StandardsTest(IMP.test.TestCase): def test_value_objects(self): "Test that module classes are either values or objects" exceptions= %(value_object_exceptions)s return self.assertValueObjects(%(module)s,exceptions) def test_classes(self): "Test that module class names follow the standards" exceptions=%(value_object_exceptions)s return self.assertClassNames(%(module)s, exceptions, spelling_exceptions) def test_functions(self): "Test that module function names follow the standards" exceptions= %(function_name_exceptions)s return self.assertFunctionNames(%(module)s, exceptions, spelling_exceptions) def test_show(self): "Test all objects have show" exceptions=%(show_exceptions)s return self.assertShow(%(module)s, exceptions) if __name__ == '__main__': IMP.test.main() """ target = os.path.join("test") tools.mkdir(target) for module, g in tools.get_modules(source): targetdir = os.path.join(target, module) tools.mkdir(targetdir) exceptions = os.path.join(g, "test", "standards_exceptions") plural_exceptions = [] show_exceptions = [] function_name_exceptions = [] value_object_exceptions = [] class_name_exceptions = [] spelling_exceptions = [] try: exec open(exceptions, "r").read() except: pass impmodule = "IMP." + module test = template % ( { 'module': impmodule, 'plural_exceptions': str(plural_exceptions), 'show_exceptions': str(show_exceptions), 'function_name_exceptions': str(function_name_exceptions), 'value_object_exceptions': str(value_object_exceptions), 'class_name_exceptions': str(class_name_exceptions), 'spelling_exceptions': str(spelling_exceptions) }) open(os.path.join("test", module, "medium_test_standards.py"), "w").write(test) cpptests = tools.get_glob([os.path.join(g, "test", "test_*.cpp")]) ecpptests = tools.get_glob( [os.path.join(g, "test", "expensive_test_*.cpp")]) cppexamples = tools.get_glob([os.path.join(g, "examples", "*.cpp")]) if len(cpptests) > 0 and scons: _make_test_driver(os.path.join(targetdir, "test_cpp_tests.py"), cpptests) if len(ecpptests) > 0 and scons: _make_test_driver( os.path.join(targetdir, "expensive_test_cpp_tests.py"), cpptests) if len(cppexamples) > 0 and scons: _make_test_driver(os.path.join(targetdir, "cpp_examples_test.py"), cppexamples) for app, g in tools.get_applications(source): tools.mkdir(os.path.join(target, app))
def get_app_sources(path, patterns): matching = tools.get_glob([os.path.join(path, x) for x in patterns]) return "\n".join( ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) for x in matching if not x.endswith("dependencies.py")] )
def get_path(self): modbin = [os.path.abspath(x) for x in tools.get_glob(["module_bin/*"])] if self.options.suffix: modbin += [os.path.join(x, self.options.suffix) for x in modbin] return modbin + [self.get_abs_binary_path("bin")] \ + self.native_paths(self.options.path, True)
def setup_module(module, path, ordered): checks = [] deps = [] contents = [] defines = [] for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]): ret = make_check(cc, module, path) checks.append(ret[0]) defines.append(ret[1]) for cc in tools.get_glob([os.path.join(path, "dependency", "*.description")]): ret = make_dependency_check(cc, module, path) if ret: deps.append(ret) if len(checks) > 0: tools.rewrite( "modules/%s/compiler/CMakeLists.txt" % module, "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x) for x in checks]), ) contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" % module) if len(deps) > 0: tools.rewrite( "modules/%s/dependency/CMakeLists.txt" % module, "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x) for x in deps]), ) contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" % module) local = os.path.join(path, "Setup.cmake") if os.path.exists(local): contents.append("include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(local)) values = {"name": module} values["NAME"] = module.upper() values["CPPNAME"] = module.upper().replace("_", "") data = tools.get_module_description(".", module, "") all_modules = tools.get_all_modules(".", [module], "", ordered) modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules] dependencies = ["${%s_LIBRARIES}" % s.upper() for s in tools.get_all_dependencies(".", [module], "", ordered)] values["modules"] = ";".join(modules) values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules]) values["other_pythons"] = "\n".join(["${IMP_%s_PYTHON}" % m for m in all_modules]) values["dependencies"] = ";".join(dependencies) values["sources"] = get_sources(module, path, "src", "*.cpp") values["headers"] = get_sources(module, path, "include", "*.h") values["cppbins"] = get_sources(module, path, "bin", "*.cpp") values["cppbenchmarks"] = get_sources(module, path, "benchmark", "*.cpp") values["pybenchmarks"] = get_sources(module, path, "benchmark", "*.py") values["pytests"] = get_sources(module, path, "test", "test_*.py") values["expytests"] = get_sources(module, path, "test", "expensive_test_*.py") values["mdpytests"] = get_sources(module, path, "test", "medium_test_*.py") values["cpptests"] = get_sources(module, path, "test", "test_*.cpp") values["mdcpptests"] = get_sources(module, path, "test", "medium_test_*.cpp") values["excpptests"] = get_sources(module, path, "test", "expensive_test_*.cpp") values["pyexamples"] = get_sources(module, path, "examples", "[a-zA-Z]*.py") values["cppexamples"] = get_sources(module, path, "examples", "*.cpp") values["excpptests"] = get_sources(module, path, "test", "expensive_test_*.cpp") values["includepath"] = get_dep_merged([module], "include_path", ordered) values["libpath"] = get_dep_merged([module], "link_path", ordered) values["swigpath"] = get_dep_merged([module], "swig_path", ordered) values["defines"] = ":".join(defines) main = os.path.join(path, "src", "CMakeLists.txt") tests = os.path.join(path, "test", "CMakeLists.txt") swig = os.path.join(path, "pyext", "CMakeLists.txt") bin = os.path.join(path, "bin", "CMakeLists.txt") benchmark = os.path.join(path, "benchmark", "CMakeLists.txt") examples = os.path.join(path, "examples", "CMakeLists.txt") tools.rewrite(main, lib_template % values) tools.rewrite(tests, test_template % values) tools.rewrite(swig, swig_template % values) tools.rewrite(bin, bin_template % values) tools.rewrite(benchmark, benchmark_template % values) tools.rewrite(examples, examples_template % values) values["tests"] = "\n".join(contents) values[ "subdirs" ] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark) add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin)""" % ( (module,) * 5 ) out = os.path.join(path, "CMakeLists.txt") tools.rewrite(out, module_template % values) return out
def setup_module(finder, module, tools_dir, extra_include, extra_swig, required): checks = [] deps = [] contents = [] defines = [] for cc in tools.get_glob([os.path.join(module.path, "compiler", "*.cpp")]): ret = make_check(cc, module) checks.append(ret[0]) defines.append(ret[1]) for cc in tools.get_glob( [os.path.join(module.path, "dependency", "*.description")]): ret = make_dependency_check(cc, module) if ret: deps.append(ret) g = tools.CMakeFileGenerator() if len(checks) > 0: g.write( os.path.join(module.path, 'compiler', 'CMakeLists.txt'), "\n".join([ "include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x) for x in checks ])) contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/%s/compiler)" % tools.to_cmake_path(module.path)) if len(deps) > 0: g.write( os.path.join(module.path, 'dependency', 'CMakeLists.txt'), "\n".join([ "include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x) for x in deps ])) contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/%s/dependency)" % tools.to_cmake_path(module.path)) local = os.path.join(module.path, "Setup.cmake") if os.path.exists(local): contents.append("include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(local)) values = { "name": module.name, "extra_include": extra_include, "extra_swig": extra_swig, "module_dir": tools.to_cmake_path(module.path) + '/' if module.path else '', "tools_dir": tools.to_cmake_path(tools_dir) + '/' if tools_dir else '' } if module.name == 'kernel': values['subdir'] = 'IMP' values['pymod'] = 'IMP' values['allh_header'] = 'IMP.h' else: values['subdir'] = 'IMP/' + module.name values['pymod'] = 'IMP.' + module.name values['allh_header'] = 'IMP/%s.h' % module.name values["NAME"] = module.name.upper() values["CPPNAME"] = module.name.upper().replace('_', '') all_modules = module.get_all_modules() modules = ["${IMP_%s_LIBRARY}" % s.name for s in all_modules] all_dependencies = list(finder.get_all_dependencies([module] + all_modules)) dependencies = ["${%s_LIBRARIES}" % s.upper() for s in all_dependencies] values["modules"] = ";".join(modules) values["tags"] = "\n".join(["${IMP_%s_DOC}" % m.name for m in all_modules]) values["other_pythons"] = "\n".join( ["${IMP_%s_PYTHON}" % m.name for m in all_modules]) values["dependencies"] = ";".join(dependencies) values["headers"] = get_sources(module, "include", "*.h") # Don't add NumPy include directory except for when we build SWIG # extensions; this prevents unnecessary rebuilds of C++ code when we # change Python version all_non_python_dependencies = [x for x in all_dependencies if x != 'NumPy'] values["includepath"] = get_dep_merged(all_non_python_dependencies, "include_path") values["python_includepath"] = get_dep_merged(all_dependencies, "include_path") values["libpath"] = get_dep_merged(all_dependencies, "link_path") values["swigpath"] = get_dep_merged(all_dependencies, "swig_path") values["defines"] = ":".join(defines) cppbins = tools.get_glob([os.path.join(module.path, "bin", "*.cpp")]) cppbins = [os.path.splitext(e)[0] for e in cppbins] pybins = get_app_sources(os.path.join(module.path, "bin"), ["*"], tools.filter_pyapps) values["pybins"] = "\n".join(pybins) values["bin_names"] = "\n".join([os.path.basename(x) \ for x in pybins + cppbins]) local = os.path.join(module.path, "Build.cmake") if os.path.exists(local): values["custom_build"] = "include(${CMAKE_SOURCE_DIR}/%s)\n" \ % tools.to_cmake_path(local) else: values["custom_build"] = "" main = os.path.join(module.path, "src", "CMakeLists.txt") tests = os.path.join(module.path, "test", "CMakeLists.txt") swig = os.path.join(module.path, "pyext", "CMakeLists.txt") util = os.path.join(module.path, "utility", "CMakeLists.txt") bin = os.path.join(module.path, "bin", "CMakeLists.txt") benchmark = os.path.join(module.path, "benchmark", "CMakeLists.txt") examples = os.path.join(module.path, "examples", "CMakeLists.txt") lib_template.write(main, values) test_template.write(tests, values) swig_template.write(swig, values) util_template.write(util, values) bin_template.write(bin, values) benchmark_template.write(benchmark, values) examples_template.write(examples, values) values["tests"] = "\n".join(contents) topdir = '/' + tools.to_cmake_path(module.path) if module.path else '' if finder.external_dir: values["build_dir"] = "--build_dir=%s " % finder.external_dir else: values["build_dir"] = "" values["disabled_status"] = "FATAL_ERROR" if required else "STATUS" values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}%s/src) add_subdirectory(${CMAKE_SOURCE_DIR}%s/test) add_subdirectory(${CMAKE_SOURCE_DIR}%s/examples) add_subdirectory(${CMAKE_SOURCE_DIR}%s/benchmark) add_subdirectory(${CMAKE_SOURCE_DIR}%s/bin) add_subdirectory(${CMAKE_SOURCE_DIR}%s/utility)""" % ((topdir, ) * 6) cmakelists = os.path.join(module.path, "CMakeLists.txt") if finder.one_module or standalone_cmake(cmakelists): out = os.path.join(module.path, "ModuleBuild.cmake") else: out = cmakelists module_template.write(out, values) # at end so directories exist subprocess.check_call([ sys.executable, os.path.join(TOPDIR, "..", "dev_tools", "setup_cmake.py") ], cwd=module.path or '.', universal_newlines=True) return out