Browse Source

Merge pull request #229 from bgrabitmap/master

sync dev branch
circular17 9 months ago
parent
commit
ca23bd1529

+ 7 - 0
.github/dependabot.yml

@@ -0,0 +1,7 @@
+---
+version: 2
+updates:
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "monthly"

+ 211 - 0
.github/workflows/make.pas

@@ -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 - 0
.github/workflows/make.yml

@@ -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

+ 24 - 2
bgrasvgimagelist.pas

@@ -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);
@@ -140,7 +162,7 @@ begin
     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;

+ 17 - 6
test/test_bckeyboard/test_bckeyboard.lpi

@@ -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"/>
@@ -24,6 +26,7 @@
           </Target>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
+            <OtherUnitFiles Value="..\.."/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
           </SearchPaths>
           <Parsing>
@@ -64,6 +67,7 @@
           </Target>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
+            <OtherUnitFiles Value="..\.."/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
           </SearchPaths>
           <CodeGeneration>
@@ -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>
@@ -102,7 +107,7 @@
         <PackageName Value="LCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="2">
+    <Units Count="3">
       <Unit0>
         <Filename Value="test_bckeyboard.lpr"/>
         <IsPartOfProject Value="True"/>
@@ -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>
@@ -124,6 +134,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="..\..;..\..\lcl"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Linking>

+ 1 - 1
test/test_bckeyboard/test_bckeyboard.lpr

@@ -7,7 +7,7 @@ uses
   cthreads,
   {$ENDIF}{$ENDIF}
   Interfaces, // this includes the LCL widgetset
-  Forms, umain
+  Forms, BCNumericKeyboard, umain
   { you can add units after this };
 
 {$R *.res}

+ 17 - 6
test/test_bcnumerickeyboard/test_bcnumerickeyboard.lpi

@@ -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="BC Numeric Keyboard"/>
       <ResourceType Value="res"/>
       <UseXPManifest Value="True"/>
@@ -24,6 +26,7 @@
           </Target>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
+            <OtherUnitFiles Value="..\.."/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
           </SearchPaths>
           <Parsing>
@@ -64,6 +67,7 @@
           </Target>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
+            <OtherUnitFiles Value="..\.."/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
           </SearchPaths>
           <CodeGeneration>
@@ -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>
@@ -102,7 +107,7 @@
         <PackageName Value="LCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="2">
+    <Units Count="3">
       <Unit0>
         <Filename Value="test_bcnumerickeyboard.lpr"/>
         <IsPartOfProject Value="True"/>
@@ -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>
@@ -124,6 +134,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="..\.."/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Linking>

+ 1 - 1
test/test_bcnumerickeyboard/test_bcnumerickeyboard.lpr

@@ -7,7 +7,7 @@ uses
   cthreads,
   {$ENDIF}{$ENDIF}
   Interfaces, // this includes the LCL widgetset
-  Forms, umain
+  Forms, umain, BCNumericKeyboard
   { you can add units after this };
 
 {$R *.res}

+ 9 - 5
test/test_bcrealnumerickeyboard/test_bcnumerickeyboard.lpi

@@ -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="BC Numeric Keyboard"/>
       <ResourceType Value="res"/>
       <UseXPManifest Value="True"/>
@@ -90,9 +92,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>
@@ -124,6 +127,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="..\.."/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Linking>

+ 9 - 22
test/test_bgrapascalscript/test_bgrapascalscript.lpi

@@ -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_bgrapascalscript"/>
       <ResourceType Value="res"/>
       <UseXPManifest Value="True"/>
@@ -14,9 +16,6 @@
     <i18n>
       <EnableI18N LFM="False"/>
     </i18n>
-    <VersionInfo>
-      <StringTable ProductVersion=""/>
-    </VersionInfo>
     <BuildModes Count="2">
       <Item1 Name="Debug" Default="True"/>
       <Item2 Name="Release">
@@ -47,12 +46,6 @@
               </Win32>
             </Options>
           </Linking>
-          <Other>
-            <CompilerMessages>
-              <MsgFileName Value=""/>
-            </CompilerMessages>
-            <CompilerPath Value="$(CompPath)"/>
-          </Other>
         </CompilerOptions>
       </Item2>
     </BuildModes>
@@ -60,9 +53,10 @@
       <Version Value="2"/>
     </PublishOptions>
     <RunParams>
-      <local>
-        <FormatVersion Value="1"/>
-      </local>
+      <FormatVersion Value="2"/>
+      <Modes Count="1">
+        <Mode0 Name="default"/>
+      </Modes>
     </RunParams>
     <RequiredPackages Count="4">
       <Item1>
@@ -82,7 +76,6 @@
       <Unit0>
         <Filename Value="test_bgrapascalscript.lpr"/>
         <IsPartOfProject Value="True"/>
-        <UnitName Value="test_bgrapascalscript"/>
       </Unit0>
       <Unit1>
         <Filename Value="umain.pas"/>
@@ -90,7 +83,6 @@
         <ComponentName Value="Form1"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
-        <UnitName Value="umain"/>
       </Unit1>
     </Units>
   </ProjectOptions>
@@ -102,6 +94,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="..\.."/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Parsing>
@@ -129,12 +122,6 @@
         </Win32>
       </Options>
     </Linking>
-    <Other>
-      <CompilerMessages>
-        <MsgFileName Value=""/>
-      </CompilerMessages>
-      <CompilerPath Value="$(CompPath)"/>
-    </Other>
   </CompilerOptions>
   <Debugging>
     <Exceptions Count="3">

+ 1 - 0
test/test_bgrascript/test_bgrascript.lpi

@@ -131,6 +131,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
+      <OtherUnitFiles Value="..\.."/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Linking>