-
Notifications
You must be signed in to change notification settings - Fork 37
/
runcompile.vbs
165 lines (136 loc) · 3.57 KB
/
runcompile.vbs
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
Option Explicit
Function FormatBatch(basedir,compiletarget,slnfile,target,fname,vsver)
dim fso,fh,cmdline
set fso = WScript.CreateObject("Scripting.FileSystemObject")
set fh = fso.CreateTextFile(fname,True)
fh.WriteLine(GetVsAllBatchCall(vsver,basedir,compiletarget))
fh.WriteLine(GetDevenvSlnRun(vsver,slnfile,basedir,target))
fh.Close
set fh = Nothing
set fso = Nothing
End Function
Sub includeFile(fSpec)
With CreateObject("Scripting.FileSystemObject")
executeGlobal .openTextFile(fSpec).readAll()
End With
End Sub
Function GetScriptDir()
dim fso ,scriptpath
Set fso = CreateObject("Scripting.FileSystemObject")
GetScriptDir=fso.GetParentFolderName(Wscript.ScriptFullName)
End Function
call includeFile( GetScriptDir() & "\reg_op.vbs")
call includeFile( GetScriptDir() & "\vs_find.vbs")
call includeFile( GetScriptDir() & "\base_func.vbs")
dim targets(),models(),sln
Function Usage(ec,fmt)
dim fh
set fh = WScript.Stderr
if ec = 0 Then
set fh = WScript.Stdout
End if
if fmt <> "" Then
fh.Writeline(fmt)
End if
fh.Writeline(WScript.ScriptName & " [OPTIONS]")
fh.Writeline(chr(9) &"-h|--help to display this information")
fh.Writeline(chr(9) &"-s|--sln slnfile to specify the sln file name")
fh.Writeline(chr(9) &"-t|--target target model to specify target in sln file")
WScript.Quit(ec)
End Function
Function ParseArgs(args)
dim i,j,unum
j = UBound(args)
i = 0
While i < j
if args(i) = "-h" or args(i) = "--help" Then
Usage 0,""
elseif args(i) = "-s" or args(i) = "--sln" Then
if (i+1) = j Then
Usage 3,args(i) &" need an arg"
End If
sln = args((i + 1))
i = i + 1
elseif args(i) = "-t" or args(i) = "--target" Then
if (i+2) = j Then
Usage 3,args(i) &" need an arg"
End If
On error resume next
Err.Number = 0
unum = Ubound(targets)
if Err.Number <> 0 Then
unum = 0
End If
On error goto 0
WScript.Stdout.Writeline("targets "& unum)
unum = unum + 1
redim preserve targets(unum)
targets((unum-1)) = args((i + 1))
WScript.Stdout.Writeline("target add("& targets((unum-1)) &")")
i = i + 1
On error resume next
Err.Number = 0
unum = Ubound(models)
if Err.Number <> 0 Then
unum = 0
End If
On error goto 0
WScript.Stdout.Writeline("models "& unum)
unum = unum + 1
redim preserve models(unum)
models((unum-1)) = args((i + 1))
WScript.Stdout.Writeline("model add("& models((unum-1)) &")")
i = i + 1
End if
i = i + 1
Wend
End Function
Function ReplaceString(s,o,p)
dim sarr,i,repl,c
sarr=Split(s,"")
repl=""
for i=0 to len(s)
c=Right(left(s,i),1)
if c = o Then
repl = repl & p
else
repl = repl & c
End If
Next
ReplaceString=repl
End Function
dim args(),num,i
num = WScript.Arguments.Count()
if num = 0 Then
Usage 3,"need args"
End if
redim args(num)
for i=0 to (num - 1)
args(i) = WScript.Arguments.Item(i)
next
ParseArgs(args)
dim basedir,vsver,vspdir,iidx,jidx
vsver=IsInstallVisualStudio(10.0)
If IsEmpty(vsver) Then
wscript.stderr.writeline("can not find visual studio installed")
wscript.Quit(3)
End If
basedir=GetVisualStudioInstdir(10.0)
if IsEmpty(basedir) Then
wscript.stderr.writeline("can not find visual studio install directory")
wscript.quit(5)
End If
iidx=0
do while iidx < Ubound(targets)
dim d,m,fname
if targets(iidx) <> "" Then
d = targets(iidx)
m = models(iidx)
fname = ReplaceString(d,"|","_")
fname = fname & ".bat"
wscript.stderr.writeline("fname " & fname)
call FormatBatch(basedir,m, sln, d, fname,vsver)
call RunCommand(fname)
End If
iidx = iidx + 1
Loop