6 Triple-use minimum working example for PyXMake. This script can be 7 executed 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 ---------------------------------------------------------------------------------------------- 29 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
33 from PyXMake
import VTL
36 __user = os.getenv(
"username")
37 __mcd_cluster_dev = posixpath.join(Utility.AsDrive(
"home",posixpath.sep),__user,
"mcodac")
38 __mcd_cluster_incpath = posixpath.join(__mcd_cluster_dev,
"include")
39 __mcd_cluster_libpath = posixpath.join(__mcd_cluster_dev,
"lib")
43 from PyCODAC.Tools.Utility
import GetPyCODACPath
45 __mcd_core_path = os.path.join(GetPyCODACPath(),
"Core")
52 ErrorHandling.InputError(20)
58 files=VTL.GetSourceCode(0),
59 command=VTL.GetBuildCommand(5),
61 source=os.path.join(__mcd_core_path,
"src"),
62 include=[posixpath.join(__mcd_cluster_incpath, x)
for x
in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4,
"x64")],
63 make=__mcd_cluster_dev,
64 link=[posixpath.join(__mcd_cluster_libpath,
"libinterpx64.a"),
65 posixpath.join(__mcd_cluster_libpath,
"libpchipx64.a"),
66 posixpath.join(__mcd_cluster_libpath,
"libbbeamx64.a"),
67 posixpath.join(__mcd_cluster_libpath,
"libmueslix64.a"),
68 posixpath.join(__mcd_cluster_libpath,
"libdispmodulex64.a"),
69 posixpath.join(__mcd_cluster_libpath,
"libtomsx64.a")],
71 environment = VTL.GetEnvironment(0),
73 architecture=
"x64", scratch=VTL.Scratch, verbosity=0,
77 host=
"129.247.54.37", port=22,
81 Main function to execute the script. 84 envlist = list([]); envlist.append(environment); envlist = list(Utility.ArbitraryFlattening(envlist))
85 makelist = list([]); makelist.append(make); makelist = list(Utility.ArbitraryFlattening(makelist))
86 precommand= kwargs.get(
"precommand",
""); replace = kwargs.get(
'replace',
False)
88 SSHBuild = pyx.SSH(BuildID, files, scratch=scratch, arch=architecture, verbose=verbosity, incremental=incremental)
91 SSHBuild.Wrapper(BuildID)
92 SSHBuild.SourcePath(source)
93 SSHBuild.AddIncludePath(include)
96 SSHBuild.Environment(bash=x)
99 SSHBuild.OutputPath(modulepath=makelist[0], libpath=makelist[1])
102 SSHBuild.OutputPath(modulepath=posixpath.join(makelist[0],
"include"), libpath=posixpath.join(makelist[0],
"lib"))
103 if isinstance(replace,dict):
104 SSHBuild.Preprocessing(precommand,inend=
'.for', outend=
'.f90', replace=replace)
107 SSHBuild.Preprocessing(copyfiles=files)
109 SSHBuild.Preprocessing(precommand,inend=
'.for', outend=
'.f90')
110 SSHBuild.Build(command, linkedIn=link)
111 SSHBuild.Settings(user, key, host, port)
112 SSHBuild.create(**kwargs)
114 if __name__ ==
"__main__":
118 parser = argparse.ArgumentParser(description=
"Build a static Fortran library remotely on the institute cluster")
119 parser.add_argument(
"user", metavar=
"user", nargs=1, help=
"Current user for SSH connection")
120 parser.add_argument(
"key", metavar=
"key", nargs=1, help=
"Path to private SSH key")
124 args, _ = parser.parse_known_args()
135 key = os.path.join(Utility.AsDrive(
"C"),
"Users",user,
"Keys",
"Putty",
"id_rsa")
138 box_source = os.path.join(__mcd_core_path,
"external",
"boxbeam")
139 box_make = [posixpath.join(__mcd_cluster_dev,
"include",
"boxbeam"), posixpath.join(__mcd_cluster_dev,
"lib")]
140 main(
'bbeam', user, key, files=VTL.GetSourceCode(1), source=box_source, include=[], make=box_make, link=[])
143 disp_source=os.path.join(__mcd_core_path,
"external",
"dispmodule",
"Fortran90",
"Src")
144 disp_make = [posixpath.join(__mcd_cluster_dev,
"include",
"dispmodule"), posixpath.join(__mcd_cluster_dev,
"lib")]
145 main(
"dispmodule" , user, key, files=VTL.GetSourceCode(5), command=VTL.GetBuildCommand(5,
"free"), source=disp_source,
146 include=[], make=disp_make, link=[], incremental=
True)
150 BuildIDs = [os.path.splitext(x)[0].lower()
for x
in VTL.GetSourceCode(6)]
151 for BuildID
in BuildIDs:
152 srcfile = [x
for x
in VTL.GetSourceCode(6)
if x.startswith(BuildID)]
154 style =
"fixed"; combine=
False 155 if not BuildID.endswith(
"790"):
156 style =
"free"; combine=
True 158 toms_source = os.path.join(__mcd_core_path,
"external",
"toms")
159 make = [posixpath.join(__mcd_cluster_dev,
"include",
"toms"),posixpath.join(__mcd_cluster_dev,
"lib")]
161 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5, style+
" -DPYX_WRAPPER"), make=make,
162 combine=combine, source=toms_source, include=[], libs=[], link=[])
165 pchip_replace = {
'FUNCTION RAND ( R )':
'FUNCTION RAND ( R ) BIND(C, NAME="pchip_rand")',
166 'subroutine timestamp ( )':
'subroutine timestamp ( ) BIND(C, NAME="pchip_timestamp")'}
170 BuildIDs = [os.path.splitext(x)[0].lower()
for x
in VTL.GetSourceCode(7)]
171 for BuildID
in BuildIDs:
172 srcfile = [x
for x
in VTL.GetSourceCode(7)
if x.startswith(BuildID)]
174 source = os.path.join(__mcd_core_path,
"external",BuildID)
175 if BuildID ==
"pchip":
176 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5,
"free"),
177 source=source, include=[], link=[],
178 precommand=
"fpp -P", replace=pchip_replace)
180 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5,
"free"), source=source, include=[], link=[])
183 main(
'mcd_core', user, key)
186 raise NotImplementedError
189 print(
"==================================")
191 print(
"==================================")
def 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,"libinterpx64.a"), posixpath, join, __mcd_cluster_libpath, libpchipx64, a, posixpath, join, __mcd_cluster_libpath, libbbeamx64, a, posixpath, join, __mcd_cluster_libpath, libmueslix64, a, posixpath, join, __mcd_cluster_libpath, libdispmodulex64, a, posixpath, join, __mcd_cluster_libpath, libtomsx64, a, environment=VTL.GetEnvironment(0), architecture="x64", scratch=VTL.Scratch, verbosity=0, incremental=False, host="129.247.54.37", port=22, kwargs)
Module containing all relevant modules and scripts associated with the building process.