Skip to content

Commit

Permalink
Windows dispatcher script
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jun 13, 2024
1 parent 0882cc4 commit 3c07824
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
10 changes: 10 additions & 0 deletions alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 6 additions & 0 deletions scripts/ci-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions scripts/version-patcher.ps1
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 5 additions & 2 deletions scripts/version-patcher.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/env bash
#!/usr/bin/env bash
# This script dispatches to the Ada patcher, after building it.

set -o errexit
Expand All @@ -19,4 +19,7 @@ else
exit 0
fi

$bin "$@"
$bin "$@"

echo "Resulting version file:"
cat src/alire/alire-version.ads | grep Current_Str
2 changes: 1 addition & 1 deletion src/alire/alire-version.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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+204eb4e4_dirty";
-- 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
Expand Down
10 changes: 8 additions & 2 deletions support/version_patcher/src/version_patcher.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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 & "...");
Expand Down

0 comments on commit 3c07824

Please sign in to comment.