-
-
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.
- Loading branch information
Showing
11 changed files
with
282 additions
and
5 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
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,22 @@ | ||
#!/bin/env bash | ||
# This script dispatches to the Ada patcher, after building it. | ||
|
||
set -o errexit | ||
|
||
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 "$@" |
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 |
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,111 @@ | ||
with Ada.Command_Line; use Ada.Command_Line; | ||
with Ada.Directories; | ||
with Ada.Environment_Variables; use Ada.Environment_Variables; | ||
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; | ||
with Ada.Text_IO; | ||
|
||
with GNAT.Expect; | ||
with GNAT.OS_Lib; | ||
|
||
--------------------- | ||
-- Version_Patcher -- | ||
--------------------- | ||
|
||
procedure Version_Patcher is | ||
|
||
--------------------- | ||
-- Replace_Version -- | ||
--------------------- | ||
|
||
procedure Replace_Version (Filename : String; Build_Info : String) is | ||
F : Ada.Text_IO.File_Type; | ||
O : Ada.Text_IO.File_Type; | ||
use Ada.Text_IO; | ||
|
||
Target : constant String := "Current_Str : constant String :="; | ||
begin | ||
Open (F, In_File, Filename); | ||
Create (O, Out_File, Filename & ".new"); | ||
while not End_Of_File (F) loop | ||
declare | ||
Line : constant String := Get_Line (F); | ||
begin | ||
if (for some I in Line'Range => | ||
I + Target'Length - 1 <= Line'Last and then | ||
Line (I .. I + Target'Length - 1) = Target) | ||
then | ||
declare | ||
Quotes_Seen : Boolean := False; | ||
begin | ||
for Char of Line loop | ||
if Char = '"' and then not Quotes_Seen then | ||
Quotes_Seen := True; | ||
Put (O, Char); | ||
elsif (Char = '"' and then Quotes_Seen) | ||
or else Char = '+' | ||
then | ||
Put_Line (O, "+" & Build_Info & '"' & ";"); | ||
exit; | ||
else | ||
Put (O, Char); | ||
end if; | ||
end loop; | ||
end; | ||
else | ||
Put_Line (O, Line); | ||
end if; | ||
end; | ||
end loop; | ||
|
||
Close (F); | ||
Close (O); | ||
|
||
Ada.Directories.Delete_File (Filename); | ||
Ada.Directories.Rename (Filename & ".new", Filename); | ||
|
||
end Replace_Version; | ||
|
||
----------------- | ||
-- Git_Command -- | ||
----------------- | ||
|
||
type Result is record | ||
Output : Unbounded_String; | ||
Code : Integer; | ||
end record; | ||
|
||
function Git_Command (Args : String) return Result is | ||
use GNAT.OS_Lib; | ||
Arg_List : constant Argument_List_Access := | ||
Argument_String_To_List (Args); | ||
Code : aliased Integer; | ||
Output : constant String | ||
:= GNAT.Expect.Get_Command_Output | ||
("git", Arg_List.all, "", Code'Access, True); | ||
begin | ||
return (To_Unbounded_String (Output), Code); | ||
end Git_Command; | ||
|
||
begin | ||
if Exists ("ALR_VERSION_DONT_PATCH") then | ||
Ada.Text_IO.Put_Line ("Note: skipping version update"); | ||
return; | ||
end if; | ||
|
||
declare | ||
Dirty : constant String | ||
:= (if Argument_Count > 0 then | ||
Argument (1) | ||
elsif Git_Command ("diff-index --quiet HEAD --").Code /= 0 then | ||
"_dirty" | ||
else | ||
""); | ||
Commit : constant String | ||
:= To_String (Git_Command ("rev-parse --short HEAD").Output); | ||
begin | ||
Ada.Text_IO.Put_Line | ||
("Updating version in src/alire/alire-version.ads to commit " | ||
& Commit & Dirty & "..."); | ||
Replace_Version ("src/alire/alire-version.ads", Commit & Dirty); | ||
end; | ||
end 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,22 @@ | ||
with "config/version_patcher_config.gpr"; | ||
project Version_Patcher is | ||
|
||
for Source_Dirs use ("src/", "config/"); | ||
for Object_Dir use "obj/" & Version_Patcher_Config.Build_Profile; | ||
for Create_Missing_Dirs use "True"; | ||
for Exec_Dir use "bin"; | ||
for Main use ("version_patcher.adb"); | ||
|
||
package Compiler is | ||
for Default_Switches ("Ada") use Version_Patcher_Config.Ada_Compiler_Switches; | ||
end Compiler; | ||
|
||
package Binder is | ||
for Switches ("Ada") use ("-Es"); -- Symbolic traceback | ||
end Binder; | ||
|
||
package Install is | ||
for Artifacts (".") use ("share"); | ||
end Install; | ||
|
||
end Version_Patcher; |