Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync dev branch #229

Merged
merged 9 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
211 changes: 211 additions & 0 deletions .github/workflows/make.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
//https://castle-engine.io/modern_pascal

program Make;
{$mode objfpc}{$H+}

uses
Classes,
SysUtils,
StrUtils,
FileUtil,
Zipper,
fphttpclient,
RegExpr,
openssl,
LazUTF8,
opensslsockets,
eventlog,
Process;

function OutLog(const Knd: TEventType; const Msg: string): string;
begin
case Knd of
etError: Result := #27'[31m%s'#27'[0m';
etInfo: Result := #27'[32m%s'#27'[0m';
etDebug: Result := #27'[33m%s'#27'[0m';
end;
Writeln(stderr, UTF8ToConsole(Result.Format([Msg])));
end;

function AddPackage(const Path: string): string;
begin
if RunCommand('lazbuild', ['--add-package-link', Path], Result, [poStderrToOutPut]) then
OutLog(etDebug, 'Add package:'#9 + Path)
else
begin
ExitCode += 1;
OutLog(etError, Result);
end;
end;

function SelectString(const Input, Reg: string): string;
var
Line: string;
begin
Result := EmptyStr;
with TRegExpr.Create do
begin
Expression := Reg;
for Line in Input.Split(LineEnding) do
if Exec(Line) then
Result += Line + LineEnding;
Free;
end;
end;

function RunTest(const Path: String): string;
begin
OutLog(etDebug, #9'run:'#9 + Path);
if RunCommand(Path, ['--all', '--format=plain'], Result, [poStderrToOutPut]) then
OutLog(etInfo, #9'success!')
else
begin
ExitCode += 1;
OutLog(etError, Result);
end;
end;

function AddDDL(const Path: String): string;
const
LibPath: string = '/usr/lib/';
var
List: array of string;
Last: integer;
begin
OutLog(etDebug, #9'add:'#9 + Path);
List := Path.Split(DirectorySeparator);
Last := High(List);
if not FileExists(LibPath + List[Last]) then
if RunCommand('sudo', ['bash', '-c', 'cp %s %s; ldconfig --verbose'.Format([Path, LibPath])], Result, [poStderrToOutPut]) then
OutLog(etInfo, #9'success!')
else
begin
ExitCode += 1;
OutLog(etError, Result);
end;
end;

function BuildProject(const Path: string): string;
var
Text: string;
begin
OutLog(etDebug, 'Build from:'#9 + Path);
if RunCommand('lazbuild',
['--build-all', '--recursive', '--no-write-project', Path], Result, [poStderrToOutPut]) then
begin
Result := SelectString(Result, 'Linking').Split(' ')[2].Replace(LineEnding, EmptyStr);
OutLog(etInfo, #9'to:'#9 + Result);
Text := ReadFileToString(Path.Replace('.lpi', '.lpr'));
if Text.Contains('program') and Text.Contains('consoletestrunner') then
RunTest(Result)
else if Text.Contains('library') and Text.Contains('exports') then
AddDDL(Result)
end
else
begin
ExitCode += 1;
OutLog(etError, SelectString(Result, '(Fatal|Error):'));
end;
end;

function DownloadFile(const Uri: string): string;
var
OutFile: TStream;
begin
InitSSLInterface;
Result := GetTempFileName;
OutFile := TFileStream.Create(Result, fmCreate or fmOpenWrite);
with TFPHttpClient.Create(nil) do
begin
try
AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
AllowRedirect := True;
Get(Uri, OutFile);
OutLog(etDebug, 'Download from %s to %s'.Format([Uri, Result]));
finally
Free;
OutFile.Free;
end;
end;
end;

procedure UnZip(const ZipFile, ZipPath: string);
begin
with TUnZipper.Create do
begin
try
FileName := ZipFile;
OutputPath := ZipPath;
Examine;
UnZipAllFiles;
OutLog(etDebug, 'Unzip from'#9 + ZipFile + #9'to'#9 + ZipPath);
DeleteFile(ZipFile);
finally
Free;
end;
end;
end;

function InstallOPM(const Path: string): string;
begin
Result :=
{$IFDEF MSWINDOWS}
GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\'
{$ELSE}
GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/'
{$ENDIF}
+ Path;
if not DirectoryExists(Result) then
begin
if ForceDirectories(Result) then
UnZip(DownloadFile('https://packages.lazarus-ide.org/%s.zip'.Format([Path])), Result);
end;
end;

function BuildAll(const Target: string; const Dependencies: array of string): string;
var
List: TStringList;
DT: TDateTime;
begin
DT := Time;
if FileExists('.gitmodules') then
if RunCommand('git', ['submodule', 'update', '--init', '--recursive',
'--force', '--remote'], Result, [poStderrToOutPut]) then
OutLog(etInfo, Result)
else
begin
ExitCode += 1;
OutLog(etError, Result);
end;
List := FindAllFiles(GetCurrentDir, '*.lpk');
try
for Result in Dependencies do
List.AddStrings(FindAllFiles(InstallOPM(Result), '*.lpk'));
for Result in List do
AddPackage(Result);
List := FindAllFiles(Target, '*.lpi');
List.Sort;
for Result in List do
if not Result.Contains('backup') then
BuildProject(Result);
finally
List.Free;
end;
if not RunCommand('delp', ['-r', GetCurrentDir], Result, [poStderrToOutPut]) then
OutLog(etError, Result);
OutLog(etDebug, 'Duration:'#9 + FormatDateTime('hh:nn:ss', Time - DT));
end;

begin
try
BuildAll('.', ['BGRABitmap']);
case ExitCode of
0: OutLog(etInfo, 'Errors:'#9 + ExitCode.ToString);
else
OutLog(etError, 'Errors:'#9 + ExitCode.ToString);
end;
except
on E: Exception do
Writeln(E.ClassName, #9, E.Message);
end;
end.
39 changes: 39 additions & 0 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Make

on:
schedule:
- cron: '0 0 1 * *'
push:
branches:
- "**"
pull_request:
branches:
- master
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 120
strategy:
matrix:
os:
- ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Build
shell: bash
run: |
set -xeuo pipefail
sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null
instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \
.github/workflows/make.pas build
26 changes: 24 additions & 2 deletions bgrasvgimagelist.pas
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,35 @@ procedure Register;

implementation

uses LCLType;
uses LCLType, XMLRead;

procedure Register;
begin
RegisterComponents('BGRA Themes', [TBGRASVGImageList]);
end;

{$IF FPC_FULLVERSION < 30203}
type

{ TPatchedXMLConfig }

TPatchedXMLConfig = class(TXMLConfig)
public
procedure LoadFromStream(S : TStream); reintroduce;
end;


{ TPatchedXMLConfig }

procedure TPatchedXMLConfig.LoadFromStream(S: TStream);
begin
FreeAndNil(Doc);
ReadXMLFile(Doc,S);
FModified := False;
if (Doc.DocumentElement.NodeName<>RootName) then
raise EXMLConfigError.CreateFmt(SWrongRootName,[RootName,Doc.DocumentElement.NodeName]);
end;
{$ENDIF}
{ TBGRASVGImageList }

procedure TBGRASVGImageList.ReadData(Stream: TStream);
Expand Down Expand Up @@ -140,7 +162,7 @@ procedure TBGRASVGImageList.ReadData(Stream: TStream);
FDataLineBreak:= GetLineEnding(Stream);
// Actually load the XML file
Stream.Position := 0;
FXMLConf.LoadFromStream(Stream);
{$IF FPC_FULLVERSION < 30203}TPatchedXMLConfig(FXMLConf){$ELSE}FXMLConf{$ENDIF}.LoadFromStream(Stream);
Load(FXMLConf);
finally
FXMLConf.Free;
Expand Down
23 changes: 17 additions & 6 deletions test/test_bckeyboard/test_bckeyboard.lpi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="test_bckeyboard"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
Expand All @@ -24,6 +26,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\.."/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
Expand Down Expand Up @@ -64,6 +67,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\.."/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
Expand All @@ -90,9 +94,10 @@
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="2">
<Item1>
Expand All @@ -102,7 +107,7 @@
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Units Count="3">
<Unit0>
<Filename Value="test_bckeyboard.lpr"/>
<IsPartOfProject Value="True"/>
Expand All @@ -114,6 +119,11 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit1>
<Unit2>
<Filename Value="..\..\bcnumerickeyboard.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="BCNumericKeyboard"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand All @@ -124,6 +134,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="..\..;..\..\lcl"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
Expand Down
2 changes: 1 addition & 1 deletion test/test_bckeyboard/test_bckeyboard.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, umain
Forms, BCNumericKeyboard, umain
{ you can add units after this };

{$R *.res}
Expand Down
Loading
Loading