My favorites
▼
|
Sign in
upp-mirror
U++ is the C++ development platform
Project Home
Downloads
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
uppsrc
/
ide
/
Builders
/
ScriptBuilder.icpp
‹r3717
r5018
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include "Builders.h"
#include <Esc/Esc.h>
EscValue ScriptBuilder::ExecuteIf(const char *fn, Vector<EscValue>& args)
{
CheckParse();
EscValue out;
int f = globals.Find(fn);
if(f < 0)
return out;
try
{
out = ::Execute(globals, NULL, globals[f], args, 50000);
}
catch(Exc e)
{
script_error = true;
PutConsole(e);
}
return out;
}
EscValue ScriptBuilder::ExecuteIf(const char *fn)
{
Vector<EscValue> args;
return ExecuteIf(fn, args);
}
EscValue ScriptBuilder::ExecuteIf(const char *fn, EscValue arg)
{
Vector<EscValue> args;
args.Add(arg);
return ExecuteIf(fn, args);
}
EscValue ScriptBuilder::ExecuteIf(const char *fn, EscValue arg1, EscValue arg2)
{
Vector<EscValue> args;
args.Add(arg1);
args.Add(arg2);
return ExecuteIf(fn, args);
}
EscValue ScriptBuilder::ExecuteIf(const char *fn, EscValue arg1, EscValue arg2, EscValue arg3)
{
Vector<EscValue> args;
args.Add(arg1);
args.Add(arg2);
args.Add(arg3);
return ExecuteIf(fn, args);
}
void ScriptBuilder::ESC_Execute(EscEscape& e)
{
e = Execute(String(e[0])) ? 0 : 1;
}
void ScriptBuilder::ESC_PutConsole(EscEscape& e)
{
PutConsole(String(e[0]));
}
void ScriptBuilder::ESC_PutVerbose(EscEscape& e)
{
PutVerbose(String(e[0]));
}
void ScriptBuilder::CheckParse()
{
if(is_parsed)
return;
script_error = false;
is_parsed = true;
StdLib(globals);
Escape(globals, "Execute(cmdline)", THISBACK(ESC_Execute));
Escape(globals, "PutConsole(text)", THISBACK(ESC_PutConsole));
Escape(globals, "PutVerbose(text)", THISBACK(ESC_PutVerbose));
EscValue inclist;
inclist.SetEmptyArray();
for(int i = 0; i < include.GetCount(); i++)
inclist.ArrayAdd(GetHostPathQ(include[i]));
globals.GetAdd("INCLUDE") = inclist;
EscValue liblist;
liblist.SetEmptyArray();
for(int i = 0; i < libpath.GetCount(); i++)
liblist.ArrayAdd(GetHostPathQ(libpath[i]));
globals.GetAdd("LIBPATH") = liblist;
try
{
String sdata = LoadFile(script);
if(IsNull(sdata))
throw Exc(NFormat("%s: not found or empty", script));
CParser parser(sdata, script, 1);
while(!parser.IsEof()) {
String id = parser.ReadId();
globals.GetAdd(id) = ReadLambda(parser);
}
}
catch(Exc e)
{
script_error = true;
PutConsole(e);
}
}
bool ScriptBuilder::BuildPackage(const String& package, Vector<String>& linkfile, String& linkoptions,
const Vector<String>& all_uses, const Vector<String>& all_libraries, int)
{
int i;
String packagepath = PackagePath(package);
Package pkg;
pkg.Load(packagepath);
String packagedir = GetFileFolder(packagepath);
ChDir(packagedir);
PutVerbose("cd " + packagedir);
Vector<String> obj;
script_error = false;
String gfl = Gather(pkg.option, config.GetKeys());
Vector<String> sfile;
Vector<String> soptions;
bool error = false;
for(i = 0; i < pkg.GetCount(); i++) {
if(!IdeIsBuilding())
return false;
if(!pkg[i].separator) {
String gop = Gather(pkg[i].option, config.GetKeys());
Vector<String> srcfile = CustomStep(pkg[i], package, error);
if(srcfile.GetCount() == 0)
error = true;
for(int j = 0; j < srcfile.GetCount(); j++) {
String fn = srcfile[j];
String ext = ToLower(GetFileExt(fn));
if(ext == ".c" || ext == ".cpp" || ext == ".cc" || ext == ".cxx" ||
(ext == ".rc" && HasFlag("WIN32"))) {
sfile.Add(fn);
soptions.Add(gfl + " " + gop);
}
else
if(ext == ".o")
obj.Add(fn);
else
if(ext == ".a" || ext == ".so")
linkfile.Add(fn);
}
}
}
/*
if(HasFlag("BLITZ")) {
Blitz b = BlitzStep(sfile, soptions, obj, ".o");
if(b.build) {
PutConsole("BLITZ:" + b.info);
int time = GetTickCount();
if(Execute(cc + " " + GetHostPathQ(b.path) + " -o " + GetHostPathQ(b.object)) == 0)
PutCompileTime(time, b.count);
else
error = true;
}
}
*/
int time = GetTickCount();
int ccount = 0;
for(i = 0; i < sfile.GetCount() && !script_error; i++) {
if(!IdeIsBuilding())
return false;
String fn = sfile[i];
String ext = ToLower(GetFileExt(fn));
// bool rc = ext == ".rc";
String objfile = ExecuteIf("objectfile", fn);
if(script_error)
return false;
if(IsNull(objfile))
objfile = CatAnyPath(outdir, GetFileTitle(fn) + ".o");
if(HdependFileTime(fn) > GetFileTime(GetHostPath(objfile))) {
PutConsole(GetFileName(fn));
int time = GetTickCount();
if(!ExecuteIf("compile", GetHostPathQ(fn), GetHostPathQ(objfile), soptions[i]).GetNumber()) {
DeleteFile(objfile);
error = true;
}
PutVerbose("compiled in " + GetPrintTime(time));
ccount++;
}
obj.Add(objfile);
}
if(ccount)
PutCompileTime(time, ccount);
if(error || script_error)
return false;
linkoptions << Gather(pkg.link, config.GetKeys());
Vector<String> libs = Split(Gather(pkg.library, config.GetKeys()), ' ');
linkfile.Append(libs);
time = GetTickCount();
if(!HasFlag("MAIN")) {
if(HasFlag("NOLIB")) {
linkfile.Append(obj);
return true;
}
String product = ExecuteIf("libraryfile", package);
if(IsNull(product))
product = CatAnyPath(outdir, GetAnyFileName(package) + ".a");
Time producttime = GetFileTime(product);
linkfile.Add("*" + product); //!! ugly
for(int i = 0; i < obj.GetCount(); i++)
if(GetFileTime(obj[i]) > producttime) {
PutConsole("Creating library...");
DeleteFile(product);
EscValue objlist;
objlist.SetEmptyArray();
for(int i = 0; i < obj.GetCount(); i++)
objlist.ArrayAdd(GetHostPathQ(obj[i]));
if(!ExecuteIf("library", objlist, product).GetNumber()) {
DeleteFile(product);
error = true;
return false;
}
PutConsole(String().Cat() << product << " (" << GetFileInfo(product).length
<< " B) created in " << GetPrintTime(time));
break;
}
return true;
}
obj.Append(linkfile);
linkfile = obj;
return true;
}
bool ScriptBuilder::Link(const Vector<String>& linkfile, const String& linkoptions, bool)
{
int time = GetTickCount();
for(int i = 0; i < linkfile.GetCount(); i++)
if(GetFileTime(linkfile[i]) >= targettime) {
EscValue objlist;
objlist.SetEmptyArray();
EscValue liblist;
liblist.SetEmptyArray();
for(i = 0; i < linkfile.GetCount(); i++)
if(*linkfile[i] == '*')
liblist.ArrayAdd(GetHostPathQ(linkfile[i].Mid(1)));
else
objlist.ArrayAdd(GetHostPathQ(linkfile[i]));
Vector<EscValue> linkargs;
linkargs.Add(objlist);
linkargs.Add(liblist);
linkargs.Add(GetHostPathQ(target));
linkargs.Add(linkoptions);
PutConsole("Linking...");
bool error = false;
CustomStep(".pre-link", Null, error);
if(!error && !ExecuteIf("link", linkargs).GetNumber()) {
DeleteFile(target);
return false;
}
CustomStep(".post-link", Null, error);
PutConsole(String().Cat() << GetHostPath(target) << " (" << GetFileInfo(target).length
<< " B) linked in " << GetPrintTime(time));
return !error;
}
PutConsole(String().Cat() << GetHostPath(target) << " (" << GetFileInfo(target).length
<< " B) is up to date.");
return true;
}
bool ScriptBuilder::Preprocess(const String& package, const String& file, const String& target, bool)
{
return ExecuteIf("preprocess", file, target).GetNumber();
}
Builder *CreateScriptBuilder()
{
return new ScriptBuilder;
}
INITBLOCK
{
RegisterBuilder("SCRIPT", CreateScriptBuilder);
}
/*
EscValue LayoutItem::CreateEsc() const
{
EscValue ctrl;
String tp = type;
String tm;
if(ParseTemplate(tp, tm)) {
CreateMethods(ctrl, tp, true);
ctrl("CtrlPaint") = ctrl("Paint");
CreateMethods(ctrl, tm, false);
}
else
CreateMethods(ctrl, tp, false);
for(int q = 0; q < property.GetCount(); q++) {
EscValue& w = ctrl(property[q].name);
const Value& v = ~property[q];
if(IsType<Font>(v))
w = EscFont(v);
if(IsString(v))
w = (WString)v;
if(IsNumber(v))
w = (double)v;
if(IsType<Color>(v))
w = EscColor(v);
}
ctrl("type") = (WString)type;
ctrl("GetSize") = ReadLambda(Format("() { return Size(%d, %d); }",
csize.cx, csize.cy));
ctrl("GetRect") = ReadLambda(Format("() { return Rect(0, 0, %d, %d); }",
csize.cx, csize.cy));
return ctrl;
}
EscValue LayoutItem::ExecuteMethod(const char *method, Vector<EscValue>& arg) const
{
try {
EscValue self = CreateEsc();
return ::Execute(UscGlobal(), &self, method, arg, 50000);
}
catch(CParser::Error& e) {
PutConsole(e + "\n");
}
return EscValue();
}
EscValue LayoutItem::ExecuteMethod(const char *method) const
{
Vector<EscValue> arg;
return ExecuteMethod(method, arg);
}
Size LayoutItem::GetMinSize()
{
return SizeEsc(ExecuteMethod("GetMinSize"));
}
*/
Show details
Hide details
Change log
r4203
by cxl on Nov 25, 2011
Diff
ide: Custom build steps refresh
Go to:
/trunk/uppsrc/Core/Format.cpp
...k/uppsrc/art/BlueBar/BlueBar.upp
...k/uppsrc/ide/Builders/Builders.h
...psrc/ide/Builders/CppBuilder.cpp
...src/ide/Builders/GccBuilder.icpp
...rc/ide/Builders/JavaBuilder.icpp
...src/ide/Builders/MscBuilder.icpp
...src/ide/Builders/OwcBuilder.icpp
.../ide/Builders/ScriptBuilder.icpp
/trunk/uppsrc/ide/Builders/init
/trunk/uppsrc/ide/Custom.cpp
Project members,
sign in
to write a code review
Older revisions
r3717
by cxl on Jul 30, 2011
Diff
.devloping umake
All revisions of this file
File info
Size: 8935 bytes, 344 lines
View raw file
Powered by
Google Project Hosting