diff --git a/alire.toml b/alire.toml index 9ab7cff57..7cee2636d 100644 --- a/alire.toml +++ b/alire.toml @@ -99,11 +99,21 @@ branch = "alire" # Before building, we add the commit to the version, for unique identification: [[actions]] +[actions.'case(os)'.windows] +type = "pre-build" +command = ["pwsh", "scripts/version-patcher.ps1"] + +[actions.'case(os)'.'...'] type = "pre-build" command = ["scripts/version-patcher.sh"] # Afterwards we leave an extra note, so people manually building don't use a # misleading commit. [[actions]] +[actions.'case(os)'.windows] +type = "post-build" +command = ["pwsh", "scripts/version-patcher.ps1", "_or_later"] + +[actions.'case(os)'.'...'] type = "post-build" command = ["scripts/version-patcher.sh", "_or_later"] \ No newline at end of file diff --git a/scripts/ci-github.sh b/scripts/ci-github.sh index 50a8f4d6e..845cd96d0 100755 --- a/scripts/ci-github.sh +++ b/scripts/ci-github.sh @@ -13,6 +13,12 @@ pushd "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" . ../dev/functions.sh popd +# Mark location safe to assuage git if necessary (happens in some distros) +if git status 2>&1 | grep -q "dubious ownership"; then + echo "Marking $PWD as safe for git" + git config --global --add safe.directory "$PWD" +fi + # Patch version scripts/version-patcher.sh diff --git a/scripts/version-patcher.ps1 b/scripts/version-patcher.ps1 new file mode 100644 index 000000000..1d1408bae --- /dev/null +++ b/scripts/version-patcher.ps1 @@ -0,0 +1,25 @@ +# This script dispatches to the Ada patcher, after building it. + +# Set strict mode for PowerShell to exit on error +$ErrorActionPreference = "Stop" + +$bin = "support/version_patcher/bin/version_patcher.exe" + +# If the binary is already in place, do nothing +if (Test-Path $bin) { + Write-Output "Patcher already built." +} elseif (Get-Command gprbuild -ErrorAction SilentlyContinue) { + Write-Output "Building patcher with gprbuild..." + gprbuild -P support/version_patcher/version_patcher.gpr +} elseif (Get-Command alr -ErrorAction SilentlyContinue) { + Write-Output "Building patcher with alr..." + alr -C (Split-Path $bin) build +} else { + Write-Output "WARNING: No Ada tool available to build patcher, skipping." + exit 0 +} + +& $bin @args + +Write-Output "Resulting version file:" +Get-Content src/alire/alire-version.ads | Select-String "Current_Str" diff --git a/scripts/version-patcher.sh b/scripts/version-patcher.sh index 2c7d39c2a..3de414b66 100755 --- a/scripts/version-patcher.sh +++ b/scripts/version-patcher.sh @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash # This script dispatches to the Ada patcher, after building it. set -o errexit @@ -19,4 +19,7 @@ else exit 0 fi -$bin "$@" \ No newline at end of file +$bin "$@" + +echo "Resulting version file:" +cat src/alire/alire-version.ads | grep Current_Str \ No newline at end of file diff --git a/src/alire/alire-version.ads b/src/alire/alire-version.ads index c51fde2ab..441a826dc 100644 --- a/src/alire/alire-version.ads +++ b/src/alire/alire-version.ads @@ -16,7 +16,7 @@ private -- be replaced by `alr build` with the current commit, and appended with -- "_or_later" after build. - Current_Str : constant String := "2.1-dev+3ab04c93_dirty"; + Current_Str : constant String := "2.1-dev"; -- 2.0.0: alr settings refactor and minor fixes -- 2.0.0-rc1: release candidate for 2.0 -- 2.0.0-b1: first public release on the 2.0 branch diff --git a/support/version_patcher/src/version_patcher.adb b/support/version_patcher/src/version_patcher.adb index a0921bae5..b91768447 100644 --- a/support/version_patcher/src/version_patcher.adb +++ b/support/version_patcher/src/version_patcher.adb @@ -100,9 +100,15 @@ begin "_dirty" else ""); - Commit : constant String - := To_String (Git_Command ("rev-parse --short HEAD").Output); + Commit_Result : constant Result := + Git_Command ("rev-parse --short HEAD"); + Commit : constant String := To_String (Commit_Result.Output); begin + if Commit_Result.Code /= 0 then + raise Constraint_Error with + "Git error while trying to get commit:" + & Commit_Result.Code'Image; + end if; Ada.Text_IO.Put_Line ("Updating version in src/alire/alire-version.ads to commit " & Commit & Dirty & "...");