-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tag builds done through
alr build
with unique build string (#1530)
* Replace version build with current commit hash * Detect dirtiness in . to flag it too in version * Fix for line terminators on Windows * Self-review * Ada version * Windows dispatcher script * Patch from the dev/build.sh script too
- Loading branch information
Showing
14 changed files
with
404 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Import reusable bits | ||
pushd $( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) > /dev/null | ||
pushd "$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" > /dev/null || exit 1 | ||
. functions.sh | ||
popd > /dev/null | ||
popd > /dev/null || exit 1 | ||
|
||
ALIRE_BUILD_JOBS="${ALIRE_BUILD_JOBS:-0}" | ||
export ALIRE_OS=$(get_OS) | ||
ALIRE_OS=$(get_OS); export ALIRE_OS | ||
|
||
scripts/version-patcher.sh | ||
|
||
echo "Building with ALIRE_OS=$ALIRE_OS..." | ||
gprbuild "-j$ALIRE_BUILD_JOBS" -r -p -P `dirname $0`/../alr_env.gpr "$@" | ||
gprbuild "-j$ALIRE_BUILD_JOBS" -r -p -P "$(dirname $0)/../alr_env.gpr" "$@" | ||
|
||
scripts/version-patcher.sh _or_later |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
def replace_version(filename, build_info): | ||
pattern = r'(Current : constant String := "[^+]+\+)([^"]*)(";)' | ||
|
||
# Depending on the context in which this is run, there may be mix-ups with | ||
# line terminators between the environment detected, github runner, etc... | ||
# So just keep them as they are and that should always work. | ||
|
||
with open(filename, 'rb') as file: | ||
content = file.read().decode() | ||
|
||
# The pattern captures the part between '+' and '";', replacing it with our | ||
# new build information | ||
|
||
new_content = re.sub(pattern, r'\g<1>' + build_info + r'\3', content) | ||
|
||
# A few sanity checks and write if needed | ||
|
||
if new_content == content: | ||
if build_info in content: | ||
print(f"Note: version in {filename} already up to date") | ||
else: | ||
print(f"WARNING: failed to update version in {filename}") | ||
else: | ||
# Ensure the content line terminators are not changed | ||
with open(filename, 'wb') as file: | ||
file.write(new_content.encode()) | ||
|
||
|
||
# If a flag exists, skip any updating, just print a message and exit | ||
if "ALR_VERSION_DONT_PATCH" in os.environ: | ||
print("Note: skipping version update") | ||
sys.exit(0) | ||
|
||
# If there is an argument to the script, retrieve it here and use it as the new | ||
# dirty flag after the commit | ||
if len(sys.argv) > 1: | ||
dirty = sys.argv[1] | ||
else: | ||
# Detect whether the current directory contains changes | ||
if subprocess.call(['git', 'diff-index', '--quiet', 'HEAD', '--']) != 0: | ||
dirty = "_dirty" | ||
else: | ||
dirty = "" | ||
|
||
# Find the short git commit of the repository in the current directory | ||
commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip() | ||
|
||
# Replace the build version part with the short commit hash plus any extra info | ||
print(f"Updating version in src/alire/alire-version.ads to commit {commit}{dirty}...") | ||
replace_version('src/alire/alire-version.ads', commit+dirty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
# This script dispatches to the Ada patcher, after building it. | ||
|
||
set -o errexit | ||
|
||
# Exit already if the ALR_VERSION_DONT_PATCH flag is defined | ||
if [ "${ALR_VERSION_DONT_PATCH:-unset}" != "unset" ]; then | ||
echo "Skipping version patching..." | ||
exit 0 | ||
fi | ||
|
||
bin=support/version_patcher/bin/version_patcher | ||
|
||
# If the binary is already in place, do nothing | ||
if [ -f $bin ]; then | ||
echo "Patcher already built." | ||
elif (which gprbuild &>/dev/null); then | ||
echo "Building patcher with gprbuild..." | ||
gprbuild -P support/version_patcher/version_patcher.gpr | ||
elif (which alr &>/dev/null); then | ||
echo "Building patcher with alr..." | ||
alr -C "$(dirname $bin)" build | ||
else | ||
echo "WARNING: No Ada tool available to build patcher, skipping." | ||
exit 0 | ||
fi | ||
|
||
$bin "$@" | ||
|
||
echo "Resulting version file:" | ||
cat src/alire/alire-version.ads | grep Current_Str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/obj/ | ||
/bin/ | ||
/alire/ | ||
/config/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name = "version_patcher" | ||
description = "Patches current commit into alire-version.ads" | ||
version = "0.1.0-dev" | ||
|
||
authors = ["Alejandro R. Mosteo"] | ||
maintainers = ["Alejandro R. Mosteo <[email protected]>"] | ||
maintainers-logins = ["mosteo"] | ||
licenses = "MIT OR Apache-2.0 WITH LLVM-exception" | ||
website = "" | ||
tags = [] | ||
|
||
executables = ["version_patcher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- Configuration for version_patcher generated by Alire | ||
pragma Restrictions (No_Elaboration_Code); | ||
pragma Style_Checks (Off); | ||
|
||
package Version_Patcher_Config is | ||
pragma Pure; | ||
|
||
Crate_Version : constant String := "0.1.0-dev"; | ||
Crate_Name : constant String := "version_patcher"; | ||
|
||
Alire_Host_OS : constant String := "linux"; | ||
|
||
Alire_Host_Arch : constant String := "x86_64"; | ||
|
||
Alire_Host_Distro : constant String := "ubuntu"; | ||
|
||
type Build_Profile_Kind is (release, validation, development); | ||
Build_Profile : constant Build_Profile_Kind := development; | ||
|
||
end Version_Patcher_Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- Configuration for version_patcher generated by Alire | ||
abstract project Version_Patcher_Config is | ||
Crate_Version := "0.1.0-dev"; | ||
Crate_Name := "version_patcher"; | ||
|
||
Alire_Host_OS := "linux"; | ||
|
||
Alire_Host_Arch := "x86_64"; | ||
|
||
Alire_Host_Distro := "ubuntu"; | ||
Ada_Compiler_Switches := External_As_List ("ADAFLAGS", " "); | ||
Ada_Compiler_Switches := Ada_Compiler_Switches & | ||
( | ||
"-Og" -- Optimize for debug | ||
,"-ffunction-sections" -- Separate ELF section for each function | ||
,"-fdata-sections" -- Separate ELF section for each variable | ||
,"-g" -- Generate debug info | ||
,"-gnatwa" -- Enable all warnings | ||
,"-gnatw.X" -- Disable warnings for No_Exception_Propagation | ||
,"-gnatVa" -- All validity checks | ||
,"-gnaty3" -- Specify indentation level of 3 | ||
,"-gnatya" -- Check attribute casing | ||
,"-gnatyA" -- Use of array index numbers in array attributes | ||
,"-gnatyB" -- Check Boolean operators | ||
,"-gnatyb" -- Blanks not allowed at statement end | ||
,"-gnatyc" -- Check comments | ||
,"-gnaty-d" -- Disable check no DOS line terminators present | ||
,"-gnatye" -- Check end/exit labels | ||
,"-gnatyf" -- No form feeds or vertical tabs | ||
,"-gnatyh" -- No horizontal tabs | ||
,"-gnatyi" -- Check if-then layout | ||
,"-gnatyI" -- check mode IN keywords | ||
,"-gnatyk" -- Check keyword casing | ||
,"-gnatyl" -- Check layout | ||
,"-gnatym" -- Check maximum line length | ||
,"-gnatyn" -- Check casing of entities in Standard | ||
,"-gnatyO" -- Check that overriding subprograms are explicitly marked as such | ||
,"-gnatyp" -- Check pragma casing | ||
,"-gnatyr" -- Check identifier references casing | ||
,"-gnatyS" -- Check no statements after THEN/ELSE | ||
,"-gnatyt" -- Check token spacing | ||
,"-gnatyu" -- Check unnecessary blank lines | ||
,"-gnatyx" -- Check extra parentheses | ||
,"-gnatW8" -- UTF-8 encoding for wide characters | ||
); | ||
|
||
type Build_Profile_Kind is ("release", "validation", "development"); | ||
Build_Profile : Build_Profile_Kind := "development"; | ||
|
||
end Version_Patcher_Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Configuration for version_patcher generated by Alire */ | ||
#ifndef VERSION_PATCHER_CONFIG_H | ||
#define VERSION_PATCHER_CONFIG_H | ||
|
||
#define CRATE_VERSION "0.1.0-dev" | ||
#define CRATE_NAME "version_patcher" | ||
|
||
#define ALIRE_HOST_OS "linux" | ||
|
||
#define ALIRE_HOST_ARCH "x86_64" | ||
|
||
#define ALIRE_HOST_DISTRO "ubuntu" | ||
|
||
#define BUILD_PROFILE_RELEASE 1 | ||
#define BUILD_PROFILE_VALIDATION 2 | ||
#define BUILD_PROFILE_DEVELOPMENT 3 | ||
|
||
#define BUILD_PROFILE 3 | ||
|
||
#endif |
Oops, something went wrong.