From 8294055e53d6c811a68ff2dd0bbb6c92ba071724 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 21:40:16 +0200 Subject: [PATCH 1/7] Rewrote CI to Pascal --- .github/workflows/make.pas | 260 +++++++++++++++++++++++++++++++++++++ .github/workflows/make.ps1 | 130 ------------------- .github/workflows/make.yml | 25 ++-- .gitmodules | 6 - use/bgrabitmap | 1 - use/bgracontrols | 1 - 6 files changed, 276 insertions(+), 147 deletions(-) create mode 100644 .github/workflows/make.pas delete mode 100644 .github/workflows/make.ps1 delete mode 100644 .gitmodules delete mode 160000 use/bgrabitmap delete mode 160000 use/bgracontrols diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas new file mode 100644 index 00000000..4c875216 --- /dev/null +++ b/.github/workflows/make.pas @@ -0,0 +1,260 @@ +program Make; +{$mode objfpc}{$H+} + +uses + Classes, + SysUtils, + StrUtils, + FileUtil, + Zipper, + fphttpclient, + RegExpr, + openssl, + opensslsockets, + Process; + +const + Target: string = 'lazpaint'; + Dependencies: array of string = ('BGRAControls', 'BGRABitmap'); + +type + Output = record + Code: boolean; + Output: ansistring; + 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'); + end; + + function AddPackage(Path: string): Output; + begin + with TRegExpr.Create do + begin + Expression := + {$IFDEF MSWINDOWS} + '(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'); + Free; + end; + end; + + function BuildProject(Path: string): Output; + var + Line: string; + begin + Write(stderr, #27'[33m', 'build from ', Path, #27'[0m'); + try + Result.Code := RunCommand('lazbuild', ['--build-all', '--recursive', + '--no-write-project', Path], Result.Output); + if Result.Code 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'); + break; + end; + end + else + begin + ExitCode += 1; + for Line in SplitString(Result.Output, LineEnding) do + with TRegExpr.Create do + begin + Expression := '(Fatal|Error):'; + if Exec(Line) then + begin + WriteLn(stderr); + Writeln(stderr, #27'[31m', Line, #27'[0m'); + end; + Free; + end; + end; + except + on E: Exception do + WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); + end; + end; + + function RunTest(Path: string): Output; + var + Temp: string; + begin + Result := BuildProject(Path); + Temp:= Result.Output; + if Result.Code then + try + if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then + ExitCode += 1; + WriteLn(stderr, Result.Output); + except + on E: Exception do + WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); + end; + end; + + function AddOPM(Each: string): string; + var + TempFile, Url: string; + Zip: TStream; + begin + Result := + {$IFDEF MSWINDOWS} + GetEnvironmentVariable('APPDATA') + '\.lazarus\onlinepackagemanager\packages\' + {$ELSE} + GetEnvironmentVariable('HOME') + '/.lazarus/onlinepackagemanager/packages/' + {$ENDIF} + + Each; + TempFile := GetTempFileName; + Url := 'https://packages.lazarus-ide.org/' + Each + '.zip'; + if not DirectoryExists(Result) then + begin + Zip := TFileStream.Create(TempFile, 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); + finally + Free; + end; + end; + Zip.Free; + CreateDir(Result); + with TUnZipper.Create do + begin + try + FileName := TempFile; + OutputPath := Result; + Examine; + UnZipAllFiles; + WriteLn(stderr, 'Unzip from ', TempFile, ' to ', Result); + finally + Free; + end; + end; + DeleteFile(TempFile); + end; + end; + + function LintPython(Path: string): Output; + begin + WriteLn(stderr, #27'[33m', 'Linting Python file: ', Path, #27'[0m'); + if not RunCommand('python3', ['-m', 'pylint', Path], Result.Output) then + begin + Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); + ExitCode += 1; + end + end; + + function LintC(Path: string): Output; + begin + WriteLn(stderr, #27'[33m', 'Linting C file: ', Path, #27'[0m'); + if not RunCommand('cppcheck', ['--language=c', '--enable=warning,style', '--template=gcc', Path], Result.Output) then + begin + Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); + ExitCode += 1; + end + end; + + function LintPython(Path: string): Output; + begin + WriteLn(stderr, #27'[33m', 'Linting Shell file: ', Path, #27'[0m'); + if not RunCommand('shellcheck', ['--external-sources', Path], Result.Output) then + begin + Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); + ExitCode += 1; + end + end; + + function LintShell(Path: string): Output; + begin + if RunCommand('python3', ['-m', 'pylint', Path], Result.Output) then + Writeln(stderr, #27'[33m', Result.Output, #27'[0m') + else + begin + Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); + ExitCode += 1; + end + end; + + procedure Main; + var + Each, Item: string; + List: TStringList; + begin + CheckModules; + InitSSLInterface; + for Each in Dependencies do + begin + List := FindAllFiles(AddOPM(Each), '*.lpk', True); + try + for Item in List do + AddPackage(Item); + finally + List.Free; + end; + end; + List := FindAllFiles(GetCurrentDir, '*.lpk', True); + try + for Each in List do + AddPackage(Each); + finally + List.Free; + end; + 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; + 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); + finally + List.Free; + end; + WriteLn(stderr); + if ExitCode <> 0 then + WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m') + else + WriteLn(stderr, #27'[32m', 'Errors: ', ExitCode, #27'[0m'); + end; + +begin + Main; +end. diff --git a/.github/workflows/make.ps1 b/.github/workflows/make.ps1 deleted file mode 100644 index 0f8c2d91..00000000 --- a/.github/workflows/make.ps1 +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env pwsh -############################################################################################################## - -Function Show-Usage { - " -Usage: pwsh -File $($PSCommandPath) [OPTIONS] -Options: - build Build program -" | Out-Host -} - -Function Build-Project { - New-Variable -Name VAR -Option Constant -Value @{ - Src = 'lazpaint' - Use = '.' - Pkg = 'use\components.txt' - } - If (! (Test-Path -Path $Var.Src)) { - 'Source do not find!' | Out-Host - Exit 1 - } - If (Test-Path -Path '.gitmodules') { - & git submodule update --init --recursive --force --remote | Out-Host - ".... [[$($LastExitCode)]] git submodule update" | 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 ".... download $($_.Uri)" - } | Out-Host - } - (Get-ChildItem -Filter '*.lpk' -Recurse -File –Path $VAR.Use).FullName | - ForEach-Object { - & lazbuild --add-package-link $_ | Out-Null - Return ".... [$($LastExitCode)] add package link $($_)" - } | 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 --build-mode='release' $_) - $Result = @(".... [$($LastExitCode)] build project $($_)") - $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 -Name VAR -Option Constant -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 Switch-Action { - $ErrorActionPreference = 'stop' - Set-PSDebug -Strict #-Trace 1 - Invoke-ScriptAnalyzer -EnableExit -Path $PSCommandPath - If ($args.count -gt 0) { - Switch ($args[0]) { - 'build' { - Build-Project - } - Default { - Show-Usage - } - } - } Else { - Show-Usage - } -} - -############################################################################################################## -Switch-Action @args diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index 006d55cd..04f9bdba 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -34,16 +34,23 @@ jobs: - name: Build on Linux if: runner.os == 'Linux' shell: bash - run: bash .github/workflows/make.sh build + run: | + set -xeuo pipefail + sudo bash -c 'apt-get update; apt-get install -y lazarus cppcheck pylint shellcheck' >/dev/null + instantfpc -Fu/usr/lib/lazarus/*/components/lazutils .github/workflows/make.pas - 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 + run: | + New-Variable -Option Constant -Name VAR -Value @{ + Uri = 'https://fossies.org/windows/misc/lazarus-3.6-fpc-3.2.2-win64.exe' + OutFile = (New-TemporaryFile).FullName + '.exe' + } + Invoke-WebRequest @VAR + & $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /SUPPRESSMSGBOXES /NORESTART | Out-Null + $Env:PATH+=';C:\Lazarus' + $Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64' + (Get-Command 'lazbuild').Source | Out-Host + (Get-Command 'instantfpc').Source | Out-Host + instantfpc '-FuC:\Lazarus\components\lazutils' .github/workflows/make.pas diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index fe8b2cba..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "use/bgracontrols"] - path = use/bgracontrols - url = git@github.com:bgrabitmap/bgracontrols.git -[submodule "use/bgrabitmap"] - path = use/bgrabitmap - url = git@github.com:bgrabitmap/bgrabitmap.git diff --git a/use/bgrabitmap b/use/bgrabitmap deleted file mode 160000 index 311fa8d5..00000000 --- a/use/bgrabitmap +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 311fa8d5f9b2baabdb3490ded5f721e68ea67ae2 diff --git a/use/bgracontrols b/use/bgracontrols deleted file mode 160000 index 555c0df8..00000000 --- a/use/bgracontrols +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 555c0df8e2c52c60a9099d1bfd7b14c19852d5a4 From 1b7269a28d2209ad284b067bf526c6129416d295 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 21:41:39 +0200 Subject: [PATCH 2/7] Rewrote CI to Pascal --- .github/workflows/make.sh | 119 -------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 .github/workflows/make.sh diff --git a/.github/workflows/make.sh b/.github/workflows/make.sh deleted file mode 100644 index f696624e..00000000 --- a/.github/workflows/make.sh +++ /dev/null @@ -1,119 +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 --build-mode='release' --widgetset='qt5' "${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) - - # Python linting - find 'resources' -type 'f' -name '*.py' | while read -r file; do - printf '\033[32m\tLinting Python file: %s\033[0m\n' "$file" - if ! python3 -m pylint "$file" 1>&2; then - printf '\033[31m\tError in Python linting: %s\033[0m\n' "$file" - ((errors+=1)) - fi - done - - # C linting - find "${VAR[src]}" -type 'f' -name '*.c' | while read -r file; do - printf '\033[32m\tLinting C file: %s\033[0m\n' "$file" - if ! cppcheck --language=c --enable=warning,style --template=gcc "$file" 1>&2; then - printf '\033[31m\tError in C linting: %s\033[0m\n' "$file" - ((errors+=1)) - fi - done - - # Shell script linting - find "${PWD}" -type 'f' -name '*.sh' | while read -r file; do - printf '\033[32m\tLinting Shell script: %s\033[0m\n' "$file" - if ! shellcheck --external-sources "$file" 1>&2; then - printf '\033[31m\tError in Shell linting: %s\033[0m\n' "$file" - ((errors+=1)) - fi - done - - exit "${errors}" -) - -function priv_main -( - set -uo pipefail - if ((${#})); then - case ${1} in - build) priv_lazbuild ;; - *) priv_clippit ;; - esac - else - priv_clippit - fi -) - -priv_main "${@}" >/dev/null From 5f40b9620507340000bcded1234fc8582dc4eb40 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 21:48:21 +0200 Subject: [PATCH 3/7] Rewrote CI to Pascal --- .github/workflows/make.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 4c875216..e398d715 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -171,7 +171,7 @@ Output = record end end; - function LintPython(Path: string): Output; + function LintShell(Path: string): Output; begin WriteLn(stderr, #27'[33m', 'Linting Shell file: ', Path, #27'[0m'); if not RunCommand('shellcheck', ['--external-sources', Path], Result.Output) then From 906b69bd5097e165b195ec5e0b18166c28988528 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 21:53:27 +0200 Subject: [PATCH 4/7] fix github-actions --- .github/workflows/make.pas | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index e398d715..4c5f7edb 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -181,17 +181,6 @@ Output = record end end; - function LintShell(Path: string): Output; - begin - if RunCommand('python3', ['-m', 'pylint', Path], Result.Output) then - Writeln(stderr, #27'[33m', Result.Output, #27'[0m') - else - begin - Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); - ExitCode += 1; - end - end; - procedure Main; var Each, Item: string; From 4d684fd4d6ea746704d85e499a3c7d82b55a4110 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Wed, 15 Jan 2025 21:58:45 +0200 Subject: [PATCH 5/7] fix github-actions --- .github/workflows/make.pas | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 4c5f7edb..68c36d06 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -216,6 +216,7 @@ Output = record finally List.Free; end; + {$IFDEF LINUX} List := FindAllFiles(GetCurrentDir, '*.py', True); try for Each in List do @@ -237,6 +238,7 @@ Output = record finally List.Free; end; + {$ENDIF} WriteLn(stderr); if ExitCode <> 0 then WriteLn(stderr, #27'[31m', 'Errors: ', ExitCode, #27'[0m') From f16955acec58dfebfeabfbbc562b5ba6965db1e5 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Thu, 16 Jan 2025 13:30:18 +0200 Subject: [PATCH 6/7] fix github-actions --- .github/workflows/make.pas | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index 68c36d06..d5aa443d 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -97,8 +97,10 @@ Output = record if Result.Code then try if not RunCommand(Temp, ['--all', '--format=plain', '--progress'], Result.Output) then - ExitCode += 1; - WriteLn(stderr, Result.Output); + begin + ExitCode += 1; + WriteLn(stderr, Result.Output); + end; except on E: Exception do WriteLn(stderr, 'Error: ' + E.ClassName + #13#10 + E.Message); @@ -157,7 +159,7 @@ Output = record if not RunCommand('python3', ['-m', 'pylint', Path], Result.Output) then begin Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); - ExitCode += 1; + //ExitCode += 1; end end; @@ -167,7 +169,7 @@ Output = record if not RunCommand('cppcheck', ['--language=c', '--enable=warning,style', '--template=gcc', Path], Result.Output) then begin Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); - ExitCode += 1; + //ExitCode += 1; end end; @@ -177,7 +179,7 @@ Output = record if not RunCommand('shellcheck', ['--external-sources', Path], Result.Output) then begin Writeln(stderr, #27'[31m', Result.Output, #27'[0m'); - ExitCode += 1; + //ExitCode += 1; end end; From cbfde42522667abf5940fd8a2f1c687cd73d15c7 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Thu, 16 Jan 2025 22:18:25 +0200 Subject: [PATCH 7/7] return use/bgrabitmap and use/bgracontrols --- .github/workflows/make.pas | 138 ++++++++++++++++--------------------- .gitmodules | 6 ++ use/bgrabitmap | 1 + use/bgracontrols | 1 + 4 files changed, 69 insertions(+), 77 deletions(-) create mode 100644 .gitmodules create mode 160000 use/bgrabitmap create mode 160000 use/bgracontrols diff --git a/.github/workflows/make.pas b/.github/workflows/make.pas index d5aa443d..843b63e9 100644 --- a/.github/workflows/make.pas +++ b/.github/workflows/make.pas @@ -15,12 +15,22 @@ 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; @@ -28,7 +38,7 @@ Output = record 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; @@ -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; @@ -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 @@ -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; @@ -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 := @@ -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; @@ -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; @@ -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. diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b0432302 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "use/bgrabitmap"] + path = use/bgrabitmap + url = git@github.com:bgrabitmap/bgrabitmap.git +[submodule "use/bgracontrols"] + path = use/bgracontrols + url = git@github.com:bgrabitmap/bgracontrols.git diff --git a/use/bgrabitmap b/use/bgrabitmap new file mode 160000 index 00000000..311fa8d5 --- /dev/null +++ b/use/bgrabitmap @@ -0,0 +1 @@ +Subproject commit 311fa8d5f9b2baabdb3490ded5f721e68ea67ae2 diff --git a/use/bgracontrols b/use/bgracontrols new file mode 160000 index 00000000..555c0df8 --- /dev/null +++ b/use/bgracontrols @@ -0,0 +1 @@ +Subproject commit 555c0df8e2c52c60a9099d1bfd7b14c19852d5a4