Skip to content

Commit fbb6b17

Browse files
committed
refactor: Got .cmd to work
1 parent f4a67aa commit fbb6b17

4 files changed

Lines changed: 65 additions & 58 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/results
66
/entries/entries.json
77
*.sh
8+
*.cmd
89

910
# Compiled l10n files: .mo should be ignored
1011
*.mo

utilities/common/utilities.data.entries.pas

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TEntry = class(TObject)
4040
FEntryFolder: TJSONStringType;
4141
FEntryBinary: TJSONStringType;
4242
FLPI: TJSONStringType;
43-
FDPR: TJSONStringType;
43+
FDPROJ: TJSONStringType;
4444
FHasRelease: Boolean;
4545
FThreads: Integer;
4646
FRunParams: TJSONStringType;
@@ -77,9 +77,9 @@ TEntry = class(TObject)
7777
property LPI: TJSONStringType
7878
read FLPI
7979
write FLPI;
80-
property DPR: TJSONStringType
81-
read FDPR
82-
write FDPR;
80+
property DPROJ: TJSONStringType
81+
read FDPROJ
82+
write FDPROJ;
8383
property HasRelease: Boolean
8484
read FHasRelease
8585
write FHasRelease;
@@ -149,7 +149,7 @@ implementation
149149
cJSONEntryFolder = 'entry-folder';
150150
cJSONEntryBinary = 'entry-binary';
151151
cJSONLPI = 'lpi';
152-
cJSONDPR = 'dpr';
152+
cJSONDPROJ = 'dproj';
153153
cJSONHasRelease = 'has-release';
154154
cJSONThreads = 'threads';
155155
cJSONRunParams = 'run-params';
@@ -172,7 +172,7 @@ constructor TEntry.Create;
172172
FEntryFolder:= '';
173173
FEntryBinary:= '';
174174
FLPI:= '';
175-
FDPR:= '';
175+
FDPROJ:= '';
176176
FHasRelease:= True;
177177
FThreads:= 1;
178178
FRunParams:= '';
@@ -207,7 +207,7 @@ procedure TEntry.setFromJSONObject(const AJSONObject: TJSONObject);
207207
FEntryFolder:= AJSONObject.Get(cJSONEntryFolder, FEntryFolder);
208208
FEntryBinary:= AJSONObject.Get(cJSONEntryBinary, FEntryBinary);
209209
FLPI:= AJSONObject.Get(cJSONLPI, FLPI);
210-
FDPR:= AJSONObject.Get(cJSONDPR, FDPR);
210+
FDPROJ:= AJSONObject.Get(cJSONDPROJ, FDPROJ);
211211
FHasRelease:= AJSONObject.Get(cJSONHasRelease, FHasRelease);
212212
FThreads:= AJSONObject.Get(cJSONThreads, FThreads);
213213
FRunParams:= AJSONObject.Get(cJSONRunParams, FRunParams);

utilities/script_builder/Common/scriptbuilder.common.pas

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ TBuilder = class(TObject)
3131
): String;
3232

3333
function GetHeader(const AHeader: String): String;
34-
function GetVariables: String;
34+
function GetVariablesBash: String;
3535
function GetFunctionCompileBash(const AEntry: TEntry): String;
3636
function GetFunctionCompileWindows(const AEntry: TEntry): String;
37-
function GetFunctionTest(const AEntry: TEntry): String;
38-
function GetFunctionRun(const AEntry: TEntry): String;
37+
function GetFunctionTestBash(const AEntry: TEntry): String;
38+
function GetFunctionRunBash(const AEntry: TEntry): String;
3939
protected
4040
public
4141
constructor Create(AConfigFile: String);
@@ -153,12 +153,15 @@ function TBuilder.GetHeader(const AHeader: String): String;
153153
{$ELSE}
154154
Result:= '@echo off' + LineEnding + LineEnding;
155155
Result:= Result + 'CALL rsvars' + LineEnding + LineEnding;
156-
Result:= Result + 'echo "******** ' + AHeader + ' ********"' + LineEnding;
157-
Result:= Result + 'echo' + LineEnding + LineEnding;
156+
Result:= Result + 'setlocal EnableExtensions EnableDelayedExpansion' + LineEnding + LineEnding;
157+
Result:= Result + 'echo "******** ' + AHeader + ' ********"' + LineEnding + LineEnding;
158+
Result:= Result + 'SET param=%1' + LineEnding + LineEnding;
159+
Result:= Result + 'if NOT DEFINED param CALL :all' + LineEnding;
160+
Result:= Result + 'if NOT DEFINED param EXIT /B' + LineEnding + LineEnding;
158161
{$ENDIF}
159162
end;
160163

161-
function TBuilder.GetVariables: String;
164+
function TBuilder.GetVariablesBash: String;
162165
begin
163166
Result:= 'BIN="' + FConfig.BinLinux + '"' + LineEnding;
164167
Result:= Result + 'ENTRIES="' + FConfig.EntriesLinux + '"' + LineEnding;
@@ -218,7 +221,7 @@ function TBuilder.GetFunctionCompileBash(const AEntry: TEntry): String;
218221
,
219222
[
220223
AEntry.EntryFolder,
221-
AEntry.DPR
224+
AEntry.DPROJ
222225
]) + LineEnding;
223226
{$ENDIF}
224227
Result:= Result + ' echo "==========="' + LineEnding;
@@ -228,24 +231,33 @@ function TBuilder.GetFunctionCompileBash(const AEntry: TEntry): String;
228231
function TBuilder.GetFunctionCompileWindows(const AEntry: TEntry): String;
229232
begin
230233
Result:= ':' + AEntry.EntryBinary + LineEnding;
234+
Result:= Result + 'echo ===== '+ UTF8Encode(AEntry.Name) +' ======' + LineEnding;
231235
Result:= Result +
232236
'msbuild /t:Build /p:Config=Release /p:platform=Linux64 ' +
233-
ConcatPaths([
234-
// FConfig.EntriesWindows,
235-
AEntry.EntryFolder,
236-
AEntry.DPR
237-
]) + LineEnding;
237+
ExpandFileName(
238+
ConcatPaths([
239+
FConfig.EntriesWindows,
240+
AEntry.EntryFolder,
241+
AEntry.DPROJ
242+
])
243+
) + LineEnding;
238244
Result:= Result + 'if ERRORLEVEL 0 (' + LineEnding;
239-
Result:= Result + ' scp bin\' + AEntry.EntryBinary +
240-
' gcarreno@10.42.0.1:/home/gcarreno/Programming/1brc-ObjectPascal/bin/' +
245+
Result:= Result + ' echo -- Transfering --' + LineEnding;
246+
Result:= Result + ' scp ' +
247+
ExpandFileName(ConcatPaths([
248+
FConfig.BinWindows,
249+
AEntry.EntryBinary
250+
])) +
251+
' gcarreno@10.42.0.1:' + FConfig.BinLinux + '/' +
241252
Aentry.EntryBinary + LineEnding;
242253
Result:= Result + ') else (' + LineEnding;
243254
Result:= Result + ' echo ERROR compiling' + LineEnding;
244255
Result:= Result + ')' + LineEnding;
245-
Result:= Result + 'EXIT /B' + LineEnding;
256+
Result:= Result + 'echo ===========' + LineEnding;
257+
Result:= Result + 'EXIT /B' + LineEnding + LineEnding;
246258
end;
247259

248-
function TBuilder.GetFunctionTest(const AEntry: TEntry): String;
260+
function TBuilder.GetFunctionTestBash(const AEntry: TEntry): String;
249261
var
250262
tmpStr: String;
251263
begin
@@ -294,7 +306,7 @@ function TBuilder.GetFunctionTest(const AEntry: TEntry): String;
294306
Result:= Result + ' echo' + LineEnding + '}' + LineEnding + LineEnding;
295307
end;
296308

297-
function TBuilder.GetFunctionRun(const AEntry: TEntry): String;
309+
function TBuilder.GetFunctionRunBash(const AEntry: TEntry): String;
298310
var
299311
tmpStr: String;
300312
begin
@@ -349,47 +361,31 @@ procedure TBuilder.BuildCompileScriptBash;
349361
line
350362
: TJSONStringType;
351363
begin
352-
{$IFDEF UNIX}
353364
FScriptFile:= IncludeTrailingPathDelimiter(FConfig.RootLinux) + cCompileBash;
354-
{$ELSE}
355-
FScriptFile:= IncludeTrailingPathDelimiter(FConfig.RootWIndows) + cCompileBash;
356-
{$ENDIF}
357365
FScriptStream:= TFileStream.Create(FScriptFile, fmCreate);
358366
try
359367
line:= GetHeader('Compile');
360-
line:= line + GetVariables;
368+
line:= line + GetVariablesBash;
361369
for index:= 0 to Pred(FConfig.Entries.Count) do
362370
begin
363371
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
364372
if not FConfig.Entries[index].Active then continue;
365-
{$IFDEF UNIX}
366373
if FConfig.Entries[index].Compiler <> cCompilerFPC then continue;
367-
{$ELSE}
368-
if FConfig.Entries[index].Compiler <> cCompilerDelphi then continue;
369-
{$ENDIF}
370374
line:= line + GetFunctionCompileBash(FConfig.Entries[index]);
371375
end;
372376
line:= line + 'if [ "$1" == "" ];then' + LineEnding;
373377
for index:= 0 to Pred(FConfig.Entries.Count) do
374378
begin
375379
if not FConfig.Entries[index].Active then continue;
376-
{$IFDEF UNIX}
377380
if FConfig.Entries[index].Compiler <> cCompilerFPC then continue;
378-
{$ELSE}
379-
if FConfig.Entries[index].Compiler <> cCompilerDelphi then continue;
380-
{$ENDIF}
381381
line:= line + ' ' + FConfig.Entries[index].EntryBinary + LineEnding;
382382
end;
383383
line:= line + 'else' + LineEnding;
384384
line:= line + ' case $1 in' + LineEnding;
385385
for index:= 0 to Pred(FConfig.Entries.Count) do
386386
begin
387387
if not FConfig.Entries[index].Active then continue;
388-
{$IFDEF UNIX}
389388
if FConfig.Entries[index].Compiler <> cCompilerFPC then continue;
390-
{$ELSE}
391-
if FConfig.Entries[index].Compiler <> cCompilerDelphi then continue;
392-
{$ENDIF}
393389
line:= line + ' ' + FConfig.Entries[index].EntryBinary + ')' + LineEnding;
394390
line:= line + ' ' + FConfig.Entries[index].EntryBinary + LineEnding;
395391
line:= line + ' ;;' + LineEnding;
@@ -419,25 +415,31 @@ procedure TBuilder.BuildCompileScriptCmd;
419415
line:= GetHeader('Compile');
420416
for index:=1 to Pred(FConfig.Entries.Count) do
421417
begin
422-
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
423-
if not FConfig.Entries[index].Active then continue;
424-
line:= line + GetFunctionCompileWindows(FConfig.Entries[index]);
418+
if FConfig.Entries[index].Compiler = cCompilerFPC then Continue;
419+
line:= line + 'if %1 == ' + FConfig.Entries[index].EntryBinary + ' (' + LineEnding;
420+
line:= line + ' CALL :' + FConfig.Entries[index].EntryBinary + LineEnding;
421+
line:= line + ' EXIT /B 0' + LineEnding;
422+
line:= line + ')' + LineEnding;
425423
end;
426-
line:= line + 'if [%1] == [] (' + LineEnding;
424+
line:= line + 'echo Unknown "%1"' + LineEnding;
425+
line:= line + 'EXIT /B 0' + LineEnding + LineEnding;
426+
line:= line + ':all' + LineEnding;
427427
for index:=1 to Pred(FConfig.Entries.Count) do
428428
begin
429-
line:= line + 'CALL ' + FConfig.Entries[index].EntryBinary + LineEnding;
429+
if not FConfig.Entries[index].Active then continue;
430+
if FConfig.Entries[index].Compiler = cCompilerFPC then Continue;
431+
line:= line + 'CALL :' + FConfig.Entries[index].EntryBinary + LineEnding;
430432
end;
431-
line:= line + ') else (' + LineEnding;
433+
line:= line + 'EXIT /B' + LineEnding;
434+
line:= line + LineEnding;
432435
for index:=1 to Pred(FConfig.Entries.Count) do
433436
begin
434-
line:= line + ' if %1 == ' + FConfig.Entries[index].EntryBinary + ' (' + LineEnding;
435-
line:= line + ' CALL FConfig.Entries[index].EntryBinary' + LineEnding;
436-
line:= line + ' EXIT 0' + LineEnding;
437-
line:= line + ' )' + LineEnding;
437+
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
438+
if not FConfig.Entries[index].Active then continue;
439+
if FConfig.Entries[index].Compiler = cCompilerFPC then Continue;
440+
line:= line + GetFunctionCompileWindows(FConfig.Entries[index]);
438441
end;
439-
line:= line + ' echo Unknown "%1"' + LineEnding;
440-
line:= line + ')' + LineEnding;
442+
FScriptStream.WriteBuffer(line[1], Length(line));
441443
finally
442444
FScriptStream.Free;
443445
end;
@@ -452,12 +454,12 @@ procedure TBuilder.BuildTestScriptBash;
452454
FScriptStream:= TFileStream.Create(FScriptFile, fmCreate);
453455
try
454456
line:= GetHeader('Test');
455-
line:= line + GetVariables;
457+
line:= line + GetVariablesBash;
456458
for index:= 0 to Pred(FConfig.Entries.Count) do
457459
begin
458460
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
459461
if not FConfig.Entries[index].Active then continue;
460-
line:= line + GetFunctionTest(FConfig.Entries[index]);
462+
line:= line + GetFunctionTestBash(FConfig.Entries[index]);
461463
end;
462464
line:= line + 'if [ "$1" == "" ];then' + LineEnding;
463465
for index:= 0 to Pred(FConfig.Entries.Count) do
@@ -497,13 +499,13 @@ procedure TBuilder.BuildRunScriptBash;
497499
FScriptStream:= TFileStream.Create(FScriptFile, fmCreate);
498500
try
499501
line:= GetHeader('Run');
500-
line:= line + GetVariables;
502+
line:= line + GetVariablesBash;
501503
for index:= 0 to Pred(FConfig.Entries.Count) do
502504
begin
503505
Write(GenerateProgressBar(index+1, FConfig.Entries.Count, 50), lineBreak);
504506
if not FConfig.Entries[index].Active then continue;
505507
if FConfig.Entries[index].EntryBinary = cBaselineBinary then continue;
506-
line:= line + GetFunctionRun(FConfig.Entries[index]);
508+
line:= line + GetFunctionRunBash(FConfig.Entries[index]);
507509
end;
508510
line:= line + 'if [ "$1" == "" ];then' + LineEnding;
509511
for index:= 0 to Pred(FConfig.Entries.Count) do

utilities/script_builder/Lazarus/src/scriptbuilder.lpr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,22 @@ procedure TScriptBuilder.DoRun;
8888

8989
FBuilder:= TBuilder.Create(configFilename);
9090
try
91+
{$IFDEF UNIX}
9192
WriteLn('=== Compile Script ===');
9293
FBuilder.BuildCompileScriptBash;
9394
WriteLn;
9495

95-
{$IFDEF UNIX}
9696
WriteLn('=== Test Script ===');
9797
FBuilder.BuildTestScriptBash;
9898
WriteLn;
9999

100100
WriteLn('=== Run Script ===');
101101
FBuilder.BuildRunScriptBash;
102102
WriteLn;
103+
{$ELSE}
104+
WriteLn('=== Compile Script ===');
105+
FBuilder.BuildCompileScriptCmd;
106+
WriteLn;
103107
{$ENDIF}
104108
finally
105109
FBuilder.Free;

0 commit comments

Comments
 (0)