-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettarg_cmd.in.lua
executable file
·187 lines (156 loc) · 6.02 KB
/
settarg_cmd.in.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!@path_to_lua@
-- -*- lua -*-
--------------------------------------------------------------------------
-- Lmod License
--------------------------------------------------------------------------
--
-- Lmod is licensed under the terms of the MIT license reproduced below.
-- This means that Lmod is free software and can be used for both academic
-- and commercial purposes at absolutely no cost.
--
-- ----------------------------------------------------------------------
--
-- Copyright (C) 2008-2018 Robert McLay
--
-- Permission is hereby granted, free of charge, to any person obtaining
-- a copy of this software and associated documentation files (the
-- "Software"), to deal in the Software without restriction, including
-- without limitation the rights to use, copy, modify, merge, publish,
-- distribute, sublicense, and/or sell copies of the Software, and to
-- permit persons to whom the Software is furnished to do so, subject
-- to the following conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
-- BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-- ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
--
--------------------------------------------------------------------------
local LuaCommandName = arg[0]
local ia,ja = LuaCommandName:find(".*/")
local LuaCommandName_dir = "./"
if (ia) then
LuaCommandName_dir = LuaCommandName:sub(1,ja)
end
local sys_lua_path = "@sys_lua_path@"
if (sys_lua_path:sub(1,1) == "@") then
sys_lua_path = package.path
end
local sys_lua_cpath = "@sys_lua_cpath@"
if (sys_lua_cpath:sub(1,1) == "@") then
sys_lua_cpath = package.cpath
end
package.path = LuaCommandName_dir .. "../tools/?.lua;" ..
LuaCommandName_dir .. "../tools/?/init.lua;" ..
LuaCommandName_dir .. "?.lua;" ..
LuaCommandName_dir .. "?/init.lua;" ..
sys_lua_path
package.cpath = LuaCommandName_dir .. "../lib/?.so;"..
sys_lua_cpath
_G._DEBUG = false
local posix = require("posix")
function cmdDir()
return LuaCommandName_dir
end
if (not pcall(require,"strict")) then
os.exit(0)
end
local s_optionTbl = {}
function optionTbl()
return s_optionTbl
end
BaseShell = require("BaseShell")
local dbg = require("Dbg"):dbg()
local CmdLineOptions = require("CmdLineOptions")
local BuildTarget = require("BuildTarget")
local STT = require("STT")
local cosmic = require("Cosmic"):singleton()
local getenv = os.getenv
require("ModifyPath")
require("Output")
require("serializeTbl")
------------------------------------------------------------------------
-- LMOD_LD_LIBRARY_PATH: LD_LIBRARY_PATH found at configure
------------------------------------------------------------------------
local ld_lib_path = "@sys_ld_lib_path@"
if (ld_lib_path:sub(1,1) == "@") then
ld_lib_path = getenv("LD_LIBRARY_PATH")
end
if (ld_lib_path == "") then
ld_lib_path = false
end
cosmic:init{name = "LMOD_LD_LIBRARY_PATH",
default = false,
assignV = ld_lib_path}
------------------------------------------------------------------------
-- LMOD_LD_PRELOAD: LD_PRELOAD found at configure
------------------------------------------------------------------------
local ld_preload = "@sys_ld_preload@"
if (ld_preload:sub(1,1) == "@") then
ld_preload = getenv("LD_PRELOAD")
end
if (ld_preload == "") then
ld_preload = nil
end
cosmic:init{name = "LMOD_LD_PRELOAD",
default = false,
assignV = ld_preload}
function main()
local optionTbl = optionTbl()
optionTbl.execDir = cmdDir()
CmdLineOptions:options()
if (optionTbl.debug) then
dbg:activateDebug(1)
end
dbg.start{"settarg()"}
-- Error out if there are spaces in command line arguments
for i = 1,#optionTbl.pargs do
local s = optionTbl.pargs[i]
if (s:find("%s")) then
io.stderr:write("Error: Argument #",i," has spaces in it: \"",s,"\"\n")
os.exit(1)
end
end
if (optionTbl.cmdHelp) then
io.stderr:write("Lmod settarg ",Version.name(),"\n")
io.stderr:write(optionTbl.cmdHelpMsg,"\n")
dbg.fini("settarg")
return
end
if (optionTbl.version) then
io.stderr:write("Lmod settarg ",Version.name(),"\n")
os.exit(0)
end
------------------------------------------
-- Build shell object
local shell = BaseShell.build(optionTbl.shell)
BuildTarget.exec(shell)
if (optionTbl.report) then
io.stderr:write(serializeTbl{name="SettargConfigFnA", indent=true, value=optionTbl.SttgConfFnA},"\n")
io.stderr:write(serializeTbl{name="BuildScenarioTbl", indent=true, value=optionTbl.BuildScenarioTbl},"\n")
io.stderr:write(serializeTbl{name="HostnameTbl", indent=true, value=optionTbl.HostTbl}, "\n")
io.stderr:write(serializeTbl{name="ModuleTbl", indent=true, value=optionTbl.ModuleTbl}, "\n")
io.stderr:write(serializeTbl{name="TargetList", indent=true, value=optionTbl.targetList}, "\n")
io.stderr:write(serializeTbl{name="SettargDirTemplate", indent=true, value=optionTbl.SettargDirTmpl}, "\n")
io.stderr:write(serializeTbl{name="TitleTbl", indent=true, value=optionTbl.TitleTbl}, "\n")
io.stderr:write("TargPathLoc = \"",optionTbl.TargPathLoc,"\"\n")
dbg.fini("settarg")
return
end
if (optionTbl.stt) then
local stt = STT:stt()
local s = stt:serializeTbl("pretty")
io.stderr:write(s,"\n")
end
ModifyPath()
Output(shell)
dbg.fini("settarg")
end
main()