summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-03-16 20:28:08 +0100
committerErich Eckner <git@eckner.net>2016-03-16 20:28:08 +0100
commit75ba2ce28e7b08ea8dabb83b08fe137dfe60a343 (patch)
tree90231911d3a5dbfe2668cac3833f87b0250b8dac
parent7bd08bcdbcedcc976afe1e38d572c83605aec2d1 (diff)
downloadunits-75ba2ce28e7b08ea8dabb83b08fe137dfe60a343.tar.xz
gitupdateunit.pas und refreshexecutableunit.pas verwenden jetzt
git-Hashes zum Identifizieren neuer Commits
-rw-r--r--.gitignore1
-rw-r--r--gitupdateunit.pas34
-rw-r--r--refreshexecutableunit.pas74
3 files changed, 78 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
index fa16a6e..fa14aab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
*~
*.o
*.ppu
+refreshexecutableunit_sums.inc
diff --git a/gitupdateunit.pas b/gitupdateunit.pas
index 536acf4..69346db 100644
--- a/gitupdateunit.pas
+++ b/gitupdateunit.pas
@@ -13,29 +13,31 @@ uses
process, systemunit, lowlevelunit, refreshExecutableUnit;
var
- updated: boolean;
- myDir,baseDir,
- output: string;
- args: array of string;
+ updated: boolean;
+ output: string;
+ args,gitDirs: tStringArray;
+ i: longint;
initialization
updated:=false;
- myDir:=extractFilePath(paramstr(0));
- baseDir:=extractFilePath(leftStr(myDir,length(myDir)-1));
+ setlength(gitDirs,2);
+ gitDirs[0]:=extractFilePath(paramstr(0));
+ gitDirs[1]:=extractFilePath(leftStr(gitDirs[0],length(gitDirs[0])-1))+'units/';
output:='';
- setlength(args,2);
- args[0]:='pull';
- args[1]:='--all';
- if runCommandInDir(myDir,'git',args,output) then begin
- 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
- refreshExecutable(myDir);
- end;
+ for i:=0 to length(gitDirs)-1 do begin
+ setlength(args,2);
+ args[0]:='pull';
+ args[1]:='--all';
+ if not runCommandInDir(gitDirs[i],'git',args,output) then continue;
+ output:=trim(output);
+ while pos(#10,output)>0 do
+ erstesArgument(output,#10);
+ updated:=updated or (output<>'Already up-to-date.') or (sourceSha512Sum(gitDirs[i])<>binarySha512Sum(i));
end;
+ if updated then
+ refreshExecutable(gitDirs);
setlength(args,0);
end.
diff --git a/refreshexecutableunit.pas b/refreshexecutableunit.pas
index 50da0a7..1984738 100644
--- a/refreshexecutableunit.pas
+++ b/refreshexecutableunit.pas
@@ -5,23 +5,46 @@ unit refreshexecutableunit;
interface
uses
- Classes, SysUtils;
+ Classes, SysUtils, lowlevelunit;
-procedure refreshExecutable(myDir: string);
+procedure refreshExecutable(dirs: tStringArray); // dirs[0] = Verzeichnis des Hauptprogramms, dirs[1] = Verzeichnis dieser Unit
+function sourceSha512Sum(dir: string): string;
+function binarySha512Sum(index: longint): string; inline;
implementation
-uses baseunix, systemunit, process, lowLevelUnit;
+uses baseunix, systemunit, process;
-procedure refreshExecutable(myDir: string);
+{$INCLUDE refreshexecutableunit_sums.inc}
+
+procedure refreshExecutable(dirs: tStringArray);
var
tmpDir,output,summeEins: string;
- args: array of string;
+ args: tStringArray;
+ i: longint;
+ f: textfile;
begin
output:='';
+
+ fileMode:=fmOpenWrite;
+
+ assignfile(f,dirs[1]+'refreshexecutableunit_sums.inc');
+ rewrite(f);
+ writeln(f,'const');
+ writeln(f,' sha512sums: array[0..1] of string = (');
+ for i:=0 to length(dirs)-1 do begin
+ write(f,' '''+sourceSha512Sum(dirs[i])+'''');
+ if i=length(dirs)-1 then
+ writeln(f)
+ else
+ writeln(f,',');
+ end;
+ writeln(f,' );');
+ closefile(f);
+
tmpDir:=mkTemp('-d /tmp/fpc.XXXXXX');
mkdir(tmpDir+'/lib');
- setlength(args,15);
+ setlength(args,13+length(dirs));
args[0]:='-MObjFPC';
args[1]:='-Scghi';
args[2]:='-Cg';
@@ -32,16 +55,17 @@ begin
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'
+ args[10]:='-FU'+tmpDir+'/lib';
+ args[11]:=dirs[0]+extractFileName(paramstr(0));
+ if fileexists(args[11]+'.lpr') then
+ args[11]:=args[11]+'.lpr'
else
- args[13]:=args[13]+'.pas';
- args[14]:='-o'+tmpDir+'/output';
- if runCommandInDir(myDir,'fpc',args,output) then begin
+ args[11]:=args[11]+'.pas';
+ args[12]:='-o'+tmpDir+'/output';
+ for i:=0 to length(dirs)-1 do
+ args[13+i]:='-Fu'+dirs[i];
+
+ if runCommandInDir(dirs[0],'fpc',args,output) then begin
setlength(args,2);
args[0]:=tmpDir+'/output';
args[1]:=paramstr(0);
@@ -70,5 +94,25 @@ begin
setlength(args,0);
end;
+function sourceSha512Sum(dir: string): string;
+var
+ args: tStringArray;
+begin
+ result:='';
+ setlength(args,3);
+ args[0]:='describe';
+ args[1]:='--always';
+ args[2]:='--abbrev=0';
+ if runCommandInDir(dir,'git',args,result) then
+ result:=trim(result)
+ else
+ result:='ungültig';
+end;
+
+function binarySha512Sum(index: longint): string;
+begin
+ result:=sha512sums[index];
+end;
+
end.