Skip to content

Commit

Permalink
return use/bgrabitmap and use/bgracontrols
Browse files Browse the repository at this point in the history
  • Loading branch information
theavege committed Jan 16, 2025
1 parent f16955a commit cbfde42
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 77 deletions.
138 changes: 61 additions & 77 deletions .github/workflows/make.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@

const
Target: string = 'lazpaint';
Dependencies: array of string = ('BGRAControls', 'BGRABitmap');
Dependencies: array of string = ();

type
TLog = (audit, info, error);
Output = record
Code: boolean;
Output: ansistring;
Success: boolean;
Output: string;
end;

procedure OutLog(Knd: TLog; Msg: string);
begin
case Knd of
error: Writeln(stderr, #27'[31m', Msg, #27'[0m');
info: Writeln(stderr, #27'[32m', Msg, #27'[0m');
audit: Writeln(stderr, #27'[33m', Msg, #27'[0m');
end;
end;

function CheckModules: Output;
begin
if FileExists('.gitmodules') then
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
'--force', '--remote'], Result.Output) then
Writeln(stderr, #27'[33m', Result.Output, #27'[0m');
OutLog(info, Result.Output);
end;

function AddPackage(Path: string): Output;
Expand All @@ -37,14 +47,14 @@ Output = record
begin
Expression :=
{$IFDEF MSWINDOWS}
'(cocoa|x11|_template)'
{$ELSE}
'(cocoa|gdi|_template)'
{$ENDIF}
'(cocoa|x11|_template)'
{$ELSE}
'(cocoa|gdi|_template)'
{$ENDIF}
;
if not Exec(Path) and RunCommand('lazbuild', ['--add-package-link', Path],
Result.Output) then
Writeln(stderr, #27'[33m', 'added ', Path, #27'[0m');
OutLog(audit, 'added ' + Path);
Free;
end;
end;
Expand All @@ -53,17 +63,17 @@ Output = record
var
Line: string;
begin
Write(stderr, #27'[33m', 'build from ', Path, #27'[0m');
OutLog(audit, 'build from ' + Path);
try
Result.Code := RunCommand('lazbuild', ['--build-all', '--recursive',
Result.Success := RunCommand('lazbuild', ['--build-all', '--recursive',
'--no-write-project', Path], Result.Output);
if Result.Code then
if Result.Success then
for Line in SplitString(Result.Output, LineEnding) do
begin
if ContainsStr(Line, 'Linking') then
begin
Result.Output := SplitString(Line, ' ')[2];
Writeln(stderr, #27'[32m', ' to ', Result.Output, #27'[0m');
OutLog(info, ' to ' + Result.Output);
break;
end;
end
Expand All @@ -75,16 +85,13 @@ Output = record
begin
Expression := '(Fatal|Error):';
if Exec(Line) then
begin
WriteLn(stderr);
Writeln(stderr, #27'[31m', Line, #27'[0m');
end;
OutLog(error, #10 + Line);
Free;
end;
end;
except
on E: Exception do
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
OutLog(error, E.ClassName + #13#10 + E.Message);
end;
end;

Expand All @@ -94,22 +101,22 @@ Output = record
begin
Result := BuildProject(Path);
Temp:= Result.Output;
if Result.Code then
if Result.Success then
try
if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then
begin
ExitCode += 1;
WriteLn(stderr, Result.Output);
end;
begin
ExitCode += 1;
OutLog(error, Result.Output);
end;
except
on E: Exception do
WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message);
OutLog(error, E.ClassName + #13#10 + E.Message);
end;
end;

function AddOPM(Each: string): string;
function InstallOPM(Each: string): string;
var
TempFile, Url: string;
OutFile, Uri: string;
Zip: TStream;
begin
Result :=
Expand All @@ -119,18 +126,18 @@ Output = record
GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/'
{$ENDIF}
+ Each;
TempFile := GetTempFileName;
Url := 'https://packages.lazarus-ide.org/' + Each + '.zip';
OutFile := GetTempFileName;
Uri := 'https://packages.lazarus-ide.org/' + Each + '.zip';
if not DirectoryExists(Result) then
begin
Zip := TFileStream.Create(TempFile, fmCreate or fmOpenWrite);
Zip := TFileStream.Create(OutFile, fmCreate or fmOpenWrite);
with TFPHttpClient.Create(nil) do
begin
try
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
AllowRedirect := True;
Get(Url, Zip);
WriteLn(stderr, 'Download from ', Url, ' to ', TempFile);
Get(Uri, Zip);
OutLog(audit, 'Download from ' + Uri + ' to ' + OutFile);
finally
Free;
end;
Expand All @@ -140,62 +147,62 @@ Output = record
with TUnZipper.Create do
begin
try
FileName := TempFile;
FileName := OutFile;
OutputPath := Result;
Examine;
UnZipAllFiles;
WriteLn(stderr, 'Unzip from ', TempFile, ' to ', Result);
OutLog(audit, 'Unzip from ' + OutFile + ' to ' + Result);
finally
Free;
end;
end;
DeleteFile(TempFile);
DeleteFile(OutFile);
end;
end;

function LintPython(Path: string): Output;
begin
WriteLn(stderr, #27'[33m', 'Linting Python file: ', Path, #27'[0m');
OutLog(audit, 'Linting Python file: ' + Path);
if not RunCommand('python3', ['-m', 'pylint', Path], Result.Output) then
begin
Writeln(stderr, #27'[31m', Result.Output, #27'[0m');
OutLog(error, Result.Output);
//ExitCode += 1;
end
end;

function LintC(Path: string): Output;
begin
WriteLn(stderr, #27'[33m', 'Linting C file: ', Path, #27'[0m');
OutLog(audit, 'Linting C file: ' + Path);
if not RunCommand('cppcheck', ['--language=c', '--enable=warning,style', '--template=gcc', Path], Result.Output) then
begin
Writeln(stderr, #27'[31m', Result.Output, #27'[0m');
OutLog(error, Result.Output);
//ExitCode += 1;
end
end;

function LintShell(Path: string): Output;
begin
WriteLn(stderr, #27'[33m', 'Linting Shell file: ', Path, #27'[0m');
OutLog(audit, 'Linting Shell file: ' + Path);
if not RunCommand('shellcheck', ['--external-sources', Path], Result.Output) then
begin
Writeln(stderr, #27'[31m', Result.Output, #27'[0m');
OutLog(error, Result.Output);
//ExitCode += 1;
end
end;

procedure Main;
procedure BuildAll;
var
Each, Item: string;
List: TStringList;
begin
CheckModules;
InitSSLInterface;
for Each in Dependencies do
for Item in Dependencies do
begin
List := FindAllFiles(AddOPM(Each), '*.lpk', True);
List := FindAllFiles(InstallOPM(Item), '*.lpk', True);
try
for Item in List do
AddPackage(Item);
for Each in List do
AddPackage(Each);
finally
List.Free;
end;
Expand All @@ -210,44 +217,21 @@ Output = record
List := FindAllFiles(Target, '*.lpi', True);
try
for Each in List do
if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')),
'consoletestrunner') then
RunTest(Each)
else
BuildProject(Each);
finally
List.Free;
end;
{$IFDEF LINUX}
List := FindAllFiles(GetCurrentDir, '*.py', True);
try
for Each in List do
LintPython(Each);
finally
List.Free;
end;
List := FindAllFiles(GetCurrentDir, '*.c', True);
try
for Each in List do
LintC(Each);
finally
List.Free;
end;
List := FindAllFiles(GetCurrentDir, '*.sh', True);
try
for Each in List do
LintShell(Each);
if not ContainsStr(Each, 'zengl') then
if ContainsStr(ReadFileToString(ReplaceStr(Each, '.lpi', '.lpr')),
'consoletestrunner') then
RunTest(Each)
else
BuildProject(Each);
finally
List.Free;
end;
{$ENDIF}
WriteLn(stderr);
if ExitCode <> 0 then
WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m')
OutLog(error, #10 + 'Errors: ' + IntToStr(ExitCode))
else
WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m');
OutLog(info, #10 + 'Errors: ' + IntToStr(ExitCode));
end;

begin
Main;
BuildAll;
end.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "use/bgrabitmap"]
path = use/bgrabitmap
url = [email protected]:bgrabitmap/bgrabitmap.git
[submodule "use/bgracontrols"]
path = use/bgracontrols
url = [email protected]:bgrabitmap/bgracontrols.git
1 change: 1 addition & 0 deletions use/bgrabitmap
Submodule bgrabitmap added at 311fa8
1 change: 1 addition & 0 deletions use/bgracontrols
Submodule bgracontrols added at 555c0d

0 comments on commit cbfde42

Please sign in to comment.