diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas new file mode 100644 index 0000000..5ed98d8 --- /dev/null +++ b/.github/workflows/make.pas @@ -0,0 +1,185 @@ +program Make; +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + StrUtils, + FileUtil, + Zipper, + fphttpclient, + RegExpr, + openssl, + opensslsockets, + Process; + +const + Target: string = '.'; + Dependencies: array of string = (); + +type + TLog = (audit, info, error); + + Output = record + Success: boolean; + Output: string; + end; + + procedure OutLog(const Knd: TLog; const 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: string; + begin + if FileExists('.gitmodules') then + if RunCommand('git', ['submodule', 'update', '--init', '--recursive', + '--force', '--remote'], Result) then + OutLog(info, Result) + else + OutLog(error, Result); + end; + + function AddPackage(const Path: string): string; + begin + if RunCommand('lazbuild', ['--add-package-link', Path], Result) then + OutLog(audit, 'Add package:'#9 + Path); + end; + + function SelectString(const Input, Reg: string): string; + var + Line: string; + begin + Result := ' '; + for Line in Input.Split(LineEnding) do + with TRegExpr.Create do + begin + Expression := Reg; + if Exec(Line) then + Result += Line + LineEnding; + Free; + end; + end; + + function RunTest(const Path: String): string; + begin + OutLog(audit, #9'run:'#9 + Path); + if RunCommand(Path, ['--all', '--format=plain'], Result) then + OutLog(info, #9'success!') + else + begin + ExitCode += 1; + OutLog(error, Result); + end; + end; + + function BuildProject(const Path: string): Output; + begin + OutLog(audit, 'Build from:'#9 + Path); + Result.Success := RunCommand('lazbuild', + ['--build-all', '--recursive', '--no-write-project', Path], Result.Output); + Result.Output := SelectString(Result.Output, '(Fatal:|Error:|Linking)'); + if Result.Success then + begin + Result.Output := Result.Output.Split(' ')[3].Replace(LineEnding, ''); + OutLog(info, #9'to:'#9 + Result.Output); + if ContainsStr(ReadFileToString(Path.Replace('.lpi', '.lpr')), 'consoletestrunner') then + RunTest(Result.Output.Replace(#10, '')); + end + else + begin + ExitCode += 1; + OutLog(error, Result.Output); + 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(audit, 'Download from ' + Uri + ' to ' + 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(audit, '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 + CreateDir(Result); + UnZip(DownloadFile('https://packages.lazarus-ide.org/' + Path + '.zip'), Result); + end; + end; + + function BuildAll: string; + var + List: TStringList; + begin + CheckModules; + List := FindAllFiles(GetCurrentDir, '*.lpk', True); + try + for Result in Dependencies do + List.AddStrings(FindAllFiles(InstallOPM(Result), '*.lpk', True)); + for Result in List do + AddPackage(Result); + List := FindAllFiles(Target, '*.lpi', True); + for Result in List do + BuildProject(Result); + finally + List.Free; + end; + case ExitCode of + 0: OutLog(info, 'Errors:'#9 + IntToStr(ExitCode)); + else + OutLog(error, 'Errors:'#9 + IntToStr(ExitCode)); + end; + end; + +begin + try + BuildAll + except + on E: Exception do + Writeln(E.ClassName, #9, E.Message); + end; +end. diff --git a/.github/workflows/make.ps1 b/.github/workflows/make.ps1 deleted file mode 100644 index 98bdf2a..0000000 --- a/.github/workflows/make.ps1 +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/env pwsh -############################################################################################################## - -Function Show-Usage { - " -vagrant = 'it-gro/win10-ltsc-eval' -download = 'https://microsoft.com/en-us/evalcenter' -package = 'https://learn.microsoft.com/en-us/mem/configmgr/develop/apps/how-to-create-the-windows-installer-file-msi' -shell = 'https://learn.microsoft.com/en-us/powershell' - -Usage: pwsh -File $($PSCommandPath) [OPTIONS] -Options: - build - lint -" | Out-Host -} - -Function Build-Project { - New-Variable -Option Constant -Name VAR -Value @{ - Src = 'Examples' - Use = 'Package' - Pkg = 'Package\components.txt' - } - If (! (Test-Path -Path $Var.Src)) { - "$([char]27)[31m.... Source do not find!$([char]27)[0m" | Out-Host - Exit 1 - } - If (Test-Path -Path '.gitmodules') { - & git submodule update --init --recursive --force --remote | Out-Host - "$([char]27)[32m.... [[$($LastExitCode)]] git submodule update$([char]27)[0m" | Out-Host - } - @( - @{ - Cmd = 'lazbuild' - Url = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' - Path = "C:\Lazarus" - } - ) | Where-Object { ! (Test-Path -Path $_.Path) } | - ForEach-Object { - $_.Url | Request-File | Install-Program - $Env:PATH+=";$($_.Path)" - (Get-Command $_.Cmd).Source | Out-Host - } - If (Test-Path -Path $VAR.Use) { - If (Test-Path -Path $VAR.Pkg) { - Get-Content -Path $VAR.Pkg | - Where-Object { - ! (Test-Path -Path "$($VAR.Use)\$($_)") && - ! (& lazbuild --verbose-pkgsearch $_ ) && - ! (& lazbuild --add-package $_) - } | ForEach-Object { - Return @{ - Uri = "https://packages.lazarus-ide.org/$($_).zip" - Path = "$($VAR.Use)\$($_)" - OutFile = (New-TemporaryFile).FullName - } - } | ForEach-Object -Parallel { - Invoke-WebRequest -OutFile $_.OutFile -Uri $_.Uri - Expand-Archive -Path $_.OutFile -DestinationPath $_.Path - Remove-Item $_.OutFile - Return "$([char]27)[32m.... download $($_.Uri)$([char]27)[0m" - } | Out-Host - } - (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName | - ForEach-Object { - & lazbuild --add-package-link $_ | Out-Null - Return "$([char]27)[32m.... [$($LastExitCode)] add package link $($_)$([char]27)[0m" - } | Out-Host - } - Exit ( - (Get-ChildItem -Filter '*.lpi' -Recurse -File –Path $Var.Src).FullName | - Sort-Object | - ForEach-Object { - $Output = (& lazbuild --build-all --recursive --no-write-project $_) - $Result = @("$([char]27)[32m.... [$($LastExitCode)] build project $($_)$([char]27)[0m") - $exitCode = Switch ($LastExitCode) { - 0 { - $Result += $Output | Select-String -Pattern 'Linking' - 0 - } - Default { - $Result += $Output | Select-String -Pattern 'Error:', 'Fatal:' - 1 - } - } - $Result | Out-Host - Return $exitCode - } | Measure-Object -Sum - ).Sum -} - -Function Request-File { - While ($Input.MoveNext()) { - New-Variable -Option Constant -Name VAR -Value @{ - Uri = $Input.Current - OutFile = (Split-Path -Path $Input.Current -Leaf).Split('?')[0] - } - Invoke-WebRequest @VAR - Return $VAR.OutFile - } -} - -Function Install-Program { - While ($Input.MoveNext()) { - Switch ((Split-Path -Path $Input.Current -Leaf).Split('.')[-1]) { - 'msi' { - & msiexec /passive /package $Input.Current | Out-Null - } - Default { - & ".\$($Input.Current)" /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null - } - } - Remove-Item $Input.Current - } -} - -Function Request-URL([Switch] $Post) { - $VAR = Switch ($Post) { - True { - Return @{ - Method = 'POST' - Headers = @{ - ContentType = 'application/json' - } - Uri = 'https://postman-echo.com/post' - Body = @{ - One = '1' - } | ConvertTo-Json - } - } - False { - Return @{ - Uri = 'https://postman-echo.com/get' - } - } - } - Return (Invoke-WebRequest @VAR | ConvertFrom-Json).Headers -} - -Function Switch-Action { - $ErrorActionPreference = 'stop' - Set-PSDebug -Strict #-Trace 1 - Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath - If ($args.count -gt 0) { - Switch ($args[0]) { - 'lint' { - Invoke-ScriptAnalyzer -EnableExit -Recurse -Path '.' - (Get-ChildItem -Filter '*.ps1' -Recurse -Path '.').FullName | - ForEach-Object { - Invoke-Formatter -ScriptDefinition $(Get-Content -Path $_ | Out-String) | - Set-Content -Path $_ - } - } - 'build' { - Build-Project - } - Default { - Show-Usage - } - } - } Else { - Show-Usage - } -} - -############################################################################################################## -Switch-Action @args diff --git a/.github/workflows/make.sh b/.github/workflows/make.sh deleted file mode 100644 index 9e6ed05..0000000 --- a/.github/workflows/make.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env bash -############################################################################################################## - -function priv_clippit -( - cat <&2 - fi - declare -i errors=0 - while read -r; do - declare -A TMP=( - [out]=$(mktemp) - ) - if (lazbuild --build-all --recursive --no-write-project "${REPLY}" > "${TMP[out]}"); then - printf '\x1b[32m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}" - grep --color='always' 'Linking' "${TMP[out]}" - else - printf '\x1b[31m\t[%s]\t%s\x1b[0m\n' "${?}" "${REPLY}" - grep --color='always' --extended-regexp '(Error|Fatal):' "${TMP[out]}" - ((errors+=1)) - fi 1>&2 - rm "${TMP[out]}" - done < <(find "${VAR[src]}" -type 'f' -name '*.lpi' | sort) - exit "${errors}" -) - -function priv_main -( - set -euo pipefail - if ((${#})); then - case ${1} in - build) priv_lazbuild ;; - *) priv_clippit ;; - esac - else - priv_clippit - fi -) - -############################################################################################################## -priv_main "${@}" >/dev/null diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 006d55c..e7ed91d 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -24,26 +24,28 @@ jobs: matrix: os: - ubuntu-latest - - windows-latest steps: - name: Checkout uses: actions/checkout@v4 with: submodules: true - - name: Build on Linux - if: runner.os == 'Linux' + - name: Build shell: bash - run: bash .github/workflows/make.sh build + run: | + set -xeuo pipefail + sudo bash -c ' + apt-get update + apt-get install -y lazarus lib{gnutls28,curl4-gnutls}-dev + ' >/dev/null + mkdir -p libsagui/build + if pushd libsagui/build; then + cmake -DCMAKE_C_COMPILER=clang .. + make && sudo make sagui install/strip && sudo ldconfig + if popd; then + instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \ + -B '.github/workflows/make.pas' + pushd Test && bash RunAllTests.sh + fi + fi - - name: Build on Windows - if: runner.os == 'Windows' - shell: powershell - run: pwsh -File .github/workflows/make.ps1 build - - - name: Archive - if: runner.os == 'Windows' - uses: actions/upload-artifact@v4 - with: - retention-days: 1 - path: src\bin\*.exe diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..07a70cd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libsagui"] + path = libsagui + url = git@github.com:risoflora/libsagui.git diff --git a/libsagui b/libsagui new file mode 160000 index 0000000..4605b6a --- /dev/null +++ b/libsagui @@ -0,0 +1 @@ +Subproject commit 4605b6abdd17ccb6e7ec3aa82ab109d65f4abcae