summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gitupdateunit.pas48
-rw-r--r--refreshexecutableunit.pas67
2 files changed, 70 insertions, 45 deletions
diff --git a/gitupdateunit.pas b/gitupdateunit.pas
index ec6c188..1542940 100644
--- a/gitupdateunit.pas
+++ b/gitupdateunit.pas
@@ -10,7 +10,7 @@ uses
implementation
uses
- baseunix, process, systemunit, lowlevelunit;
+ process, systemunit, lowlevelunit, refreshExecutableUnit;
var
updated: boolean;
@@ -34,50 +34,8 @@ initialization
updated:=updated or (output<>'Already up-to-date.'#10);
if runCommandInDir(baseDir+'units','git',args,output) then begin
updated:=updated or (output<>'Already up-to-date.'#10);
- if updated then begin
- tmpDir:=mkTemp('-d /tmp/fpc.XXXXXX');
- mkdir(tmpDir+'/lib');
- setlength(args,15);
- args[0]:='-MObjFPC';
- args[1]:='-Scghi';
- args[2]:='-Cg';
- args[3]:='-CirotR';
- args[4]:='-O1';
- args[5]:='-g';
- args[6]:='-gl';
- args[7]:='-l';
- args[8]:='-vewnhibq';
- args[9]:='-Fi'+tmpDir+'/lib';
- args[10]:='-Fu../units';
- args[11]:='-Fu.';
- args[12]:='-FU'+tmpDir+'/lib';
- args[13]:=myDir+extractFileName(paramstr(0));
- if fileexists(args[13]+'.lpr') then
- args[13]:=args[13]+'.lpr'
- else
- args[13]:=args[13]+'.pas';
- args[14]:='-o'+tmpDir+'/output';
- if runCommandInDir(myDir,'fpc',args,output) then begin
- setlength(args,2);
- args[0]:=tmpDir+'/output';
- args[1]:=paramstr(0);
- if runCommand('sha512sum',args,output) then begin
- baseDir:=erstesArgument(output,#10);
- if erstesArgument(baseDir)<>erstesArgument(output) then begin
- deletefile(paramstr(0));
- if runCommand('mv',args,output) then begin
- setlength(args,2);
- args[0]:='-rf';
- args[1]:=tmpDir;
- if runCommand('rm',args,output) then begin
- fpExecVe(paramstr(0),argv,envp);
- raise exception.create('Fehler beim Ersetzen der Executable!');
- end;
- end;
- end;
- end;
- end;
- end;
+ if updated then
+ refreshExecutable(myDir);
end;
end;
if (tmpDir<>'') and directoryexists(tmpDir) then begin
diff --git a/refreshexecutableunit.pas b/refreshexecutableunit.pas
new file mode 100644
index 0000000..1ce9655
--- /dev/null
+++ b/refreshexecutableunit.pas
@@ -0,0 +1,67 @@
+unit refreshexecutableunit;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ Classes, SysUtils;
+
+procedure refreshExecutable(myDir: string);
+
+implementation
+
+uses baseunix, systemunit, process, lowLevelUnit;
+
+procedure refreshExecutable(myDir: string);
+var
+ tmpDir,output,summeEins: string;
+ args: array of string;
+begin
+ output:='';
+ tmpDir:=mkTemp('-d /tmp/fpc.XXXXXX');
+ mkdir(tmpDir+'/lib');
+ setlength(args,15);
+ args[0]:='-MObjFPC';
+ args[1]:='-Scghi';
+ args[2]:='-Cg';
+ args[3]:='-CirotR';
+ args[4]:='-O1';
+ args[5]:='-g';
+ args[6]:='-gl';
+ args[7]:='-l';
+ args[8]:='-vewnhibq';
+ args[9]:='-Fi'+tmpDir+'/lib';
+ args[10]:='-Fu../units';
+ args[11]:='-Fu.';
+ args[12]:='-FU'+tmpDir+'/lib';
+ args[13]:=myDir+extractFileName(paramstr(0));
+ if fileexists(args[13]+'.lpr') then
+ args[13]:=args[13]+'.lpr'
+ else
+ args[13]:=args[13]+'.pas';
+ args[14]:='-o'+tmpDir+'/output';
+ if runCommandInDir(myDir,'fpc',args,output) then begin
+ setlength(args,2);
+ args[0]:=tmpDir+'/output';
+ args[1]:=paramstr(0);
+ if runCommand('sha512sum',args,output) then begin
+ summeEins:=erstesArgument(output,#10);
+ if erstesArgument(summeEins)<>erstesArgument(output) then begin
+ deletefile(paramstr(0));
+ if runCommand('mv',args,output) then begin
+ setlength(args,2);
+ args[0]:='-rf';
+ args[1]:=tmpDir;
+ if runCommand('rm',args,output) then begin
+ fpExecVe(paramstr(0),argv,envp);
+ raise exception.create('Fehler beim Ersetzen der Executable!');
+ end;
+ end;
+ end;
+ end;
+ end;
+end;
+
+end.
+