6Triple-use minimum working example for PyXMake. This script can be
7executed in three different ways in varying levels of accessibility
9@note: Compile Fortran source on the institute cluster.
13----------------------------------------------------------------------------------------------
18@author: garb_ma [DLR-FA,STM Braunschweig]
19----------------------------------------------------------------------------------------------
30 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
34 from PyXMake
import VTL
37__user = os.getenv(
"username",
"")
38__mcd_cluster_dev = posixpath.join(Utility.AsDrive(
"home",posixpath.sep),__user,
"mcodac")
39__mcd_cluster_incpath = posixpath.join(__mcd_cluster_dev,
"include")
40__mcd_cluster_libpath = posixpath.join(__mcd_cluster_dev,
"lib")
44 from PyCODAC.Tools.Utility
import GetPyCODACPath
46 __mcd_core_path = os.path.join(GetPyCODACPath(),
"Core")
59 files=VTL.GetSourceCode(0),
60 command=VTL.GetBuildCommand(5),
62 source=os.path.join(__mcd_core_path,
"src"),
63 include=[posixpath.join(__mcd_cluster_incpath, x)
for x
in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4,
"x64")],
64 make=__mcd_cluster_dev,
65 link=[posixpath.join(__mcd_cluster_libpath,
".".join([
"lib"+x,
"a"]))
for x
in VTL.GetLinkDependency(0, 4,
"x64")],
67 environment = VTL.GetEnvironment(0),
69 architecture=
"x64", scratch=VTL.Scratch, verbosity=0,
73 host=
"129.247.54.37", port=22,
77 Main function to execute the script.
80 envlist = list([]); envlist.append(environment); envlist = list(Utility.ArbitraryFlattening(envlist))
81 makelist = list([]); makelist.append(make); makelist = list(Utility.ArbitraryFlattening(makelist))
82 precommand= kwargs.get(
"precommand",
""); replace = kwargs.get(
'replace',
False)
84 SSHBuild = pyx.SSH(BuildID, files, scratch=scratch, arch=architecture, verbose=verbosity, incremental=incremental)
87 SSHBuild.Wrapper(BuildID)
88 SSHBuild.SourcePath(source)
89 SSHBuild.AddIncludePath(include)
92 SSHBuild.Environment(bash=x)
95 SSHBuild.OutputPath(modulepath=makelist[0], libpath=makelist[1])
98 SSHBuild.OutputPath(modulepath=posixpath.join(makelist[0],
"include"), libpath=posixpath.join(makelist[0],
"lib"))
99 if isinstance(replace,dict):
100 SSHBuild.Preprocessing(precommand,inend=
'.for', outend=
'.f90', replace=replace)
103 SSHBuild.Preprocessing(copyfiles=files)
105 SSHBuild.Preprocessing(precommand,inend=
'.for', outend=
'.f90')
106 SSHBuild.Build(command, linkedIn=link)
107 SSHBuild.Settings(user, key, host, port, **kwargs)
108 SSHBuild.create(**kwargs)
110if __name__ ==
"__main__":
114 parser = argparse.ArgumentParser(description=
"Build a static Fortran library remotely on the institute cluster")
115 parser.add_argument(
"user", metavar=
"user", nargs=1, help=
"Current user for SSH connection")
116 parser.add_argument(
"key", metavar=
"key", nargs=1, help=
"Path to private SSH key")
120 args, _ = parser.parse_known_args()
131 key = os.path.join(Utility.AsDrive(
"C"),
"Users",user,
"Keys",
"Putty",
"id_rsa")
134 box_source = os.path.join(__mcd_core_path,
"external",
"boxbeam")
135 box_make = [posixpath.join(__mcd_cluster_dev,
"include",
"boxbeam"), posixpath.join(__mcd_cluster_dev,
"lib")]
136 main(
'bbeam', user, key, files=VTL.GetSourceCode(1), source=box_source, include=[], make=box_make, link=[])
139 disp_source=os.path.join(__mcd_core_path,
"external",
"dispmodule",
"Fortran90",
"Src")
140 disp_make = [posixpath.join(__mcd_cluster_dev,
"include",
"dispmodule"), posixpath.join(__mcd_cluster_dev,
"lib")]
141 main(
"dispmodule" , user, key, files=VTL.GetSourceCode(5), command=VTL.GetBuildCommand(5,
"free"), source=disp_source,
142 include=[], make=disp_make, link=[], incremental=
True)
146 BuildIDs = [os.path.splitext(x)[0].lower()
for x
in VTL.GetSourceCode(6)]
147 for BuildID
in BuildIDs:
148 srcfile = [x
for x
in VTL.GetSourceCode(6)
if x.startswith(BuildID)]
150 style =
"fixed"; combine=
False
151 if not BuildID.endswith(
"790"):
152 style =
"free"; combine=
True
154 toms_source = os.path.join(__mcd_core_path,
"external",
"toms")
155 make = [posixpath.join(__mcd_cluster_dev,
"include",
"toms"),posixpath.join(__mcd_cluster_dev,
"lib")]
157 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5, style+
" -DPYX_WRAPPER"), make=make,
158 combine=combine, source=toms_source, include=[], libs=[], link=[])
161 pchip_replace = collections.OrderedDict([(
'rand',
"pchip_rand"), (
'RAND',
"pchip_rand"), (
'subroutine timestamp ( )',
'subroutine timestamp ( ) BIND(C, NAME="pchip_timestamp")')])
165 BuildIDs = [os.path.splitext(x)[0].lower()
for x
in VTL.GetSourceCode(7)]
166 for BuildID
in BuildIDs:
167 srcfile = [x
for x
in VTL.GetSourceCode(7)
if x.startswith(BuildID)]
169 source = os.path.join(__mcd_core_path,
"external",BuildID)
170 if BuildID ==
"pchip":
171 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5,
"free"),
172 source=source, include=[], link=[],
173 precommand=
"fpp -P", replace=pchip_replace)
175 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5,
"free"), source=source, include=[], link=[])
178 main(
'mcd_core', user, key)
181 raise NotImplementedError
184 print(
"==================================")
186 print(
"==================================")
Module containing all relevant modules and scripts associated with the building process.
main(BuildID, user, key, files=VTL.GetSourceCode(0), command=VTL.GetBuildCommand(5), source=os.path.join(__mcd_core_path,"src"), include=[posixpath.join(__mcd_cluster_incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")], make=__mcd_cluster_dev, link=[posixpath.join(__mcd_cluster_libpath, ".".join(["lib"+x,"a"])) for x in VTL.GetLinkDependency(0, 4, "x64")], environment=VTL.GetEnvironment(0), architecture="x64", scratch=VTL.Scratch, verbosity=0, incremental=False, host="129.247.54.37", port=22, **kwargs)