10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-03 09:55:59 +02:00

Cleaning compile.py

This commit is contained in:
Thomas Applencourt 2015-06-11 11:58:26 +02:00
parent fbed320e83
commit b99679041e
4 changed files with 569 additions and 460 deletions

475
configure.py Executable file
View File

@ -0,0 +1,475 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""configure
Usage: configure <config_file> (--production | --development)
Options:
config_file A config file will all the information for the compilation
(Fortran Compiler, FLag, ...)
--production You cannot compile only one module with this flag.
but the compilation will be lighting fast
--development It will create a build.ninja for each directory
who containt a binary, than you can compile then
individualy if you want
"""
import subprocess
import os
import sys
from os.path import join
if not any(i in ["--production", "--development"] for i in sys.argv):
print __doc__
sys.exit()
if len(sys.argv) != 3:
print __doc__
sys.exit()
# __ _
# /__ | _ |_ _. | o ._ _|_ _
# \_| |_ (_) |_) (_| | | | | | (_)
#
QP_ROOT = os.getcwd()
QP_ROOT_BIN = join(QP_ROOT, "bin")
QP_ROOT_INSTALL = join(QP_ROOT, "install")
d_dependency = {
"ocaml": ["m4", "curl", "zlib", "patch", "gcc"],
"m4": ["make"],
"curl": ["make"],
"zlib": ["gcc", "make"],
"patch": ["make"],
"ezfio": ["irpf90"],
"irpf90": ["python"],
"docopt": ["python"],
"resultsFile": ["python"],
"emsl": ["python"],
"gcc": [],
"python": [],
"ninja": ["gcc", "python"],
"make": []
}
from collections import namedtuple
Info = namedtuple("Info", ["url", "description", "default_path"])
path_github = {"head": "http://github.com/", "tail": "archive/master.tar.gz"}
ocaml = Info(
url='http://raw.github.com/ocaml/opam/master/shell/opam_installer.sh',
description=' ocaml (it will take some time roughly 20min)',
default_path=join(QP_ROOT_BIN, "opam"))
m4 = Info(
url="http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz",
description=" m4",
default_path=join(QP_ROOT_BIN, "m4"))
curl = Info(
url="http://qmcchem.ups-tlse.fr/files/scemama/curl-7.30.0.ermine.tar.bz2",
description=" curl",
default_path=join(QP_ROOT_BIN, "curl"))
zlib = Info(
url='http://zlib.net/zlib-1.2.8.tar.gz',
description=' zlib',
default_path=join(QP_ROOT_INSTALL, "zlib"))
path = Info(
url='ftp://ftp.gnu.org/gnu/patch/patch-2.7.5.tar.gz',
description=' path',
default_path=join(QP_ROOT, "lib", "libz.a"))
irpf90 = Info(
url='{head}/LCPQ/irpf90/{tail}'.format(**path_github),
description=' irpf90',
default_path=join(QP_ROOT_BIN, "irpf90"))
docopt = Info(
url='{head}/docopt/docopt/{tail}'.format(**path_github),
description=' docop',
default_path=join(QP_ROOT_INSTALL, "docopt"))
resultsFile = Info(
url='{head}/LCPQ/resultsFile/{tail}'.format(**path_github),
description=' resultsFile',
default_path=join(QP_ROOT_INSTALL, "resultsFile"))
ninja = Info(
url='{head}/martine/ninja/{tail}'.format(**path_github),
description=' nina',
default_path=join(QP_ROOT_BIN, "ninja"))
emsl = Info(
url='{head}/LCPQ/EMSL_Basis_Set_Exchange_Local/{tail}'.format(**
path_github),
description=' emsl',
default_path=join(QP_ROOT_INSTALL, "emsl"))
ezfio = Info(
url='{head}/LCPQ/EZFIO/{tail}'.format(**path_github),
description=' EZFIO',
default_path=join(QP_ROOT_INSTALL, "EZFIO"))
d_info = dict()
for m in ["ocaml", "m4", "curl", "zlib", "path", "irpf90", "docopt",
"resultsFile", "ninja", "emsl", "ezfio"]:
exec ("d_info['{0}']={0}".format(m))
def find_path(bin_, l_installed):
"""Use the global variable
* l_installed
* d_info
"""
try:
locate = l_installed[bin_]
except KeyError:
locate = d_info[bin_].default_path
return locate
# _
# |_ ._ _ _|_ o _ ._
# | |_| | | (_ |_ | (_) | |
#
def check_output(*popenargs, **kwargs):
"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.
>>> check_output(['/usr/bin/python', '--version'])
Python 2.6.2
"""
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
def checking(d_dependency):
"""
For each key in d_dependency check if it
it avalabie or not
"""
def check_python():
req_version = (2, 6)
cur_version = sys.version_info
# Check python
if cur_version >= req_version:
return 1
else:
print "To old version (need >2.5). Abort"
sys.exit(1)
def check_availabiliy(binary):
"""
If avalabie return the path who can can't find the
binary else return 0
"""
if binary == "python":
check_python()
try:
return check_output(["which", binary])
except subprocess.CalledProcessError:
default_path = d_info[binary].default_path
if os.path.exists(default_path):
return default_path
else:
return 0
def get_list_descendant(d_dependency, l_installed, l_needed):
"""
Descendant a node reachable by repeated proceeding from parent to child.
"""
d_need_genealogy = dict()
for need in l_needed:
d_need_genealogy[need] = None
for childen in d_dependency[need]:
if childen not in l_installed:
d_need_genealogy[childen] = None
return d_need_genealogy.keys()
return d_need_genealogy.keys()
print """
_
|_) _ o _
| \ (/_ \/ | (/_ \/\/
"""
print "Checking what you need to install and what is it avalaible"
print ""
l_installed = dict()
l_needed = []
# Check all the other
length = max(map(len, d_dependency))
for i in d_dependency.keys():
print "Checking {0:>{1}}...".format(i, length),
r = check_availabiliy(i)
if r:
print "[ OK ] ( {0} )".format(r.strip())
l_installed[i] = r.strip()
else:
print "[ FAIL ]"
l_needed.append(i)
print ""
# Expend the need_stuff for all the genealogy
l_install_descendant = get_list_descendant(d_dependency, l_installed,
l_needed)
return l_installed, l_install_descendant
def installation(l_install_descendant):
"""
Installing all the list
0 install ninja
1 create ninja
2 run ninja
"""
def create_rule_ninja():
l_rules = [
"rule download", " command = wget ${url} -O ${out} -o /dev/null",
" description = Downloading ${descr}", ""
]
l_rules += [
"rule install",
" command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1",
" description = Installing ${descr}", ""
]
l_rules += [
"rule install_verbose",
" command = ./scripts/install_${target}.sh | tee _build/${target}.log 2>&1",
" description = Installing ${descr}", " pool = console", ""
]
return l_rules
def splitext(path):
for ext in ['.tar.gz', '.tar.bz2']:
if path.endswith(ext):
return path[:-len(ext)], path[-len(ext):]
return os.path.splitext(path)
print """
___
| ._ _ _|_ _. | | _. _|_ o _ ._
_|_ | | _> |_ (_| | | (_| |_ | (_) | |
"""
d_print = {
"install_ninja": "Install ninja...",
"build": "Creating build.ninja...",
"install": "Installing the dependancy through ninja..."
}
length = max(map(len, d_print.values()))
def str_info(key):
return "{0:<{1}}".format(d_print[key], length)
if "ninja" in l_install_descendant:
print str_info("install_ninja"),
url = d_info["ninja"].url
extension = splitext(url)[1]
path_archive = "Downloads/{0}{1}".format("ninja", extension)
l_cmd = ["cd install &&",
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
"./scripts/install_ninja.sh 2> /dev/null &&", "cd -"]
try:
check_output(" ".join(l_cmd), shell=True)
except:
print "[ OK ]"
l_install_descendant.remove("ninja")
print str_info("build"),
l_string = create_rule_ninja()
l_build = []
for need in l_install_descendant:
url = d_info[need].url
extension = splitext(url)[1]
archive_path = "Downloads/{0}{1}".format(need, extension)
descr = d_info[need].description
default_path = d_info[need].default_path
# Build to dowload
l_build += ["build {0}: download".format(archive_path),
" url = {0}".format(url), " descr = {0}".format(descr),
""]
# Build to install
l_dependancy = [d_info[i].default_path for i in d_dependency[need]
if i in l_install_descendant]
str_dependancy = " ".join(l_dependancy)
rule = "install" if need != "ocaml" else "install_verbose"
l_build += ["build {0}: {1} {2} {3}".format(default_path, rule,
archive_path,
str_dependancy),
" target = {0}".format(need),
" descr = {0}".format(descr), ""]
l_string += l_build
path = join(QP_ROOT_INSTALL, "build.ninja")
with open(path, "w+") as f:
f.write("\n".join(l_string))
print " [ OK ] ({0})".format(path)
print str_info("install"),
print " [ Running ]"
try:
path_ninja = find_path("ninja", l_installed)
subprocess.check_call("cd install ;{0}".format(path_ninja), shell=True)
except:
raise
else:
print r"""
_________
< Success >
---------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
"""
def create_ninja_and_rc(l_installed):
print """
_
|_ o ._ _. | o _ _
| | | | (_| | | /_ (/_
"""
d_print = {
"qp_root": "Creating quantum_package.rc...",
"build": "Creating build.ninja..."
}
length = max(map(len, d_print.values()))
def str_info(key):
return "{0:<{1}}".format(d_print[key], length)
print str_info("qp_root"),
python_path = [join(QP_ROOT, "scripts"), join(QP_ROOT, "install")]
l_python = [join(QP_ROOT, "scripts")]
for dir_ in python_path:
for folder in os.listdir(dir_):
path = join(dir_, folder)
if os.path.isdir(path):
l_python.append(path)
l_rc = [
'export QP_ROOT={0}'.format(QP_ROOT),
'export QP_EZFIO={0}'.format(find_path('ezfio', l_installed)),
'export IRPF90={0}'.format(find_path("irpf90", l_installed)),
'export NINJA={0}'.format(find_path("ninja", l_installed)),
'export QP_PYTHON={0}'.format(":".join(l_python)), "",
'export PYTHONPATH="${PYTHONPATH}":"${QP_PYTHON}"',
'export PATH="${PATH}":"${QP_PYTHON}":"${QP_ROOT}"/bin:"${QP_ROOT}"/ocaml',
'export LD_LIBRARY_PATH="${QP_ROOT}"/lib:"${LD_LIBRARY_PATH}"',
'export LIBRARY_PATH="${QP_ROOT}"/lib:"${LIBRARY_PATH}"', ""
'source ${HOME}/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true',
""
]
path = join(QP_ROOT, "quantum_package.rc")
with open(path, "w+") as f:
f.write("\n".join(l_rc))
print "[ OK ] ({0})".format(path)
print str_info("build"),
command = ['bash', '-c', 'source {0} && env'.format(path)]
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
for line in proc.stdout:
(key, _, value) = line.partition("=")
os.environ[key] = value.strip()
qp_create_ninja = os.path.join(QP_ROOT, "scripts", "compilation",
"qp_create_ninja.py")
l = [qp_create_ninja, "create"] + sys.argv[1:]
try:
subprocess.check_call(" ".join(l), shell=True)
except:
raise
else:
print "[ OK ]"
def recommendation():
print "Last Step:"
path = join(QP_ROOT, "quantum_package.rc")
print "Now :"
print " source {0}".format(path)
print " ninja"
print " cd ocaml; make "
print ""
print "PS : For more info on compiling the code, read the COMPILE_RUN.md file."
if __name__ == '__main__':
l_installed, l_install_descendant = checking(d_dependency)
if l_install_descendant:
print "You will need to install:"
for i in l_install_descendant:
print "* {0}".format(i)
installation(l_install_descendant)
else:
print "Perfect, nothing to install"
create_ninja_and_rc(l_installed)
recommendation()

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Usage: qp_create_ninja.py create (--development | --production) CONFIG_FILE Usage: qp_create_ninja.py create <config_file> (--development | --production)
qp_create_ninja.py update qp_create_ninja.py update
""" """
@ -22,6 +22,27 @@ except ImportError:
print "source .quantum_package.rc" print "source .quantum_package.rc"
sys.exit(1) sys.exit(1)
header = r"""#
# _______ _____
# __ __ \___ _______ _________ /____ ________ ___
# _ / / / / / / __ `/_ __ \ __/ / / /_ __ `__ \
# / /_/ // /_/ // /_/ /_ / / / /_ / /_/ /_ / / / / /
# \___\_\\__,_/ \__,_/ /_/ /_/\__/ \__,_/ /_/ /_/ /_/
#
# ________ ______
# ___ __ \_____ _________ /_______ _______ _____
# __ /_/ / __ `/ ___/_ //_/ __ `/_ __ `/ _ \
# _ ____// /_/ // /__ _ ,< / /_/ /_ /_/ // __/
# /_/ \__,_/ \___/ /_/|_| \__,_/ _\__, / \___/
# /____/
#
# https://github.com/LCPQ/quantum_package,
#
# Generated automatically by {0}.".format(__file__)
#
#
"""
# __ # __
# /__ | _ |_ _. | _. ._ o _. |_ | _ _ # /__ | _ |_ _. | _. ._ o _. |_ | _ _
# \_| | (_) |_) (_| | \/ (_| | | (_| |_) | (/_ _> # \_| | (_) |_) (_| | \/ (_| | | (_| |_) | (/_ _>
@ -32,6 +53,7 @@ QP_ROOT_SRC = join(QP_ROOT, 'src')
QP_ROOT_EZFIO = join(QP_ROOT, 'install', 'EZFIO') QP_ROOT_EZFIO = join(QP_ROOT, 'install', 'EZFIO')
EZFIO_LIB = join(QP_ROOT, "lib", "libezfio.a") EZFIO_LIB = join(QP_ROOT, "lib", "libezfio.a")
ROOT_BUILD_NINJA = join(QP_ROOT, "config", "build.ninja")
# #
# |\ | _. ._ _ _ _| _|_ ._ | _ # |\ | _. ._ _ _ _| _|_ ._ | _
@ -231,8 +253,7 @@ def ninja_ezfio_rule():
l_string = ["rule build_ezfio", l_string = ["rule build_ezfio",
" command = {0}".format(" ; ".join(l_cmd)), " command = {0}".format(" ; ".join(l_cmd)),
" description = Create $out" " pool = console", " description = Create $out", ""]
""]
return l_string return l_string
@ -377,7 +398,7 @@ def ninja_irpf90_make_rule():
# c m d # # c m d #
# ~#~#~ # # ~#~#~ #
l_cmd = ["cd $module"] + l_flag + ["irpf90 $include_dir $IRPF90_FLAGS"] l_cmd = ["cd $module_abs"] + l_flag + ["irpf90 $include_dir $IRPF90_FLAGS"]
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
# s t r i n g # # s t r i n g #
@ -386,7 +407,7 @@ def ninja_irpf90_make_rule():
l_string = ["pool irp_pool", " depth = 1", "", "rule build_irpf90.ninja", l_string = ["pool irp_pool", " depth = 1", "", "rule build_irpf90.ninja",
" command = {0}".format(" ; ".join(l_cmd)), " command = {0}".format(" ; ".join(l_cmd)),
" pool = irp_pool", " pool = irp_pool",
" description = Create the IRP_Tree for $module", ""] " description = Running IRPF90 for $module_rel", ""]
return l_string return l_string
@ -429,7 +450,8 @@ def ninja_irpf90_make_build(path_module, l_needed_molule, d_irp):
l_string = [ l_string = [
"build {0}: build_irpf90.ninja {1}".format(str_creation, str_depend), "build {0}: build_irpf90.ninja {1}".format(str_creation, str_depend),
" module = {0}".format(path_module.abs), " module_abs = {0}".format(path_module.abs),
" module_rel = {0}".format(path_module.rel),
" SRC = {0}".format(" ".join(l_src)), " SRC = {0}".format(" ".join(l_src)),
" OBJ = {0}".format(" ".join(l_obj)), " OBJ = {0}".format(" ".join(l_obj)),
" include_dir = {0}".format(" ".join(l_include_dir)), "" " include_dir = {0}".format(" ".join(l_include_dir)), ""
@ -444,7 +466,7 @@ def ninja_readme_rule():
For not dealted the readme when ninja -t clean and the generator option For not dealted the readme when ninja -t clean and the generator option
""" """
l_string = ["rule build_readme", l_string = ["rule build_readme",
" command = cd $module ; update_README.py", " command = cd $module_abs ; update_README.py",
" generator = 1", ""] " generator = 1", ""]
return l_string return l_string
@ -459,7 +481,8 @@ def ninja_readme_build(path_module):
l_string = ["build {0}: build_readme {1}".format(path_readme, l_string = ["build {0}: build_readme {1}".format(path_readme,
path_irp_man), path_irp_man),
" module = {0}".format(path_module.abs), ""] " module_abs = {0}".format(path_module.abs),
" module_rel = {0}".format(path_module.rel), ""]
return l_string return l_string
@ -554,7 +577,7 @@ def ninja_binaries_rule():
# c m d # # c m d #
# ~#~#~ # # ~#~#~ #
l_cmd = ["cd $module/IRPF90_temp", "ninja $out && touch $out"] l_cmd = ["cd $module_abs/IRPF90_temp", "ninja $out && touch $out"]
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
# s t r i n g # # s t r i n g #
@ -562,7 +585,9 @@ def ninja_binaries_rule():
l_string = ["rule build_binaries", l_string = ["rule build_binaries",
" command = {0}".format(" ; ".join(l_cmd)), " command = {0}".format(" ; ".join(l_cmd)),
" description = Create all the binaries from $module", ""] " pool = console",
" description = Create all the binaries from $module_rel",
""]
return l_string return l_string
@ -586,7 +611,8 @@ def ninja_binaries_build(path_module, l_children, d_binaries):
l_string = ["build {0}: build_binaries {1} {2}".format(" ".join(l_abs_bin), l_string = ["build {0}: build_binaries {1} {2}".format(" ".join(l_abs_bin),
EZFIO_LIB, EZFIO_LIB,
ninja_module_path), ninja_module_path),
" module = {0}".format(path_module.abs), ""] " module_abs = {0}".format(path_module.abs),
" module_rel = {0}".format(path_module.rel), ""]
l_string += ["build module_{0}: phony {1}".format(path_module.rel, l_string += ["build module_{0}: phony {1}".format(path_module.rel,
" ".join(l_abs_bin)), ""] " ".join(l_abs_bin)), ""]
@ -619,12 +645,12 @@ def ninja_dot_tree_rule():
# c m d # # c m d #
# ~#~#~ # # ~#~#~ #
l_cmd = ["cd $module", "module_handler.py create_png"] l_cmd = ["cd $module_abs", "module_handler.py create_png"]
l_string = [ l_string = [
"rule build_dot_tree", " command = {0}".format(" ; ".join(l_cmd)), "rule build_dot_tree", " command = {0}".format(" ; ".join(l_cmd)),
" generator = 1", " generator = 1",
" description = Generate Png representtion of the Tree Dependancies of $module", " description = Generate Png representtion of the Tree Dependencies of $module_rel",
"" ""
] ]
@ -635,39 +661,73 @@ def ninja_dot_tree_build(path_module):
path_tree = join(path_module.abs, "tree_dependency.png") path_tree = join(path_module.abs, "tree_dependency.png")
l_string = ["build {0}: build_dot_tree".format(path_tree), l_string = ["build {0}: build_dot_tree".format(path_tree),
" module = {0}".format(path_module.abs), ""] " module_abs = {0}".format(path_module.abs),
" module_rel = {0}".format(path_module.rel), ""]
return l_string return l_string
# #
# |\/| _ _| | _ # |\/| _ _| | _
# | | (_) (_| |_| | (/_ # | | (_) (_| |_| | (/_
# #
def create_build_ninja_module(path_module):
l_string = ["rule update_build_ninja_root",
def create_ninja_module(path_module):
path_ninja_root = join(QP_ROOT, "build.ninja")
l_string = ["rule update_ninja_common",
" command = qp_create_ninja.py update", ""] " command = qp_create_ninja.py update", ""]
l_string += ["rule make_local_binaries", l_string += ["rule make_local_binaries",
" command = ninja -j 1 -f {0} module_{1}".format( " command = ninja -f {0} module_{1}".format(
path_ninja_root, path_module.rel), ROOT_BUILD_NINJA, path_module.rel), " pool = console",
" description = Compile only {0}".format(path_module.rel), " description = Compile only {0}".format(path_module.rel),
""] ""]
l_string += ["rule make_all_binaries", l_string += ["rule make_all_binaries",
" command = ninja -j 1 -f {0}".format(path_ninja_root), " command = ninja -f {0}".format(ROOT_BUILD_NINJA),
" description = Compile all the module", ""] " pool = console", " description = Compile all the module",
""]
l_string += ["build dumy_target: update_ninja_common", "", l_string += ["rule make_clean", " command = clean_modules.sh",
"build all: make_all_binaries dumy_target", "", " description = Cleaning module {0}".format(path_module.rel),
"build local: make_local_binaries dumy_target", ""]
"default local", ""]
l_string += ["build dummy_target: update_build_ninja_root", "",
"build all: make_all_binaries dummy_target", "",
"build local: make_local_binaries dummy_target",
"default local", "", "build clean: make_clean dummy_target",
""]
path_ninja_cur = join(path_module.abs, "build.ninja") path_ninja_cur = join(path_module.abs, "build.ninja")
with open(path_ninja_cur, "w") as f: with open(path_ninja_cur, "w") as f:
f.write(header)
f.write("\n".join(l_string))
def create_build_ninja_global():
l_string = ["rule update_build_ninja_root",
" command = qp_create_ninja.py update", ""]
l_string += ["rule make_all_binaries",
" command = ninja -f {0}".format(ROOT_BUILD_NINJA),
" pool = console", " description = Compile all the module",
""]
l_string += ["rule make_clean",
" command = cd {0} ; clean_modules.sh *".format(QP_ROOT_SRC),
" description = Cleaning all modules", ""]
l_string += ["build dummy_target: update_build_ninja_root",
"",
"build all: make_all_binaries dummy_target",
"default all",
"",
"build clean: make_clean",
"", ]
path_ninja_cur = join(QP_ROOT, "build.ninja")
with open(path_ninja_cur, "w") as f:
f.write(header)
f.write("\n".join(l_string)) f.write("\n".join(l_string))
# #
@ -689,12 +749,12 @@ if __name__ == "__main__":
elif arguments["create"]: elif arguments["create"]:
arguments["CONFIG_FILE"] = os.path.realpath(arguments["CONFIG_FILE"]) arguments["<config_file>"] = os.path.realpath(arguments["<config_file>"])
with open(pickle_path, 'wb') as handle: with open(pickle_path, 'wb') as handle:
pickle.dump(arguments, handle) pickle.dump(arguments, handle)
pwd_config_file = arguments["CONFIG_FILE"] pwd_config_file = arguments["<config_file>"]
# _ # _
# |_ ._ _. ._ o _. |_ | _ _ # |_ ._ _. ._ o _. |_ | _ _
@ -756,19 +816,18 @@ if __name__ == "__main__":
if arguments["--production"]: if arguments["--production"]:
d_binaries = get_dict_binaries(l_module, mode="production") d_binaries = get_dict_binaries(l_module, mode="production")
l_module = d_binaries.keys() l_module = d_binaries.keys()
elif arguments["--development"]: elif arguments["--development"]:
d_binaries = get_dict_binaries(l_module, mode="development") d_binaries = get_dict_binaries(l_module, mode="development")
l_module = d_binaries.keys() l_module = d_binaries.keys()
create_build_ninja_global()
for module_to_compile in l_module: for module_to_compile in l_module:
if arguments["--development"]: if arguments["--development"]:
create_ninja_module(module_to_compile) create_build_ninja_module(module_to_compile)
# ~#~#~#~#~#~#~#~ # # ~#~#~#~#~#~#~#~ #
# S y m l i n k # # S y m l i n k #
@ -793,5 +852,6 @@ if __name__ == "__main__":
l_string += ninja_binaries_build(module_to_compile, l_children, l_string += ninja_binaries_build(module_to_compile, l_children,
d_binaries) d_binaries)
with open(join(QP_ROOT, "build.ninja"), "w+") as f: with open(join(QP_ROOT, "config", "build.ninja"), "w+") as f:
f.write(header)
f.write("\n".join(l_string)) f.write("\n".join(l_string))

View File

@ -13,11 +13,9 @@ source ${QP_ROOT}/scripts/qp_include.sh
function do_clean() function do_clean()
{ {
rm -rf -- \ rm -rf -- \
IRPF90_temp IRPF90_man Makefile.depend \ IRPF90_temp IRPF90_man \
$(module_handler.py print_descendant) include \ $(module_handler.py print_descendant) include \
ezfio_interface.irp.f irpf90.make irpf90_entities tags $(ls_exe) *.mod ezfio_interface.irp.f irpf90.make irpf90_entities tags $(ls_exe) *.mod
touch -c EZFIO.cfg *.ezfio_config
} }
if [[ -z $1 ]] if [[ -z $1 ]]

View File

@ -1,424 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import os
import sys
import pprint
from os.path import join
# __ _
# /__ | _ |_ _. | o ._ _|_ _
# \_| |_ (_) |_) (_| | | | | | (_)
#
QP_ROOT = os.getcwd()
QP_ROOT_BIN = join(QP_ROOT, "bin")
QP_ROOT_INSTALL = join(QP_ROOT, "install")
d_dependency = {
"ocaml": ["m4", "curl", "zlib", "patch", "gcc"],
"m4": ["make"],
"curl": ["make"],
"zlib": ["gcc", "make"],
"patch": ["make"],
"ezfio": ["irpf90"],
"irpf90": ["python"],
"docopt": ["python"],
"resultsFile": ["python"],
"emsl": ["python"],
"gcc": [],
"python": [],
"ninja": ["gcc", "python"],
"make": []
}
from collections import namedtuple
Info = namedtuple("Info", ["url", "description", "default_path"])
path_github = {"head": "http://github.com/", "tail": "archive/master.tar.gz"}
ocaml = Info(
url='http://raw.github.com/ocaml/opam/master/shell/opam_installer.sh',
description=' ocaml (it will take some time roughly 20min)',
default_path=join(QP_ROOT_BIN, "opam"))
m4 = Info(
url="http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz",
description=" m4",
default_path=join(QP_ROOT_BIN, "m4"))
curl = Info(
url="http://qmcchem.ups-tlse.fr/files/scemama/curl-7.30.0.ermine.tar.bz2",
description=" curl",
default_path=join(QP_ROOT_BIN, "curl"))
zlib = Info(
url='http://zlib.net/zlib-1.2.8.tar.gz',
description=' zlib',
default_path=join(QP_ROOT_INSTALL, "zlib"))
path = Info(
url='ftp://ftp.gnu.org/gnu/patch/patch-2.7.5.tar.gz',
description=' path',
default_path=join(QP_ROOT, "lib", "libz.a"))
irpf90 = Info(
url='{head}/LCPQ/irpf90/{tail}'.format(**path_github),
description=' irpf90',
default_path=join(QP_ROOT_BIN, "irpf90"))
docopt = Info(
url='{head}/docopt/docopt/{tail}'.format(**path_github),
description=' docop',
default_path=join(QP_ROOT_INSTALL, "docopt"))
resultsFile = Info(
url='{head}/LCPQ/resultsFile/{tail}'.format(**path_github),
description=' resultsFile',
default_path=join(QP_ROOT_INSTALL, "resultsFile"))
ninja = Info(
url='{head}/martine/ninja/{tail}'.format(**path_github),
description=' nina',
default_path=join(QP_ROOT_BIN, "ninja"))
emsl = Info(
url='{head}/LCPQ/EMSL_Basis_Set_Exchange_Local/{tail}'.format(**
path_github),
description=' emsl',
default_path=join(QP_ROOT_INSTALL, "emsl"))
ezfio = Info(
url='{head}/LCPQ/EZFIO/{tail}'.format(**path_github),
description=' EZFIO',
default_path=join(QP_ROOT_INSTALL, "EZFIO"))
d_info = dict()
for m in ["ocaml", "m4", "curl", "zlib", "path", "irpf90", "docopt",
"resultsFile", "ninja", "emsl", "ezfio"]:
exec ("d_info['{0}']={0}".format(m))
l_need = []
# _
# |_ ._ _ _|_ o _ ._
# | |_| | | (_ |_ | (_) | |
#
def check_output(*popenargs, **kwargs):
"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.
>>> check_output(['/usr/bin/python', '--version'])
Python 2.6.2
"""
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
def check_python():
req_version = (2, 6)
cur_version = sys.version_info
# Check python
if cur_version >= req_version:
l_installed["python"] = ""
else:
print "To old version (need >2.5). Abort"
sys.exit(1)
def check_availabiliy(binary):
if binary == "python":
check_python()
try:
return check_output(["which", binary])
except subprocess.CalledProcessError:
default_path = d_info[binary].default_path
if os.path.exists(default_path):
return default_path
else:
return 0
def splitext(path):
for ext in ['.tar.gz', '.tar.bz2']:
if path.endswith(ext):
return path[:-len(ext)], path[-len(ext):]
return os.path.splitext(path)
def find_path(bin_):
"""Use the global variable
* l_installed
* d_info
"""
try:
locate = l_installed[bin_]
except KeyError:
locate = d_info[bin_].default_path
return locate
def create_rule_ninja():
l_rules = [
"rule download", " command = wget ${url} -O ${out} -o /dev/null",
" description = Downloading ${descr}", "", "rule install",
" command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1",
" description = Installing ${descr}", ""
]
return l_rules
def finalize():
print """
___ _
| ._ _|_ _ ._ ._ _ _. _|_ o _ ._
_|_ | | | (_) | | | | (_| |_ | (_) | |
"""
path = join(QP_ROOT, "quantum_package.rc")
print "For more info on compiling the code, read the COMPILE_RUN.md file."
print ""
print "You can check {0} and run:".format(path)
print ""
print " source {0}".format(path)
print " qp_create_ninja.py --production $QP_ROOT/config/ifort.cfg"
print " ninja"
print " make -C ocaml"
print ""
sys.exit()
def get_list_need_child(l_need):
"""
Descendant a node reachable by repeated proceeding from parent to child.
"""
d_need_genealogy = dict()
for need in l_need:
d_need_genealogy[need] = None
for childen in d_dependency[need]:
if childen not in l_installed:
d_need_genealogy[childen] = None
return d_need_genealogy.keys()
return d_need_genealogy.keys()
print """
_
/ |_ _ _ | o ._ _
\_ | | (/_ (_ |< | | | (_|
_|
"""
l_installed = dict()
# Check all the other
length = max(map(len, d_dependency))
for i in d_dependency.keys():
print "Checking if {0:^{1}} is avalaible...".format(i, length),
r = check_availabiliy(i)
if r:
print "[ OK ]"
l_installed[i] = r.strip()
else:
print "[ Will compile it ]"
l_need.append(i)
print """
__
(_ ._ _ ._ _ _. ._
__) |_| | | | | | | (_| | \/
/
"""
print "You have already installed :"
len_bin, len_path = [max(map(len, line))
for line in zip(*l_installed.iteritems())]
for bin, path in l_installed.iteritems():
print "{0:<{2}} : {1:<{3}}".format(bin, path, len_bin, len_path)
# Expend the need_stuff for all the genealogy
l_install_descendant = get_list_need_child(l_need)
print """
___
| ._ _ _|_ _. | | _. _|_ o _ ._
_|_ | | _> |_ (_| | | (_| |_ | (_) | |
"""
if l_install_descendant:
print "You need to install:"
pprint.pprint(l_install_descendant)
else:
print "Nothing to do."
finalize()
need_to_install_ninja = "ninja" in l_install_descendant
l_install_with_ninja = []
l_install_without_ninja = []
for need in l_install_descendant:
if need == "ocaml":
l_install_without_ninja.append(need)
else:
l_install_with_ninja.append(need)
if need_to_install_ninja:
print """
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
# I n s t a l l _ n i n j a #
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
"""
url = d_info["ninja"].url
extension = splitext(url)[1]
path_archive = "Downloads/{0}{1}".format("ninja", extension)
l_cmd = ["cd install &&",
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
"./scripts/install_ninja.sh 2> /dev/null &&", "cd -"]
check_output(" ".join(l_cmd), shell=True)
print "Done"
l_install_with_ninja.remove("ninja")
if l_install_with_ninja:
print """
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
# C r e a t i n g _ n i n j a #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
"""
l_string = create_rule_ninja()
l_build = []
for need in l_install_with_ninja:
url = d_info[need].url
extension = splitext(url)[1]
archive_path = "Downloads/{0}{1}".format(need, extension)
descr = d_info[need].description
# Build to dowload
l_build += ["build {0}: download".format(archive_path),
" url = {0}".format(url), " descr = {0}".format(descr),
""]
# Build to install
l_dependancy = [d_info[i].default_path for i in d_dependency[need]
if i in l_install_descendant]
l_build += ["build {0}: install {1} {2}".format(
d_info[need].default_path, archive_path, " ".join(l_dependancy)),
" target = {0}".format(need),
" descr = {0}".format(descr), ""]
l_string += l_build
path = join(QP_ROOT_INSTALL, "build.ninja")
with open(path, "w+") as f:
f.write("\n".join(l_string))
print "Done"
print "You can check {0}".format(path)
print """
# ~#~#~#~#~#~#~#~#~ #
# R u n _ n i n j a #
# ~#~#~#~#~#~#~#~#~ #
"""
if [i for i in l_install_descendant if i not in "ocaml"]:
subprocess.check_call("{0} -C install".format(find_path("ninja")),
shell=True)
print "Done"
if "ocaml" in l_install_without_ninja:
print """
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
# I n s t a l l _ o c a m l #
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
"""
url = d_info["ocaml"].url
extension = splitext(url)[1]
path_archive = "Downloads/{0}{1}".format("ocaml", extension)
l_cmd = ["cd install &&",
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
"./scripts/install_ocaml.sh"]
os.system(" ".join(l_cmd))
print "Done"
l_install_descendant.remove("ocaml")
print """
_. _. ._ _|_ ._ _ ._ _. _ | _. _ _ ._ _
(_| |_| (_| | | |_ |_| | | | |_) (_| (_ |< (_| (_| (/_ o | (_
| __ | _|
"""
python_path = [join(QP_ROOT, "scripts"), join(QP_ROOT, "install")]
l_python = [join(QP_ROOT, "scripts")]
for dir_ in python_path:
for folder in os.listdir(dir_):
path = join(dir_, folder)
if os.path.isdir(path):
l_python.append(path)
l_rc = [
'export QP_ROOT={0}'.format(QP_ROOT), 'export QP_EZFIO={0}'.format(
find_path('ezfio')), 'export IRPF90={0}'.format(find_path("irpf90")),
'export NINJA={0}'.format(find_path("ninja")),
'export QP_PYTHON={0}'.format(":".join(l_python)), "",
'export PYTHONPATH="${PYTHONPATH}":"${QP_PYTHON}"',
'export PATH="${PATH}":"${QP_PYTHON}":"${QP_ROOT}"/bin:"${QP_ROOT}"/ocaml',
'export LD_LIBRARY_PATH="${QP_ROOT}"/lib:"${LD_LIBRARY_PATH}"',
'export LIBRARY_PATH="${QP_ROOT}"/lib:"${LIBRARY_PATH}"', ""
'source ${HOME}/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true',
""
]
path = join(QP_ROOT, "quantum_package.rc")
with open(path, "w+") as f:
f.write("\n".join(l_rc))
print "Done."
finalize()