From ea80aa44c52f551c401ef10538391542585278fd Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Sun, 23 Mar 2025 14:42:31 +0100 Subject: [PATCH] feat: `templates_parser` for file initializations (#1890) * feat: `templates_parser` for file initializations commit 72eff5c0b408b7fae9006e6b5f07a649fb33a73d Author: Alejandro R. Mosteo Date: Mon Mar 10 23:55:41 2025 +0100 Self-review commit 417497746894fc073e732f8b9ee870c7fe3caa1c Author: Alejandro R. Mosteo Date: Mon Mar 10 23:21:52 2025 +0100 Downgrade templates parser to avoid GNAT>=11 commit 9cece278f5644539833846659cba61909c89d25a Author: Alejandro R. Mosteo Date: Mon Mar 10 23:17:50 2025 +0100 Hash to avoid arbitrary regeneration commit bd240607edc6de98a1402ffb2368236e55e48474 Author: Alejandro R. Mosteo Date: Mon Mar 10 23:06:53 2025 +0100 Tests passing commit b37e33e93659ed520d75cd54887b0e40d2aa1666 Author: Alejandro R. Mosteo Date: Mon Mar 10 14:45:27 2025 +0100 update init to use templates commit ffd90a009adc636884126c2702edccaa02dd96dd Author: Alejandro R. Mosteo Date: Sun Mar 9 23:15:35 2025 +0100 Proof of concept working commit 95514205091938a83a6c61ed951988f4f2a9b917 Author: Alejandro R. Mosteo Date: Sun Mar 9 22:46:06 2025 +0100 Templated file trees commit 557e67ec31a2b28b2f1c28bbb99c1f94be5423bf Author: Alejandro R. Mosteo Date: Sun Mar 9 21:15:56 2025 +0100 Remove custom experiments in main commit f0c573d599fb4ce9d398f8a6b9f1309c289785ea Author: Alejandro R. Mosteo Date: Sun Mar 9 21:12:23 2025 +0100 Write file with templating commit 947d1db4467458955f79516207895104c13af42c Author: Alejandro R. Mosteo Date: Sun Mar 9 20:12:23 2025 +0100 Embedded resource writing (no templating) commit 5e533d5860066f80a5949815b43c726457757b9d Author: Alejandro R. Mosteo Date: Sun Mar 9 11:30:06 2025 +0100 Template registration commit fc19c099ce40600457ac48b91e7c9de4af694df1 Author: Alejandro R. Mosteo Date: Sun Mar 9 10:55:06 2025 +0100 embedder script commit 90d0778662e51d9153a2187597c4c4755cc8ddb7 Author: Alejandro R. Mosteo Date: Sun Mar 9 10:32:14 2025 +0100 Sample binary crate commit ce9ef501e92df5da5d9c89b668fa472555e820a8 Author: Alejandro R. Mosteo Date: Sun Nov 10 19:00:53 2024 +0100 wip: on track to 1st prototype commit 1e52e5803d4363428ed6c445ee3d4d9f40647c0a Author: Alejandro R. Mosteo Date: Sun Oct 27 20:05:57 2024 +0100 WIP: experimenting with embedded resources * Fix tests * Fix compilation with `alr build` * Fix tags initialization * Self-review * Remove useless template timestamp --- .gitmodules | 3 + alire.gpr | 7 +- alire.toml | 36 +- alire_common.gpr | 5 +- alr_env.gpr | 21 +- deps/gnatcoll-slim | 2 +- deps/templates-parser | 1 + src/alire/alire-directories.adb | 30 +- src/alire/alire-directories.ads | 3 + src/alire/alire-os_lib.adb | 10 +- src/alire/alire-os_lib.ads | 7 +- src/alire/alire-templates-builtins.ads | 111 +++++ src/alire/alire-templates.adb | 169 +++++++ src/alire/alire-templates.ads | 149 ++++++ src/alire/alire-toml_adapters.adb | 28 ++ src/alire/alire-toml_adapters.ads | 3 + src/alire/alire-utils-text_files.adb | 14 +- src/alire/alire-utils-text_files.ads | 2 + src/alire/alire-version.ads | 3 +- src/alire/alire_early_elaboration.adb | 4 + src/alr/alr-commands-init.adb | 470 +++--------------- src/templates/r-crate_bin_alire_toml.ads | 43 ++ src/templates/r-crate_bin_name_gpr.ads | 59 +++ src/templates/r-crate_bin_src_name_adb.ads | 20 + .../r-crate_common_gitignore_hidden.ads | 18 + src/templates/r-crate_lib_alire_toml.ads | 41 ++ src/templates/r-crate_lib_name_gpr.ads | 84 ++++ src/templates/r-crate_lib_src_name_ads.ads | 19 + .../r-crate_test_tests_alire_toml.ads | 32 ++ ...crate_test_tests_common_name_tests_ads.ads | 19 + ...-crate_test_tests_crate_test_tests_gpr.ads | 62 +++ ..._tests_src_name_testsxexample_test_adb.ads | 30 ++ src/templates/r.adb | 80 +++ src/templates/r.ads | 9 + support/embedder/.gitignore | 1 + support/embedder/embedder.sh | 122 +++++ support/embedder/templates.hash | 1 + templates/crate_bin/alire.toml | 19 + templates/crate_bin/name.gpr | 23 + templates/crate_bin/src/name.adb | 4 + templates/crate_common/gitignore.hidden | 10 + templates/crate_lib/alire.toml | 17 + templates/crate_lib/name.gpr | 30 ++ templates/crate_lib/src/name.ads | 3 + templates/crate_test/tests/alire.toml | 13 + .../crate_test/tests/common/name_tests.ads | 3 + .../crate_test/tests/crate_test_tests.gpr | 19 + .../tests/src/name_tests-example_test.adb | 7 + .../tests/workflows/init-with-pin/test.py | 5 +- 49 files changed, 1431 insertions(+), 440 deletions(-) create mode 160000 deps/templates-parser create mode 100644 src/alire/alire-templates-builtins.ads create mode 100644 src/alire/alire-templates.adb create mode 100644 src/alire/alire-templates.ads create mode 100644 src/templates/r-crate_bin_alire_toml.ads create mode 100644 src/templates/r-crate_bin_name_gpr.ads create mode 100644 src/templates/r-crate_bin_src_name_adb.ads create mode 100644 src/templates/r-crate_common_gitignore_hidden.ads create mode 100644 src/templates/r-crate_lib_alire_toml.ads create mode 100644 src/templates/r-crate_lib_name_gpr.ads create mode 100644 src/templates/r-crate_lib_src_name_ads.ads create mode 100644 src/templates/r-crate_test_tests_alire_toml.ads create mode 100644 src/templates/r-crate_test_tests_common_name_tests_ads.ads create mode 100644 src/templates/r-crate_test_tests_crate_test_tests_gpr.ads create mode 100644 src/templates/r-crate_test_tests_src_name_testsxexample_test_adb.ads create mode 100644 src/templates/r.adb create mode 100644 src/templates/r.ads create mode 100644 support/embedder/.gitignore create mode 100755 support/embedder/embedder.sh create mode 100644 support/embedder/templates.hash create mode 100644 templates/crate_bin/alire.toml create mode 100644 templates/crate_bin/name.gpr create mode 100644 templates/crate_bin/src/name.adb create mode 100644 templates/crate_common/gitignore.hidden create mode 100644 templates/crate_lib/alire.toml create mode 100644 templates/crate_lib/name.gpr create mode 100644 templates/crate_lib/src/name.ads create mode 100644 templates/crate_test/tests/alire.toml create mode 100644 templates/crate_test/tests/common/name_tests.ads create mode 100644 templates/crate_test/tests/crate_test_tests.gpr create mode 100644 templates/crate_test/tests/src/name_tests-example_test.adb diff --git a/.gitmodules b/.gitmodules index 92d69327..ca9f5279 100644 --- a/.gitmodules +++ b/.gitmodules @@ -69,3 +69,6 @@ [submodule "deps/yeison"] path = deps/yeison url = https://github.com/mosteo/yeison +[submodule "deps/templates-parser"] + path = deps/templates-parser + url = https://github.com/alire-project/templates-parser diff --git a/alire.gpr b/alire.gpr index 05206784..9e223591 100644 --- a/alire.gpr +++ b/alire.gpr @@ -17,6 +17,7 @@ with "simple_logging"; with "si_units"; with "spdx"; with "stopwatch"; +with "templates_parser"; with "toml_slicer"; with "uri_ada"; with "xml_ez_out"; @@ -25,10 +26,12 @@ library project Alire is for Library_Name use "alire"; - -- Set OS-dependent source files + -- OS-independent source files - Src_Dirs := ("src/alire"); + Src_Dirs := ("src/alire", + "src/templates"); + -- OS-dependent source files case Alire_Common.Host_Os is when "freebsd" => Src_Dirs := Src_Dirs & ("src/alire/os_freebsd"); when "openbsd" => Src_Dirs := Src_Dirs & ("src/alire/os_openbsd"); diff --git a/alire.toml b/alire.toml index 43ce9d9d..3448d79a 100644 --- a/alire.toml +++ b/alire.toml @@ -31,21 +31,24 @@ semantic_versioning = "^3.0" simple_logging = "^2.0" si_units = "~0.2.2" stopwatch = "~0.1" +templates_parser = "^24" # Latests pre-Ada 2022 version toml_slicer = "~0.1" uri_ada = "^2.0" spdx = "~0.2" -# For some reason static-pic is causing problems in CLIC [gpr-set-externals] -CLIC_LIBRARY_TYPE="static" +CLIC_LIBRARY_TYPE="static" # Has problems with "static-pic" for some reason -# Building alr requires the explicit setting of this variable +# Building alr requires the explicit setting of these variables +# ALIRE_OS required by alr +# GNATCOLL_OS required by gnatcoll +# PRJ_TARGET required by templates_parser [gpr-set-externals."case(os)"] -freebsd = { ALIRE_OS = "freebsd" } -openbsd = { ALIRE_OS = "openbsd" } -linux = { ALIRE_OS = "linux" } -macos = { ALIRE_OS = "macos" } -windows = { ALIRE_OS = "windows" } +freebsd = { ALIRE_OS = "freebsd", GNATCOLL_OS = "unix", PRJ_TARGET = "FreeBSD" } +openbsd = { ALIRE_OS = "openbsd", GNATCOLL_OS = "unix", PRJ_TARGET = "UNIX" } +linux = { ALIRE_OS = "linux", GNATCOLL_OS = "unix", PRJ_TARGET = "Linux" } +macos = { ALIRE_OS = "macos", GNATCOLL_OS = "osx", PRJ_TARGET = "macOS" } +windows = { ALIRE_OS = "windows", GNATCOLL_OS = "windows", PRJ_TARGET = "Windows" } "..." = { ALIRE_OS = "unknown" } # Will cause the build to fail # Some dependencies require precise versions during the development cycle: @@ -83,7 +86,8 @@ commit = "60729edf31816aca0036b13b2794c39a9bd0172e" [pins.gnatcoll] url = "https://github.com/alire-project/gnatcoll-core.git" -commit = "4e663b87a028252e7e074f054f8f453661397166" +commit = "40cb993cc0bdd84bd7c4d5ff0438380751497c16" + [pins.lml] url = "https://github.com/mosteo/lml_ada.git" commit = "3d79edaff98bc4985014c641327ceb22d655df6b" @@ -112,6 +116,11 @@ commit = "9329d2591b82440ccc859a53f1380ac07ea4194d" url = "https://github.com/mosteo/stopwatch" commit = "f607a63b714f09bbf6126de9851cbc21cf8666c9" +[pins.templates_parser] +# We pin templates parser to avoid a spurious dependency on gnat>=14 +url = "https://github.com/alire-project/templates-parser" +commit = "441acdc3769469e348680d4afd1928022a4da36b" + [pins.toml_slicer] url = "https://github.com/mosteo/toml_slicer" commit = "3e5cbdb5673b85a1da6344a41764ef1cbafe3289" @@ -133,6 +142,15 @@ command = ["pwsh", "scripts/version-patcher.ps1"] type = "pre-build" command = ["scripts/version-patcher.sh"] +# Before building, on Linux only, we regenerate resources. This is not needed +# on other platforms as this is only to ensure that in the rare case of +# template modification, the developer on Linux has not to regenerate manually +# every time. For builds on GitHub, embedded templates should be up to date. +[[actions]] +[actions.'case(os)'.linux] +type = "pre-build" +command = ["support/embedder/embedder.sh"] + [test] runner = "alire" directory = "testsuite/tests_ada" diff --git a/alire_common.gpr b/alire_common.gpr index ed3281ee..42b5f326 100644 --- a/alire_common.gpr +++ b/alire_common.gpr @@ -64,7 +64,7 @@ abstract project Alire_Common is "-gnatx", "-gnatwJ" -- Disable warnings about obsolescent "()" ); - when "disabled" => Experimental_Ada_Switches := (); + when "disabled" => Experimental_Ada_Switches := ("-gnat2012"); end case; Ada_Common_Switches := @@ -110,7 +110,8 @@ abstract project Alire_Common is -- Enable lots of extra runtime checks "-gnatVa", "-gnatwa", "-gnato", "-fstack-check", "-gnata", "-gnatf", "-fPIC") - & Style_Check_Switches; + & Style_Check_Switches + & Experimental_Ada_Switches; for Default_Switches ("C") use ("-g", "-O2", "-Wall", "-fPIC"); -- Likewise for C units diff --git a/alr_env.gpr b/alr_env.gpr index 0d246fcd..219775f2 100644 --- a/alr_env.gpr +++ b/alr_env.gpr @@ -28,6 +28,7 @@ aggregate project Alr_Env is "deps/simple_logging", "deps/spdx", "deps/stopwatch", + "deps/templates-parser", "deps/toml_slicer", "deps/umwi", "deps/uri-ada", @@ -40,11 +41,21 @@ aggregate project Alr_Env is -- Set environment variables for dependencies case Alire_Common.Host_Os is - when "freebsd" => for External ("GNATCOLL_OS") use "unix"; - when "openbsd" => for External ("GNATCOLL_OS") use "unix"; - when "linux" => for External ("GNATCOLL_OS") use "unix"; - when "macos" => for External ("GNATCOLL_OS") use "osx"; - when "windows" => for External ("GNATCOLL_OS") use "windows"; + when "freebsd" => + for External ("GNATCOLL_OS") use "unix"; + for External ("PRJ_TARGET") use "FreeBSD"; -- used by templates_parser + when "openbsd" => + for External ("GNATCOLL_OS") use "unix"; + for External ("PRJ_TARGET") use "UNIX"; + when "linux" => + for External ("GNATCOLL_OS") use "unix"; + for External ("PRJ_TARGET") use "Linux"; + when "macos" => + for External ("GNATCOLL_OS") use "osx"; + for External ("PRJ_TARGET") use "macOS"; + when "windows" => + for External ("GNATCOLL_OS") use "windows"; + for External ("PRJ_TARGET") use "Windows"; end case; for External ("LIBRARY_TYPE") use "static"; diff --git a/deps/gnatcoll-slim b/deps/gnatcoll-slim index 4e663b87..40cb993c 160000 --- a/deps/gnatcoll-slim +++ b/deps/gnatcoll-slim @@ -1 +1 @@ -Subproject commit 4e663b87a028252e7e074f054f8f453661397166 +Subproject commit 40cb993cc0bdd84bd7c4d5ff0438380751497c16 diff --git a/deps/templates-parser b/deps/templates-parser new file mode 160000 index 00000000..441acdc3 --- /dev/null +++ b/deps/templates-parser @@ -0,0 +1 @@ +Subproject commit 441acdc3769469e348680d4afd1928022a4da36b diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index 38249592..d91def8b 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -469,6 +469,13 @@ package body Alire.Directories is Alire.Utils.Finalize_Exception (E); end Finalize; + ------------ + -- Exists -- + ------------ + + function Exists (Path : Any_Path) return Boolean + is (Den.Exists (Den.Scrub (Path))); + ------------------ -- Is_Directory -- ------------------ @@ -1023,14 +1030,23 @@ package body Alire.Directories is Backup_Dir : Any_Path := "") return Replacer is begin - return This : constant Replacer := (Length => File'Length, - Backup_Len => Backup_Dir'Length, - Original => File, - Backup => Backup, - Backup_Dir => Backup_Dir, - Temp_Copy => <>) + return This : constant Replacer := + (Length => File'Length, + Backup_Len => Backup_Dir'Length, + Original => File, + Backup => Is_File (File) and then Backup, + Backup_Dir => Backup_Dir, + Temp_Copy => <>) do - Ada.Directories.Copy_File (File, This.Temp_Copy.Filename); + if Exists (File) then + if Is_File (File) then + Ada.Directories.Copy_File (File, This.Temp_Copy.Filename); + else + Raise_Checked_Error + ("Cannot replace path " & File + & " denoting not a file but: " & Den.Kind (File)'Image); + end if; + end if; end return; end New_Replacement; diff --git a/src/alire/alire-directories.ads b/src/alire/alire-directories.ads index f3292093..c7c79fb7 100644 --- a/src/alire/alire-directories.ads +++ b/src/alire/alire-directories.ads @@ -75,6 +75,9 @@ package Alire.Directories is function Find_Relative_Path_To (Path : Any_Path) return Any_Path; -- Same as Find_Relative_Path (Parent => Current, Child => Path) + function Exists (Path : Any_Path) return Boolean; + -- Path designates something, be it file, dir or symbolic link + function Is_Directory (Path : Any_Path) return Boolean; -- Returns false for non-existing paths too diff --git a/src/alire/alire-os_lib.adb b/src/alire/alire-os_lib.adb index a5e3022b..f96541c4 100644 --- a/src/alire/alire-os_lib.adb +++ b/src/alire/alire-os_lib.adb @@ -6,8 +6,14 @@ package body Alire.OS_Lib is -- "/" -- --------- - function "/" (L, R : String) return String is - (L & GNAT.OS_Lib.Directory_Separator & R); + function "/" (L : Any_Path; R : Relative_Path) return Any_Path is + (L + & (if R /= "" and then L (L'Last) /= GNAT.OS_Lib.Directory_Separator + then "" & GNAT.OS_Lib.Directory_Separator + else "") + & (if R /= "" + then R + else "")); ------------- -- Bailout -- diff --git a/src/alire/alire-os_lib.ads b/src/alire/alire-os_lib.ads index 5b0b2b81..bb2f1358 100644 --- a/src/alire/alire-os_lib.ads +++ b/src/alire/alire-os_lib.ads @@ -4,12 +4,15 @@ with GNATCOLL.OS.Constants; package Alire.OS_Lib with Preelaborate is - function "/" (L, R : String) return String; + function "/" (L : Any_Path; R : Relative_Path) return Any_Path with + Pre => L /= "", + Post => (if R = "" then "/"'Result = L); -- Shorthand for path composition -- Package to enable easy use of "/" package Operators is - function "/" (L, R : String) return String renames OS_Lib."/"; + function "/" (L : Any_Path; R : Relative_Path) return Any_Path + renames OS_Lib."/"; end Operators; procedure Bailout (Code : Integer := 0); diff --git a/src/alire/alire-templates-builtins.ads b/src/alire/alire-templates-builtins.ads new file mode 100644 index 00000000..870b35f5 --- /dev/null +++ b/src/alire/alire-templates-builtins.ads @@ -0,0 +1,111 @@ +pragma Style_Checks (Off); +-- awsres doesn't use proper casing, and fighting GNAT studio is tiresome + +with R.Crate_Bin_Alire_Toml; +with R.Crate_Bin_Name_Gpr; +with R.Crate_Bin_Src_Name_Adb; + +with R.Crate_Common_Gitignore_Hidden; + +with R.Crate_Lib_Alire_Toml; +with R.Crate_Lib_Name_Gpr; +with R.Crate_Lib_Src_Name_Ads; + +with R.Crate_Test_Tests_Alire_Toml; +with R.Crate_Test_Tests_Common_Name_Tests_Ads; +with R.Crate_Test_Tests_Crate_Test_Tests_Gpr; +with R.Crate_Test_Tests_Src_Name_Testsxexample_Test_Adb; + +private with Alire.TOML_Adapters; + +package Alire.Templates.Builtins is + + -- Hardcoded initializations in Alire + + -- Info needed to initialize a crate, MUST NOT be TOML-escaped (done here), + -- and its corresponding template name. + type Crate_Init_Info is record + Name : UString; -- NAME + Is_Library : Boolean; -- IS_LIBRARY + GitHub_Login : UString; -- LOGIN + Username : UString; -- USERNAME + Email : UString; -- EMAIL + Licenses : UString; -- LICENSES + Description : UString; -- DESCRIPTION + Website : UString; -- WEBSITE + Tags : AAA.Strings.Vector; -- TAGS (expanded: "tag1", "tag2"...) + With_Test : Boolean; -- WITH_TEST + end record; + + function Init_Crate_Translation (Info : Crate_Init_Info) + return Translations; + -- Use this translation to initialize crates (trees immediately following) + + -- Files common to binary and library crates + Crate_Common : constant Tree := New_Tree + .Append (".gitignore", +R.Crate_Common_Gitignore_Hidden.Content) + .Append ("share/@_NAME_@", New_Dir) + ; + + -- Files to initialize a binary crate + Crate_Bin : constant Tree := Crate_Common + .Append ("alire.toml", +R.Crate_Bin_Alire_Toml.Content) + .Append ("@_NAME_@.gpr", +R.Crate_Bin_Name_Gpr.Content) + .Append ("src/@_NAME_@.adb", +R.Crate_Bin_Src_Name_Adb.Content) + ; + + -- Files to initialize a library crate + Crate_Lib : constant Tree := Crate_Common + .Append ("alire.toml", +R.Crate_Lib_Alire_Toml.Content) + .Append ("@_NAME_@.gpr", +R.Crate_Lib_Name_Gpr.Content) + .Append ("src/@_NAME_@.ads", +R.Crate_Lib_Src_Name_Ads.Content) + ; + + -- Files to initalize a no-skel binary crate + Crate_Bin_No_Skel : constant Tree := New_Tree + .Append ("alire.toml", +R.Crate_Bin_Alire_Toml.Content) + ; + + -- Files to initialize a no-skel library crate + Crate_Lib_No_Skel : constant Tree := New_Tree + .Append ("alire.toml", +R.Crate_Lib_Alire_Toml.Content) + ; + + -- Files to initialize a test crate within a regular crate + Crate_Test : constant Tree := New_Tree + .Append (".gitignore", +R.Crate_Common_Gitignore_Hidden.Content) + .Append ("alire.toml", +R.Crate_Test_Tests_Alire_Toml.Content) + .Append ("@_NAME_@_tests.gpr", +R.Crate_Test_Tests_Crate_Test_Tests_Gpr.Content) + .Append ("common/@_NAME_@_tests.ads", +R.Crate_Test_Tests_Common_Name_Tests_Ads.Content) + .Append ("src/@_NAME_@_tests-example_test.adb", +R.Crate_Test_Tests_Src_Name_Testsxexample_Test_Adb.Content) + ; + +private + + pragma Style_Checks (On); + + use TOML_Adapters; + + ---------------------------- + -- Init_Crate_Translation -- + ---------------------------- + + function Init_Crate_Translation (Info : Crate_Init_Info) + return Translations + is (New_Translation + .Append ("NAME", Info.Name) + .Append ("IS_LIBRARY", Info.Is_Library) + .Append ("LOGIN", Info.GitHub_Login) + .Append ("USERNAME", Escape (+Info.Username)) + .Append ("EMAIL", Info.Email) + .Append ("LICENSES", Info.Licenses) + .Append ("DESCRIPTION", Escape (+Info.Description)) + .Append ("WEBSITE", Info.Website) + .Append ("TAGS", + (if Info.Tags.Is_Empty + then "" + else '"' & Info.Tags.Flatten ('"' & ", " & '"') & '"')) + .Append ("WITH_TEST", Info.With_Test) + ); + +end Alire.Templates.Builtins; diff --git a/src/alire/alire-templates.adb b/src/alire/alire-templates.adb new file mode 100644 index 00000000..56e57920 --- /dev/null +++ b/src/alire/alire-templates.adb @@ -0,0 +1,169 @@ +with Ada.Characters.Latin_1; + +with Alire.Directories; +with Alire.Errors; +with Alire.Utils.Text_Files; +with Alire.VFS; + +with Den; + +package body Alire.Templates is + + ------------ + -- Append -- + ------------ + + function Append (This : Tree; + File : Portable_Path; + Data : Filesystem_Entry) return Tree + is + begin + return Result : Tree := This do + Result.Insert (File, Data); + end return; + end Append; + + --------------- + -- Append_If -- + --------------- + + function Append_If (This : Tree; + Cond : Boolean; + File : Portable_Path; + Data : Filesystem_Entry) return Tree + is (if Cond + then This.Append (File, Data) + else This); + + --------------- + -- As_String -- + --------------- + + function As_String (Data : Embedded) return String is + Fake_String : aliased String (1 .. Data'Length); + for Fake_String'Address use Data (Data'First)'Address; + begin + return Fake_String; + end As_String; + + -------------------- + -- Translate_File -- + -------------------- + + procedure Translate_File (Src : Embedded; + Dst : Relative_File; + Map : Translations) + is + + ------------------- + -- Parsing_Error -- + ------------------- + + procedure Parsing_Error (Tag_Name : String; + Filename : String := ""; + Line : Natural := 0; + Reason : Templates_Parser.Reason_Kind) + is + begin + if Reason in Templates_Parser.Unused then + return; + -- Unused tags are usual e.g. for no-skel initialization + end if; + + raise Program_Error with + Errors.Set + ("bad tag during generation of " & Filename + & " at line" & Line'Image + & ", offending tag is " & Tag_Name + & ", reason is " & Reason'Image); + end Parsing_Error; + + Temp : Directories.Temp_File; -- temporary template on disk + begin + -- To gain access to the full capabilities of Templates_Parser we must + -- read the file from disk, so we first write the embedded data to a + -- temporary file we can read. + + declare + Contents : constant AAA.Strings.Vector := + AAA.Strings.To_Vector (As_String (Src)); + Tmpl : Utils.Text_Files.File := + Utils.Text_Files.Create (Temp.Filename); + begin + Tmpl.Lines.all := Contents; + end; + + -- At this point the source template exists on disk. We also take the + -- opportunity to replace UNIX \n in the file so generation on other + -- platforms uses the proper line endings. + + declare + Parsed : constant String := + Templates_Parser.Parse + (Filename => Temp.Filename, + Translations => Map.Set, + Report => Parsing_Error'Access); + Content : AAA.Strings.Vector + := AAA.Strings.Split (Parsed, + Ada.Characters.Latin_1.LF); + File : Utils.Text_Files.File := Utils.Text_Files.Create (Dst); + begin + -- Remove a possibly empty last line + if not Content.Is_Empty and then Content.Last_Element = "" then + Content.Delete_Last; + end if; + + File.Lines.all := Content; + end; + end Translate_File; + + -------------------- + -- Translate_Tree -- + -------------------- + + procedure Translate_Tree (Parent : Relative_Path; + Files : Tree'Class; + Map : Translations) + is + package Dirs renames Directories; + package TP renames Templates_Parser; + use Directories.Operators; + use File_Data_Maps; + begin + for I in Files.Iterate loop + declare + Raw_Name : constant Portable_Path := Key (I); + + -- Translate the path + Entry_Name : constant Relative_File := + VFS.To_Native + (Portable_Path + (TP.Translate (String (Raw_Name), + Map.Set))); + begin + -- Ensure parent exists + Dirs.Create_Tree (Parent / Dirs.Parent (Entry_Name)); + + -- And translate the actual file or create the directory + if Files (I).Is_Dir then + Dirs.Create_Tree (Parent / Entry_Name); + else + declare + File_Name : constant Any_Path := Parent / Entry_Name; + begin + if Den.Exists (File_Name) then + Raise_Checked_Error + ("Cannot generate, " + & TTY.URL (File_Name) & " already exists"); + else + Translate_File (Files (I).Data, + Parent / Entry_Name, + Map); + end if; + end; + end if; + end; + end loop; + end Translate_Tree; + +end Alire.Templates; diff --git a/src/alire/alire-templates.ads b/src/alire/alire-templates.ads new file mode 100644 index 00000000..b292c817 --- /dev/null +++ b/src/alire/alire-templates.ads @@ -0,0 +1,149 @@ +with Ada.Calendar; +with Ada.Containers.Indefinite_Ordered_Maps; +with Ada.Streams; + +private with Templates_Parser; + +package Alire.Templates with Elaborate_Body is + + type Embedded is access constant Ada.Streams.Stream_Element_Array; + + type Translations (<>) is private; + -- Wrapper of Templates_Parser mappings for cleaner syntax here and in + -- Alire.Templates.Builtins + + procedure Translate_File (Src : Embedded; + Dst : Relative_File; + Map : Translations); + -- Apply templating to a single file + + -- Types to support generation of filesystem trees from templates, which is + -- our main need with `alr init` at present. + + type Filesystem_Entry (Is_Dir : Boolean) is record + case Is_Dir is + when True => null; + when False => Data : Embedded; + end case; + end record; + + function New_Dir return Filesystem_Entry; + + function New_File (Data : Embedded) return Filesystem_Entry; + + package File_Data_Maps is new + Ada.Containers.Indefinite_Ordered_Maps (Portable_Path, Filesystem_Entry); + -- In addition to be portable, these paths must be obviously relative + + type Tree is new File_Data_Maps.Map with null record; + -- Just a collection of names --> data + + -- See Alire.Templates.Builtins for how to use the following tree-building + -- subprograms + + function New_Tree return Tree; + + function Append (This : Tree; + File : Portable_Path; + Data : Filesystem_Entry) return Tree; + + function Append_If (This : Tree; + Cond : Boolean; + File : Portable_Path; + Data : Filesystem_Entry) return Tree; + -- Conditionally append an entry to a filesystem hierarchy + + procedure Translate_Tree (Parent : Relative_Path; + Files : Tree'Class; + Map : Translations); + -- Will create all files under Parent dir, respecting their relative path + -- and applying the given translations to both contents and paths. + + -- Builders for use in child packages + + function "+" (S : aliased Ada.Streams.Stream_Element_Array) + return Filesystem_Entry; + -- Sweep under the rug uses of 'Access, used in child package Builtins + + -- Other procedures + + procedure Register (File : Relative_Path; + Data : Embedded; + Stamp : Ada.Calendar.Time) is null; + -- This is required by the code generated by awsres, but we do not actually + -- need (for now) to register resources by name, as we reference them + -- directly in their header files which eliminates one indirection and + -- possible error source. This could be made private by making embedded + -- generated packages children of Alire.Templates, but those already have + -- quite long names so a common prefix will make working with them even + -- more uncomfortable. + +private + + --------- + -- "+" -- + --------- + + function "+" (S : aliased Ada.Streams.Stream_Element_Array) + return Filesystem_Entry + is (New_File (S'Unchecked_Access)); + -- Hide uses of 'Access, used in child package Builtins + + type Translations is tagged record + Set : Templates_Parser.Translate_Set; + end record; + + --------------------- + -- New_Translation -- + --------------------- + + function New_Translation return Translations + is (Set => Templates_Parser.Null_Set); + + function Append (This : Translations; + Var : String; + Val : Boolean) return Translations + is (Set => Templates_Parser."&" + (This.Set, Templates_Parser.Assoc (Var, Val))); + + ------------ + -- Append -- + ------------ + + function Append (This : Translations; + Var : String; + Val : String) return Translations + is (Set => Templates_Parser."&" + (This.Set, Templates_Parser.Assoc (Var, Val))); + + ------------ + -- Append -- + ------------ + + function Append (This : Translations; + Var : String; + Val : UString) return Translations + is (This.Append (Var, +Val)); + + ------------- + -- New_Dir -- + ------------- + + function New_Dir return Filesystem_Entry is (Is_Dir => True); + + -------------- + -- New_File -- + -------------- + + function New_File (Data : Embedded) return Filesystem_Entry + is (Is_Dir => False, + Data => Data); + + -------------- + -- New_Tree -- + -------------- + + function New_Tree return Tree + is (File_Data_Maps.Empty_Map with null record); + +end Alire.Templates; diff --git a/src/alire/alire-toml_adapters.adb b/src/alire/alire-toml_adapters.adb index 5a0a3791..3623fedd 100644 --- a/src/alire/alire-toml_adapters.adb +++ b/src/alire/alire-toml_adapters.adb @@ -2,6 +2,34 @@ with Alire.Utils; package body Alire.TOML_Adapters is + ------------ + -- Escape -- + ------------ + + function Escape (S : String) return String + -- We trick the TOML exporter to get a valid escaped string + is + use TOML; + Table : constant TOML_Value := Create_Table; + begin + Table.Set ("key", TOML.Create_String (S)); + + -- Remove excess whitespace and quotation + declare + Result : constant String := + Trim + (Trim + (Tail (TOML.Dump_As_String (Table), '='), + ASCII.LF)); + begin + -- Trimming the TOML quotes at the extremes fails for a + -- string with quotes at the extremes of the string because + -- Ada.Strings.Trim removes those too! So just remove the + -- quotes we know are there. + return Result (Result'First + 1 .. Result'Last - 1); + end; + end Escape; + -------------- -- Finalize -- -------------- diff --git a/src/alire/alire-toml_adapters.ads b/src/alire/alire-toml_adapters.ads index 39be73b6..b8eab37d 100644 --- a/src/alire/alire-toml_adapters.ads +++ b/src/alire/alire-toml_adapters.ads @@ -9,6 +9,9 @@ with TOML; use all type TOML.Any_Value_Kind; package Alire.TOML_Adapters with Preelaborate is + function Escape (S : String) return String; + -- Returns an unquoted string escaped for use in a doubly-quoted string + function Create_Table (Key : String; Value : TOML.TOML_Value) return TOML.TOML_Value with diff --git a/src/alire/alire-utils-text_files.adb b/src/alire/alire-utils-text_files.adb index b060d233..199074e3 100644 --- a/src/alire/alire-utils-text_files.adb +++ b/src/alire/alire-utils-text_files.adb @@ -1,9 +1,11 @@ -with Ada.Text_IO; use Ada.Text_IO; +with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO; with AAA.Strings; use AAA.Strings; with Alire.Directories; +with LML; + package body Alire.Utils.Text_Files is ------------------ @@ -55,12 +57,16 @@ package body Alire.Utils.Text_Files is This.Backup, This.Backup_Dir); begin - Open (File, Out_File, Replacer.Editable_Name); + Create (File, Out_File, Replacer.Editable_Name); for Line of This.Lines loop - Put_Line (File, Line); + Put_Line (File, LML.Decode (Line)); end loop; Close (File); Replacer.Replace; + exception + when E : others => + Log_Exception (E); + raise; end; exception @@ -124,7 +130,7 @@ package body Alire.Utils.Text_Files is do Open (F, In_File, From); while not End_Of_File (F) loop - This.Orig.Append (Get_Line (F)); + This.Orig.Append (LML.Encode (Get_Line (F))); end loop; Close (F); diff --git a/src/alire/alire-utils-text_files.ads b/src/alire/alire-utils-text_files.ads index abf43f68..656532e1 100644 --- a/src/alire/alire-utils-text_files.ads +++ b/src/alire/alire-utils-text_files.ads @@ -6,6 +6,8 @@ package Alire.Utils.Text_Files is -- lines. On destruction, changes to the contents are written back to disk. -- A backup ".prev" file is also created by default. + -- Lines are presumed to be UTF-8 and are written via Wide_Wide_Text_IO + type File (<>) is tagged limited private; function Create (Name : Any_Path) return File; diff --git a/src/alire/alire-version.ads b/src/alire/alire-version.ads index d5f35336..30fcd5a9 100644 --- a/src/alire/alire-version.ads +++ b/src/alire/alire-version.ads @@ -12,7 +12,8 @@ private -- Remember to update Alire.Index branch if needed too - Current_Str : constant String := "2.2.0-dev"; + Current_Str : constant String := "3.0.0-dev"; + -- 3.0.0: new built-in test runner -- 2.1.0: new solver and other internal largish refactorings, bugfixes -- 2.0.2: quarterly bugfix maintenance release -- 2.0.1: fix `alr install` and minor fixes diff --git a/src/alire/alire_early_elaboration.adb b/src/alire/alire_early_elaboration.adb index 0f92508f..ffb80ef1 100644 --- a/src/alire/alire_early_elaboration.adb +++ b/src/alire/alire_early_elaboration.adb @@ -12,6 +12,8 @@ with GNAT.IO; with Interfaces.C_Streams; +with r; + with Simple_Logging.Filtering; package body Alire_Early_Elaboration is @@ -266,4 +268,6 @@ begin TTY_Detection; Early_Switch_Detection; + + r.Init; -- Register all embedded resources end Alire_Early_Elaboration; diff --git a/src/alr/alr-commands-init.adb b/src/alr/alr-commands-init.adb index c3ac93c9..298dbf90 100644 --- a/src/alr/alr-commands-init.adb +++ b/src/alr/alr-commands-init.adb @@ -1,332 +1,49 @@ with AAA.Text_IO; -with Ada.Directories; with Ada.Wide_Wide_Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Alire.Directories; with Alire.Paths; with Alire.Settings.Builtins; with Alire.Roots.Optional; +with Alire.Templates.Builtins; with Alire.Utils.User_Input.Query_Config; with CLIC.User_Input; -with GNATCOLL.VFS; use GNATCOLL.VFS; - -with TOML; - with SPDX; with CLIC.TTY; use CLIC.TTY; package body Alr.Commands.Init is + package Dirs renames Alire.Directories; + package Templates renames Alire.Templates; package TIO renames Ada.Wide_Wide_Text_IO; package UI renames Alire.Utils.User_Input; - type Crate_Kind is (Library, Binary); + subtype Crate_Init_Info is Templates.Builtins.Crate_Init_Info; - type Crate_Init_Info is record - Name : Unbounded_String; - Kind : Crate_Kind := Library; - GitHub_Login : Unbounded_String; - Username : Unbounded_String; - Email : Unbounded_String; - Licenses : Unbounded_String; - Description : Unbounded_String; - Website : Unbounded_String; - Tags : AAA.Strings.Vector; - end record; + type Crate_Kind is (Library, Binary); -------------- -- Generate -- -------------- procedure Generate (Cmd : Command; - Info : Crate_Init_Info) + Info : Alire.Templates.Builtins.Crate_Init_Info) is - use AAA.Strings; + use Dirs.Operators; - For_Library : constant Boolean := Info.Kind = Library; - Name : constant String := To_String (Info.Name); - Lower_Name : constant String := AAA.Strings.To_Lower_Case (Name); - Upper_Name : constant String := AAA.Strings.To_Upper_Case (Name); - Mixed_Name : constant String := AAA.Strings.To_Mixed_Case (Name); + For_Library : constant Boolean := Info.Is_Library; + Name : constant Alire.Crate_Name := +To_String (Info.Name); - Directory : constant Virtual_File := + Directory : constant Alire.Absolute_Path := (if Cmd.In_Place - then Get_Current_Dir - else Create (+Name, Normalize => True)); - Src_Directory : constant Virtual_File := Directory / "src"; - Share_Directory : constant Virtual_File := - Directory / "share" / Filesystem_String (Lower_Name); - Test_Directory : constant Virtual_File := - Directory / (+Alire.Paths.Default_Tests_Folder); - - File : TIO.File_Type; - - function Create (Filename : String) return Boolean; - -- Return False if the file already exists - - procedure Put_New_Line; - procedure Put_Line (S : String); - -- Shortcuts to write to File - - function Escape (S : String) return String - -- We trick the TOML exporter to get a valid escaped string - is - use TOML; - Table : constant TOML_Value := Create_Table; - begin - Table.Set ("key", TOML.Create_String (S)); - - -- Remove excess whitespace and quotation - declare - Result : constant String := - Trim - (Trim - (Tail (TOML.Dump_As_String (Table), '='), - ASCII.LF)); - begin - -- Trimming the TOML quotes at the extremes fails for a - -- string with quotes at the extremes of the string because - -- Ada.Strings.Trim removes those too! So just remove the - -- quotes we know are there. - return Result (Result'First + 1 .. Result'Last - 1); - end; - end Escape; - - function Q (S : String) return String is ('"' & Escape (S) & '"'); - -- Quote string - - function Q (S : Unbounded_String) return String - is (Q (To_String (S))); - -- Quote string - - function Arr (S : String) return String is ("[" & S & "]"); - -- Wrap string into TOML array - - function Q_Arr (Arr : AAA.Strings.Vector) return String - is (if Arr.Is_Empty - then "[]" - else "[""" & Arr.Flatten (""", """) & """]"); - -- String vector to TOML array of strings - - procedure Generate_Project_File; - -- Generate a project file for this crate - - procedure Generate_Root_Package; - -- Generate the specification for the root package of this crate - - procedure Generate_Program_Main; - -- Generate the procedure body for the program main of this crate - - procedure Generate_Gitignore; - -- Generate or append .gitignore - - procedure Generate_Manifest; - -- Generates the initial manifest by hand. This is more legible than - -- exporting using To_TOML functions. We still use TOML encoding for - -- the generated strings to be on the safe side. - - --------------------------- - -- Generate_Project_File -- - --------------------------- - - procedure Generate_Project_File is - Filename : constant String := - +Full_Name (Directory / (+Lower_Name & ".gpr")); - begin - -- Use more than 80 columns for more readable strings - pragma Style_Checks ("M200"); - - -- Main project file - if not Create (Filename) then - Trace.Warning ("Cannot create '" & Filename & "'"); - return; - end if; - Put_Line ("with ""config/" & Lower_Name & "_config.gpr"";"); - Put_Line ("project " & Mixed_Name & " is"); - Put_New_Line; - if For_Library then - Put_Line (" for Library_Name use """ & Mixed_Name & """;"); - Put_Line (" for Library_Version use Project'Library_Name & "".so."" & " & Mixed_Name & "_Config.Crate_Version;"); - Put_New_Line; - end if; - Put_Line (" for Source_Dirs use (""src/"", ""config/"");"); - Put_Line (" for Object_Dir use ""obj/"" & " & Mixed_Name & "_Config.Build_Profile;"); - Put_Line (" for Create_Missing_Dirs use ""True"";"); - if For_Library then - Put_Line (" for Library_Dir use ""lib"";"); - Put_New_Line; - Put_Line (" type Library_Type_Type is " & - "(""relocatable"", ""static"", ""static-pic"");"); - Put_Line (" Library_Type : Library_Type_Type :="); - Put_Line (" external (""" & Upper_Name & "_LIBRARY_TYPE"", external (""LIBRARY_TYPE"", ""static""));"); - Put_Line (" for Library_Kind use Library_Type;"); - else - Put_Line (" for Exec_Dir use ""bin"";"); - Put_Line (" for Main use (""" & Lower_Name & ".adb"");"); - end if; - Put_New_Line; - Put_Line (" package Compiler is"); - Put_Line (" for Default_Switches (""Ada"") use " & Mixed_Name & "_Config.Ada_Compiler_Switches;"); - Put_Line (" end Compiler;"); - Put_New_Line; - Put_Line (" package Binder is"); - Put_Line (" for Switches (""Ada"") use (""-Es""); -- Symbolic traceback"); - Put_Line (" end Binder;"); - Put_New_Line; - Put_Line (" package Install is"); - Put_Line (" for Artifacts (""."") use (""share"");"); - Put_Line (" end Install;"); - Put_New_Line; - TIO.Put (File, WW ("end " & Mixed_Name & ";")); - pragma Style_Checks ("M80"); - - TIO.Close (File); - end Generate_Project_File; - - --------------------------- - -- Generate_Root_Package -- - --------------------------- - - procedure Generate_Root_Package is - Filename : constant String := - +Full_Name (Src_Directory / (+Lower_Name & ".ads")); - begin - if not Create (Filename) then - return; - end if; - Put_Line ("package " & Mixed_Name & " is"); - Put_New_Line; - TIO.Put (File, WW ("end " & Mixed_Name & ";")); - TIO.Close (File); - end Generate_Root_Package; - - --------------------------- - -- Generate_Program_Main -- - --------------------------- - - procedure Generate_Program_Main is - Filename : constant String := - +Full_Name (Src_Directory / (+Lower_Name & ".adb")); - begin - if not Create (Filename) then - return; - end if; - Put_Line ("procedure " & Mixed_Name & " is"); - Put_Line ("begin"); - Put_Line (" null;"); - TIO.Put (File, WW ("end " & Mixed_Name & ";")); - TIO.Close (File); - end Generate_Program_Main; - - ------------------------ - -- Generate_Gitignore -- - ------------------------ - - procedure Generate_Gitignore is - Filename : constant String := - +Full_Name (Directory / ".gitignore"); - begin - if Ada.Directories.Exists (Filename) then - TIO.Open (File, TIO.Append_File, Filename); - else - TIO.Create (File, TIO.Out_File, Filename); - end if; - - Put_Line ("/obj/"); - if For_Library then - Put_Line ("/lib/"); - else - Put_Line ("/bin/"); - end if; - Put_Line ("/alire/"); - Put_Line ("/config/"); - TIO.Close (File); - end Generate_Gitignore; - - ----------------------- - -- Generate_Manifest -- - ----------------------- - - procedure Generate_Manifest is - begin - declare - -- Retrieve initial values from config or user. Only the name may - -- require encoding, as emails and logins cannot contain strange - -- characters. - Login : constant String := To_String (Info.GitHub_Login); - Username : constant String := To_String (Info.Username); - Email : constant String := To_String (Info.Email); - Filename : constant String := - +Full_Name (Directory / (+Alire.Roots.Crate_File_Name)); - begin - if not Create (Filename) then - Reportaise_Command_Failed ("Cannot create '" & Filename & "'"); - end if; - Put_Line ("name = " & Q (Lower_Name)); - Put_Line ("description = " & Q (Info.Description)); - Put_Line ("version = " & Q ("0.1.0-dev")); - Put_New_Line; - Put_Line ("authors = " & Arr (Q (Username))); - Put_Line ("maintainers = " - & Arr (Q (Username & " <" & Email & ">"))); - if Login /= "" then - Put_Line ("maintainers-logins = " & Arr (Q (Login))); - end if; - Put_Line ("licenses = " & Q (Info.Licenses)); - Put_Line ("website = " & Q (Info.Website)); - Put_Line ("tags = " & Q_Arr (Info.Tags)); - end; - - if Cmd.Bin then - Put_New_Line; - Put_Line ("executables = " & Arr (Q (Lower_Name))); - end if; - - if not (Cmd.No_Skel or else Cmd.No_Test) then - Put_New_Line; - Put_Line ("[test]"); - Put_Line ("runner = ""alire"""); - end if; - - TIO.Close (File); - end Generate_Manifest; - - ------------ - -- Create -- - ------------ - - function Create (Filename : String) return Boolean is - begin - if Ada.Directories.Exists (Filename) then - Trace.Warning (Filename & " already exists."); - return False; - end if; - - TIO.Create (File, TIO.Out_File, Filename); - - return True; - end Create; - - ------------------ - -- Put_New_Line -- - ------------------ - - procedure Put_New_Line is - begin - TIO.New_Line (File); - end Put_New_Line; - - -------------- - -- Put_Line -- - -------------- - - procedure Put_Line (S : String) is - begin - TIO.Put_Line (File, WW (S)); - end Put_Line; + then Dirs.Current + else Dirs.Full_Name (Name.As_String)); + Test_Directory : constant Alire.Absolute_Path := + Directory / Alire.Paths.Default_Tests_Folder; --------------------- -- Generate_Config -- @@ -334,120 +51,64 @@ package body Alr.Commands.Init is procedure Generate_Config is Root : Alire.Roots.Optional.Root := - Alire.Roots.Optional.Detect_Root (+Directory.Full_Name); + Alire.Roots.Optional.Detect_Root (Directory); begin Root.Value.Build_Prepare (Saved_Profiles => False, Force_Regen => False); end Generate_Config; + use Alire; + ------------------------- - -- Generate_Test_Crate -- + -- Generate_Main_Crate -- ------------------------- - procedure Generate_Test_Crate is - Test_Srcs : constant Virtual_File := Test_Directory / "src"; - Test_Common : constant Virtual_File := Test_Directory / "common"; + procedure Generate_Main_Crate is + begin + Templates.Translate_Tree + (Directory, + (if For_Library + then Templates.Builtins.Crate_Lib + else Templates.Builtins.Crate_Bin), + Templates.Builtins.Init_Crate_Translation (Info)); + end Generate_Main_Crate; + + ----------------------- + -- Generate_Manifest -- + ----------------------- - Test_Lower : constant String := Lower_Name & "_tests"; - Test_Upper : constant String := Mixed_Name & "_Tests"; + procedure Generate_Manifest is begin - pragma Style_Checks ("M120"); + Templates.Translate_Tree + (Directory, + (if For_Library + then Templates.Builtins.Crate_Lib_No_Skel + else Templates.Builtins.Crate_Bin_No_Skel), + Templates.Builtins.Init_Crate_Translation (Info)); + end Generate_Manifest; - Test_Directory.Make_Dir; - if not Create (+Full_Name (Test_Directory / "alire.toml")) then - Trace.Warning ("Could not create test crate skeleton"); - return; - end if; - Put_Line ("name = '" & Test_Lower & "'"); - Put_Line ("description = ''"); - Put_Line ("version = '0.0.0-test'"); - Put_New_Line; - Put_Line ("[[depends-on]]"); - Put_Line (Lower_Name & " = '*'"); - Put_New_Line; - Put_Line ("[[pins]]"); - Put_Line (Lower_Name & " = { path = '..' }"); - Put_New_Line; - Put_Line ("[build-profiles]"); - Put_Line (Lower_Name & " = 'validation'"); - Put_Line (Test_Lower & " = 'validation'"); - TIO.Close (File); - - if not Create (+Full_Name (Test_Directory / (+Test_Lower & ".gpr"))) then - Trace.Warning ("Could not create project file 'tests/" & Test_Lower & ".gpr"); - return; - end if; - Put_Line ("with ""config/" & Test_Lower & "_config.gpr"";"); - Put_Line ("with ""config/" & Test_Lower & "_list_config.gpr"";"); - Put_New_Line; - Put_Line ("project " & Test_Upper & " is"); - Put_Line (" for Source_Dirs use (""src/**"", ""common/"", ""config/"");"); - Put_Line (" for Object_Dir use ""obj/"" & " & Test_Upper & "_Config.Build_Profile;"); - Put_Line (" for Create_Missing_Dirs use ""True"";"); - Put_Line (" for Exec_Dir use ""bin"";"); - Put_Line (" for Main use " & Test_Upper & "_List_Config.Test_Files;"); - Put_New_Line; - Put_Line (" package Compiler is"); - Put_Line (" for Default_Switches (""Ada"") use " & Test_Upper & "_Config.Ada_Compiler_Switches;"); - Put_Line (" end Compiler;"); - Put_New_Line; - Put_Line (" package Binder is"); - Put_Line (" for Switches (""Ada"") use (""-Es""); -- Symbolic traceback"); - Put_Line (" end Binder;"); - Put_Line ("end " & Test_Upper & ";"); - TIO.Close (File); - - if not Create (+Full_Name (Test_Directory / ".gitignore")) then - Trace.Warning ("Could not create .gitignore for test crate"); - return; - end if; - Put_Line ("/obj/"); - Put_Line ("/bin/"); - Put_Line ("/alire/"); - Put_Line ("/config/"); - TIO.Close (File); - - Test_Srcs.Make_Dir; - if not Create (+Full_Name (Test_Srcs / (+Test_Lower & "-example_test.adb"))) then - Trace.Warning ("Could not create example test in 'tests/src'"); - return; - end if; - Put_Line ("with Ada.Assertions;"); - Put_New_Line; - Put_Line ("procedure " & Test_Upper & ".Example_Test is"); - Put_Line ("begin"); - Put_Line (" Ada.Assertions.Assert (True);"); - Put_Line ("end " & Test_Upper & ".Example_Test;"); - TIO.Close (File); - - Test_Common.Make_Dir; - if not Create (+Full_Name (Test_Common / (+Test_Lower & ".ads"))) then - Trace.Warning ("Could not create tests package in 'tests/common'"); - return; + ------------------------- + -- Generate_Test_Crate -- + ------------------------- + + procedure Generate_Test_Crate is + begin + if Info.With_Test then + Templates.Translate_Tree + (Test_Directory, + Templates.Builtins.Crate_Test, + Templates.Builtins.Init_Crate_Translation (Info)); end if; - Put_Line ("package " & Test_Upper & " is"); - Put_Line ("end " & Test_Upper & ";"); - TIO.Close (File); end Generate_Test_Crate; begin - -- Crate dir - Directory.Make_Dir; - if not Cmd.No_Skel then - Generate_Project_File; - Src_Directory.Make_Dir; - Share_Directory.Make_Dir; - if For_Library then - Generate_Root_Package; - else - Generate_Program_Main; - end if; - Generate_Gitignore; + if Cmd.No_Skel then + Generate_Manifest; + else + Generate_Main_Crate; end if; - Generate_Manifest; - if not Cmd.No_Skel then Generate_Config; @@ -456,15 +117,17 @@ package body Alr.Commands.Init is end if; end if; - Alire.Put_Success (TTY.Emph (Lower_Name) & " initialized successfully."); + Alire.Put_Success (TTY.Emph (Name.As_String) + & " initialized successfully."); end Generate; ---------------------- -- Query_Crate_Name -- ---------------------- - procedure Query_Crate_Name (Args : AAA.Strings.Vector; - Info : in out Crate_Init_Info) + procedure Query_Crate_Name + (Args : AAA.Strings.Vector; + Info : in out Alire.Templates.Builtins.Crate_Init_Info) is begin case Args.Length is @@ -535,7 +198,8 @@ package body Alr.Commands.Init is -- Query_License -- ------------------- - procedure Query_License (Info : in out Crate_Init_Info) is + procedure Query_License (Info : in out Templates.Builtins.Crate_Init_Info) + is License_Other : constant String := "Other..."; License_Vect : constant AAA.Strings.Vector := @@ -612,7 +276,7 @@ package body Alr.Commands.Init is " you want to create:", Choices => Kinds); - Info.Kind := Crate_Kind'Value (Kinds (Answer)); + Info.Is_Library := Library = Crate_Kind'Value (Kinds (Answer)); end Query_Crate_Kind; ---------------------------- @@ -703,7 +367,7 @@ package body Alr.Commands.Init is Args : AAA.Strings.Vector) is use Alire.Settings; - Info : Crate_Init_Info; + Info : Alire.Templates.Builtins.Crate_Init_Info; User_Not_Already_Configured : constant Boolean := Builtins.User_Email.Is_Empty or else Builtins.User_Name.Is_Empty @@ -715,12 +379,14 @@ package body Alr.Commands.Init is Reportaise_Wrong_Arguments ("Please provide either --bin or --lib"); end if; + Info.With_Test := not (Cmd.No_Test or else Cmd.No_Skel); + Query_Crate_Name (Args, Info); if Cmd.Bin then - Info.Kind := Binary; + Info.Is_Library := False; elsif Cmd.Lib then - Info.Kind := Library; + Info.Is_Library := True; else Query_Crate_Kind (Info); end if; diff --git a/src/templates/r-crate_bin_alire_toml.ads b/src/templates/r-crate_bin_alire_toml.ads new file mode 100644 index 00000000..7115b393 --- /dev/null +++ b/src/templates/r-crate_bin_alire_toml.ads @@ -0,0 +1,43 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_bin_alire_toml is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (110, 97, 109, 101, 32, 61, 32, 34, 64, 95, 76, 79, 87, 69, + 82, 58, 78, 65, 77, 69, 95, 64, 34, 10, 100, 101, 115, 99, + 114, 105, 112, 116, 105, 111, 110, 32, 61, 32, 34, 64, 95, 68, + 69, 83, 67, 82, 73, 80, 84, 73, 79, 78, 95, 64, 34, 10, + 118, 101, 114, 115, 105, 111, 110, 32, 61, 32, 34, 48, 46, 49, + 46, 48, 45, 100, 101, 118, 34, 10, 10, 97, 117, 116, 104, 111, + 114, 115, 32, 61, 32, 91, 34, 64, 95, 85, 83, 69, 82, 78, + 65, 77, 69, 95, 64, 34, 93, 10, 109, 97, 105, 110, 116, 97, + 105, 110, 101, 114, 115, 32, 61, 32, 91, 34, 64, 95, 85, 83, + 69, 82, 78, 65, 77, 69, 95, 64, 32, 60, 64, 95, 69, 77, + 65, 73, 76, 95, 64, 62, 34, 93, 10, 64, 64, 73, 70, 64, + 64, 32, 64, 95, 76, 79, 71, 73, 78, 95, 64, 32, 47, 61, + 32, 34, 34, 10, 109, 97, 105, 110, 116, 97, 105, 110, 101, 114, + 115, 45, 108, 111, 103, 105, 110, 115, 32, 61, 32, 91, 34, 64, + 95, 76, 79, 71, 73, 78, 95, 64, 34, 93, 10, 64, 64, 69, + 78, 68, 95, 73, 70, 64, 64, 10, 108, 105, 99, 101, 110, 115, + 101, 115, 32, 61, 32, 34, 77, 73, 84, 32, 79, 82, 32, 65, + 112, 97, 99, 104, 101, 45, 50, 46, 48, 32, 87, 73, 84, 72, + 32, 76, 76, 86, 77, 45, 101, 120, 99, 101, 112, 116, 105, 111, + 110, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, 61, 32, 34, + 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, 34, 10, 116, + 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, 71, 83, 95, + 64, 93, 10, 10, 101, 120, 101, 99, 117, 116, 97, 98, 108, 101, + 115, 32, 61, 32, 91, 34, 64, 95, 76, 79, 87, 69, 82, 58, + 78, 65, 77, 69, 95, 64, 34, 93, 10, 64, 64, 73, 70, 64, + 64, 32, 64, 95, 87, 73, 84, 72, 95, 84, 69, 83, 84, 95, + 64, 10, 10, 91, 116, 101, 115, 116, 93, 10, 114, 117, 110, 110, + 101, 114, 32, 61, 32, 34, 97, 108, 105, 114, 101, 34, 10, 64, + 64, 69, 78, 68, 95, 73, 70, 64, 64, 10); + +end r.crate_bin_alire_toml; diff --git a/src/templates/r-crate_bin_name_gpr.ads b/src/templates/r-crate_bin_name_gpr.ads new file mode 100644 index 00000000..b9697c33 --- /dev/null +++ b/src/templates/r-crate_bin_name_gpr.ads @@ -0,0 +1,59 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_bin_name_gpr is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (119, 105, 116, 104, 32, 34, 99, 111, 110, 102, 105, 103, 47, 64, + 95, 78, 65, 77, 69, 95, 64, 95, 99, 111, 110, 102, 105, 103, + 46, 103, 112, 114, 34, 59, 10, 10, 112, 114, 111, 106, 101, 99, + 116, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, + 58, 78, 65, 77, 69, 95, 64, 32, 105, 115, 10, 10, 32, 32, + 32, 102, 111, 114, 32, 83, 111, 117, 114, 99, 101, 95, 68, 105, + 114, 115, 32, 117, 115, 101, 32, 40, 34, 115, 114, 99, 47, 34, + 44, 32, 34, 99, 111, 110, 102, 105, 103, 47, 34, 41, 59, 10, + 32, 32, 32, 102, 111, 114, 32, 79, 98, 106, 101, 99, 116, 95, + 68, 105, 114, 32, 117, 115, 101, 32, 34, 111, 98, 106, 47, 34, + 32, 38, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, + 69, 58, 78, 65, 77, 69, 95, 64, 95, 67, 111, 110, 102, 105, + 103, 46, 66, 117, 105, 108, 100, 95, 80, 114, 111, 102, 105, 108, + 101, 59, 10, 32, 32, 32, 102, 111, 114, 32, 67, 114, 101, 97, + 116, 101, 95, 77, 105, 115, 115, 105, 110, 103, 95, 68, 105, 114, + 115, 32, 117, 115, 101, 32, 34, 84, 114, 117, 101, 34, 59, 10, + 32, 32, 32, 102, 111, 114, 32, 69, 120, 101, 99, 95, 68, 105, + 114, 32, 117, 115, 101, 32, 34, 98, 105, 110, 34, 59, 10, 32, + 32, 32, 102, 111, 114, 32, 77, 97, 105, 110, 32, 117, 115, 101, + 32, 40, 34, 64, 95, 78, 65, 77, 69, 95, 64, 46, 97, 100, + 98, 34, 41, 59, 10, 10, 32, 32, 32, 112, 97, 99, 107, 97, + 103, 101, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 105, 115, + 10, 32, 32, 32, 32, 32, 32, 102, 111, 114, 32, 68, 101, 102, + 97, 117, 108, 116, 95, 83, 119, 105, 116, 99, 104, 101, 115, 32, + 40, 34, 65, 100, 97, 34, 41, 32, 117, 115, 101, 32, 64, 95, + 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, + 69, 95, 64, 95, 67, 111, 110, 102, 105, 103, 46, 65, 100, 97, + 95, 67, 111, 109, 112, 105, 108, 101, 114, 95, 83, 119, 105, 116, + 99, 104, 101, 115, 59, 10, 32, 32, 32, 101, 110, 100, 32, 67, + 111, 109, 112, 105, 108, 101, 114, 59, 10, 10, 32, 32, 32, 112, + 97, 99, 107, 97, 103, 101, 32, 66, 105, 110, 100, 101, 114, 32, + 105, 115, 10, 32, 32, 32, 32, 32, 32, 102, 111, 114, 32, 83, + 119, 105, 116, 99, 104, 101, 115, 32, 40, 34, 65, 100, 97, 34, + 41, 32, 117, 115, 101, 32, 40, 34, 45, 69, 115, 34, 41, 59, + 32, 45, 45, 32, 32, 83, 121, 109, 98, 111, 108, 105, 99, 32, + 116, 114, 97, 99, 101, 98, 97, 99, 107, 10, 32, 32, 32, 101, + 110, 100, 32, 66, 105, 110, 100, 101, 114, 59, 10, 10, 32, 32, + 32, 112, 97, 99, 107, 97, 103, 101, 32, 73, 110, 115, 116, 97, + 108, 108, 32, 105, 115, 10, 32, 32, 32, 32, 32, 32, 102, 111, + 114, 32, 65, 114, 116, 105, 102, 97, 99, 116, 115, 32, 40, 34, + 46, 34, 41, 32, 117, 115, 101, 32, 40, 34, 115, 104, 97, 114, + 101, 34, 41, 59, 10, 32, 32, 32, 101, 110, 100, 32, 73, 110, + 115, 116, 97, 108, 108, 59, 10, 10, 101, 110, 100, 32, 64, 95, + 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, + 69, 95, 64, 59, 10); + +end r.crate_bin_name_gpr; diff --git a/src/templates/r-crate_bin_src_name_adb.ads b/src/templates/r-crate_bin_src_name_adb.ads new file mode 100644 index 00000000..e21644a9 --- /dev/null +++ b/src/templates/r-crate_bin_src_name_adb.ads @@ -0,0 +1,20 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_bin_src_name_adb is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (112, 114, 111, 99, 101, 100, 117, 114, 101, 32, 64, 95, 67, 65, + 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, + 64, 32, 105, 115, 10, 98, 101, 103, 105, 110, 10, 32, 32, 32, + 110, 117, 108, 108, 59, 10, 101, 110, 100, 32, 64, 95, 67, 65, + 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, + 64, 59, 10); + +end r.crate_bin_src_name_adb; diff --git a/src/templates/r-crate_common_gitignore_hidden.ads b/src/templates/r-crate_common_gitignore_hidden.ads new file mode 100644 index 00000000..02569bd6 --- /dev/null +++ b/src/templates/r-crate_common_gitignore_hidden.ads @@ -0,0 +1,18 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_common_gitignore_hidden is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (47, 97, 108, 105, 114, 101, 47, 10, 47, 98, 105, 110, 47, 10, + 47, 99, 111, 110, 102, 105, 103, 47, 10, 47, 108, 105, 98, 47, + 10, 47, 111, 98, 106, 47, 10, 10, 42, 46, 97, 10, 42, 46, + 97, 108, 105, 10, 42, 46, 111, 10, 42, 46, 115, 111); + +end r.crate_common_gitignore_hidden; diff --git a/src/templates/r-crate_lib_alire_toml.ads b/src/templates/r-crate_lib_alire_toml.ads new file mode 100644 index 00000000..029865c1 --- /dev/null +++ b/src/templates/r-crate_lib_alire_toml.ads @@ -0,0 +1,41 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_lib_alire_toml is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (110, 97, 109, 101, 32, 61, 32, 34, 64, 95, 76, 79, 87, 69, + 82, 58, 78, 65, 77, 69, 95, 64, 34, 10, 100, 101, 115, 99, + 114, 105, 112, 116, 105, 111, 110, 32, 61, 32, 34, 64, 95, 68, + 69, 83, 67, 82, 73, 80, 84, 73, 79, 78, 95, 64, 34, 10, + 118, 101, 114, 115, 105, 111, 110, 32, 61, 32, 34, 48, 46, 49, + 46, 48, 45, 100, 101, 118, 34, 10, 10, 97, 117, 116, 104, 111, + 114, 115, 32, 61, 32, 91, 34, 64, 95, 85, 83, 69, 82, 78, + 65, 77, 69, 95, 64, 34, 93, 10, 109, 97, 105, 110, 116, 97, + 105, 110, 101, 114, 115, 32, 61, 32, 91, 34, 64, 95, 85, 83, + 69, 82, 78, 65, 77, 69, 95, 64, 32, 60, 64, 95, 69, 77, + 65, 73, 76, 95, 64, 62, 34, 93, 10, 64, 64, 73, 70, 64, + 64, 32, 64, 95, 76, 79, 71, 73, 78, 95, 64, 32, 47, 61, + 32, 34, 34, 10, 109, 97, 105, 110, 116, 97, 105, 110, 101, 114, + 115, 45, 108, 111, 103, 105, 110, 115, 32, 61, 32, 91, 34, 64, + 95, 76, 79, 71, 73, 78, 95, 64, 34, 93, 10, 64, 64, 69, + 78, 68, 95, 73, 70, 64, 64, 10, 108, 105, 99, 101, 110, 115, + 101, 115, 32, 61, 32, 34, 77, 73, 84, 32, 79, 82, 32, 65, + 112, 97, 99, 104, 101, 45, 50, 46, 48, 32, 87, 73, 84, 72, + 32, 76, 76, 86, 77, 45, 101, 120, 99, 101, 112, 116, 105, 111, + 110, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, 61, 32, 34, + 64, 95, 87, 69, 66, 83, 73, 84, 69, 95, 64, 34, 10, 116, + 97, 103, 115, 32, 61, 32, 91, 64, 95, 84, 65, 71, 83, 95, + 64, 93, 10, 64, 64, 73, 70, 64, 64, 32, 64, 95, 87, 73, + 84, 72, 95, 84, 69, 83, 84, 95, 64, 10, 10, 91, 116, 101, + 115, 116, 93, 10, 114, 117, 110, 110, 101, 114, 32, 61, 32, 34, + 97, 108, 105, 114, 101, 34, 10, 64, 64, 69, 78, 68, 95, 73, + 70, 64, 64, 10); + +end r.crate_lib_alire_toml; diff --git a/src/templates/r-crate_lib_name_gpr.ads b/src/templates/r-crate_lib_name_gpr.ads new file mode 100644 index 00000000..7517e2fd --- /dev/null +++ b/src/templates/r-crate_lib_name_gpr.ads @@ -0,0 +1,84 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_lib_name_gpr is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (119, 105, 116, 104, 32, 34, 99, 111, 110, 102, 105, 103, 47, 64, + 95, 78, 65, 77, 69, 95, 64, 95, 99, 111, 110, 102, 105, 103, + 46, 103, 112, 114, 34, 59, 10, 112, 114, 111, 106, 101, 99, 116, + 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, + 78, 65, 77, 69, 95, 64, 32, 105, 115, 10, 10, 32, 32, 32, + 102, 111, 114, 32, 76, 105, 98, 114, 97, 114, 121, 95, 78, 97, + 109, 101, 32, 117, 115, 101, 32, 34, 64, 95, 67, 65, 80, 73, + 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, 64, 34, + 59, 10, 32, 32, 32, 102, 111, 114, 32, 76, 105, 98, 114, 97, + 114, 121, 95, 86, 101, 114, 115, 105, 111, 110, 32, 117, 115, 101, + 10, 32, 32, 32, 32, 32, 80, 114, 111, 106, 101, 99, 116, 39, + 76, 105, 98, 114, 97, 114, 121, 95, 78, 97, 109, 101, 32, 38, + 32, 34, 46, 115, 111, 46, 34, 32, 38, 32, 64, 95, 67, 65, + 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, + 64, 95, 67, 111, 110, 102, 105, 103, 46, 67, 114, 97, 116, 101, + 95, 86, 101, 114, 115, 105, 111, 110, 59, 10, 10, 32, 32, 32, + 102, 111, 114, 32, 83, 111, 117, 114, 99, 101, 95, 68, 105, 114, + 115, 32, 117, 115, 101, 32, 40, 34, 115, 114, 99, 47, 34, 44, + 32, 34, 99, 111, 110, 102, 105, 103, 47, 34, 41, 59, 10, 32, + 32, 32, 102, 111, 114, 32, 79, 98, 106, 101, 99, 116, 95, 68, + 105, 114, 32, 117, 115, 101, 32, 34, 111, 98, 106, 47, 34, 32, + 38, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, + 58, 78, 65, 77, 69, 95, 64, 95, 67, 111, 110, 102, 105, 103, + 46, 66, 117, 105, 108, 100, 95, 80, 114, 111, 102, 105, 108, 101, + 59, 10, 32, 32, 32, 102, 111, 114, 32, 67, 114, 101, 97, 116, + 101, 95, 77, 105, 115, 115, 105, 110, 103, 95, 68, 105, 114, 115, + 32, 117, 115, 101, 32, 34, 84, 114, 117, 101, 34, 59, 10, 32, + 32, 32, 102, 111, 114, 32, 76, 105, 98, 114, 97, 114, 121, 95, + 68, 105, 114, 32, 117, 115, 101, 32, 34, 108, 105, 98, 34, 59, + 10, 10, 32, 32, 32, 116, 121, 112, 101, 32, 76, 105, 98, 114, + 97, 114, 121, 95, 84, 121, 112, 101, 95, 84, 121, 112, 101, 32, + 105, 115, 32, 40, 34, 114, 101, 108, 111, 99, 97, 116, 97, 98, + 108, 101, 34, 44, 32, 34, 115, 116, 97, 116, 105, 99, 34, 44, + 32, 34, 115, 116, 97, 116, 105, 99, 45, 112, 105, 99, 34, 41, + 59, 10, 32, 32, 32, 76, 105, 98, 114, 97, 114, 121, 95, 84, + 121, 112, 101, 32, 58, 32, 76, 105, 98, 114, 97, 114, 121, 95, + 84, 121, 112, 101, 95, 84, 121, 112, 101, 32, 58, 61, 10, 32, + 32, 32, 32, 32, 101, 120, 116, 101, 114, 110, 97, 108, 32, 40, + 34, 64, 95, 85, 80, 80, 69, 82, 58, 78, 65, 77, 69, 95, + 64, 95, 76, 73, 66, 82, 65, 82, 89, 95, 84, 89, 80, 69, + 34, 44, 32, 101, 120, 116, 101, 114, 110, 97, 108, 32, 40, 34, + 76, 73, 66, 82, 65, 82, 89, 95, 84, 89, 80, 69, 34, 44, + 32, 34, 115, 116, 97, 116, 105, 99, 34, 41, 41, 59, 10, 32, + 32, 32, 102, 111, 114, 32, 76, 105, 98, 114, 97, 114, 121, 95, + 75, 105, 110, 100, 32, 117, 115, 101, 32, 76, 105, 98, 114, 97, + 114, 121, 95, 84, 121, 112, 101, 59, 10, 10, 32, 32, 32, 112, + 97, 99, 107, 97, 103, 101, 32, 67, 111, 109, 112, 105, 108, 101, + 114, 32, 105, 115, 10, 32, 32, 32, 32, 32, 32, 102, 111, 114, + 32, 68, 101, 102, 97, 117, 108, 116, 95, 83, 119, 105, 116, 99, + 104, 101, 115, 32, 40, 34, 65, 100, 97, 34, 41, 32, 117, 115, + 101, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, + 58, 78, 65, 77, 69, 95, 64, 95, 67, 111, 110, 102, 105, 103, + 46, 65, 100, 97, 95, 67, 111, 109, 112, 105, 108, 101, 114, 95, + 83, 119, 105, 116, 99, 104, 101, 115, 59, 10, 32, 32, 32, 101, + 110, 100, 32, 67, 111, 109, 112, 105, 108, 101, 114, 59, 10, 10, + 32, 32, 32, 112, 97, 99, 107, 97, 103, 101, 32, 66, 105, 110, + 100, 101, 114, 32, 105, 115, 10, 32, 32, 32, 32, 32, 32, 102, + 111, 114, 32, 83, 119, 105, 116, 99, 104, 101, 115, 32, 40, 34, + 65, 100, 97, 34, 41, 32, 117, 115, 101, 32, 40, 34, 45, 69, + 115, 34, 41, 59, 32, 45, 45, 32, 32, 83, 121, 109, 98, 111, + 108, 105, 99, 32, 116, 114, 97, 99, 101, 98, 97, 99, 107, 10, + 32, 32, 32, 101, 110, 100, 32, 66, 105, 110, 100, 101, 114, 59, + 10, 10, 32, 32, 32, 112, 97, 99, 107, 97, 103, 101, 32, 73, + 110, 115, 116, 97, 108, 108, 32, 105, 115, 10, 32, 32, 32, 32, + 32, 32, 102, 111, 114, 32, 65, 114, 116, 105, 102, 97, 99, 116, + 115, 32, 40, 34, 46, 34, 41, 32, 117, 115, 101, 32, 40, 34, + 115, 104, 97, 114, 101, 34, 41, 59, 10, 32, 32, 32, 101, 110, + 100, 32, 73, 110, 115, 116, 97, 108, 108, 59, 10, 10, 101, 110, + 100, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, + 58, 78, 65, 77, 69, 95, 64, 59, 10); + +end r.crate_lib_name_gpr; diff --git a/src/templates/r-crate_lib_src_name_ads.ads b/src/templates/r-crate_lib_src_name_ads.ads new file mode 100644 index 00000000..947174e9 --- /dev/null +++ b/src/templates/r-crate_lib_src_name_ads.ads @@ -0,0 +1,19 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_lib_src_name_ads is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (112, 97, 99, 107, 97, 103, 101, 32, 64, 95, 67, 65, 80, 73, + 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, 64, 32, + 105, 115, 10, 10, 101, 110, 100, 32, 64, 95, 67, 65, 80, 73, + 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, 64, 59, + 10); + +end r.crate_lib_src_name_ads; diff --git a/src/templates/r-crate_test_tests_alire_toml.ads b/src/templates/r-crate_test_tests_alire_toml.ads new file mode 100644 index 00000000..8c91c8dd --- /dev/null +++ b/src/templates/r-crate_test_tests_alire_toml.ads @@ -0,0 +1,32 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_test_tests_alire_toml is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (110, 97, 109, 101, 32, 61, 32, 34, 64, 95, 78, 65, 77, 69, + 95, 64, 95, 116, 101, 115, 116, 115, 34, 10, 100, 101, 115, 99, + 114, 105, 112, 116, 105, 111, 110, 32, 61, 32, 34, 84, 101, 115, + 116, 115, 32, 102, 111, 114, 32, 116, 104, 101, 32, 98, 117, 105, + 108, 116, 45, 105, 110, 32, 65, 108, 105, 114, 101, 32, 116, 101, + 115, 116, 32, 114, 117, 110, 110, 101, 114, 34, 10, 118, 101, 114, + 115, 105, 111, 110, 32, 61, 32, 34, 48, 46, 48, 46, 48, 45, + 116, 101, 115, 116, 34, 10, 10, 91, 91, 100, 101, 112, 101, 110, + 100, 115, 45, 111, 110, 93, 93, 10, 64, 95, 78, 65, 77, 69, + 95, 64, 32, 61, 32, 34, 42, 34, 10, 10, 91, 91, 112, 105, + 110, 115, 93, 93, 10, 64, 95, 78, 65, 77, 69, 95, 64, 32, + 61, 32, 123, 32, 112, 97, 116, 104, 32, 61, 32, 34, 46, 46, + 34, 32, 125, 10, 10, 91, 98, 117, 105, 108, 100, 45, 112, 114, + 111, 102, 105, 108, 101, 115, 93, 10, 64, 95, 78, 65, 77, 69, + 95, 64, 32, 32, 32, 32, 32, 32, 32, 61, 32, 34, 118, 97, + 108, 105, 100, 97, 116, 105, 111, 110, 34, 10, 64, 95, 78, 65, + 77, 69, 95, 64, 95, 116, 101, 115, 116, 115, 32, 61, 32, 34, + 118, 97, 108, 105, 100, 97, 116, 105, 111, 110, 34, 10); + +end r.crate_test_tests_alire_toml; diff --git a/src/templates/r-crate_test_tests_common_name_tests_ads.ads b/src/templates/r-crate_test_tests_common_name_tests_ads.ads new file mode 100644 index 00000000..c30f2d23 --- /dev/null +++ b/src/templates/r-crate_test_tests_common_name_tests_ads.ads @@ -0,0 +1,19 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_test_tests_common_name_tests_ads is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (112, 97, 99, 107, 97, 103, 101, 32, 64, 95, 67, 65, 80, 73, + 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, 64, 95, + 84, 101, 115, 116, 115, 32, 105, 115, 10, 10, 101, 110, 100, 32, + 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, + 65, 77, 69, 95, 64, 95, 84, 101, 115, 116, 115, 59, 10); + +end r.crate_test_tests_common_name_tests_ads; diff --git a/src/templates/r-crate_test_tests_crate_test_tests_gpr.ads b/src/templates/r-crate_test_tests_crate_test_tests_gpr.ads new file mode 100644 index 00000000..e18f9ff8 --- /dev/null +++ b/src/templates/r-crate_test_tests_crate_test_tests_gpr.ads @@ -0,0 +1,62 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_test_tests_crate_test_tests_gpr is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (119, 105, 116, 104, 32, 34, 99, 111, 110, 102, 105, 103, 47, 64, + 95, 78, 65, 77, 69, 95, 64, 95, 116, 101, 115, 116, 115, 95, + 99, 111, 110, 102, 105, 103, 46, 103, 112, 114, 34, 59, 10, 119, + 105, 116, 104, 32, 34, 99, 111, 110, 102, 105, 103, 47, 64, 95, + 78, 65, 77, 69, 95, 64, 95, 116, 101, 115, 116, 115, 95, 108, + 105, 115, 116, 95, 99, 111, 110, 102, 105, 103, 46, 103, 112, 114, + 34, 59, 10, 10, 112, 114, 111, 106, 101, 99, 116, 32, 64, 95, + 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, + 69, 95, 64, 95, 84, 101, 115, 116, 115, 32, 105, 115, 10, 32, + 32, 32, 102, 111, 114, 32, 83, 111, 117, 114, 99, 101, 95, 68, + 105, 114, 115, 32, 117, 115, 101, 32, 40, 34, 115, 114, 99, 47, + 42, 42, 34, 44, 32, 34, 99, 111, 109, 109, 111, 110, 47, 34, + 44, 32, 34, 99, 111, 110, 102, 105, 103, 47, 34, 41, 59, 10, + 32, 32, 32, 102, 111, 114, 32, 79, 98, 106, 101, 99, 116, 95, + 68, 105, 114, 32, 117, 115, 101, 32, 34, 111, 98, 106, 47, 34, + 32, 38, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, + 69, 58, 78, 65, 77, 69, 95, 64, 95, 84, 101, 115, 116, 115, + 95, 67, 111, 110, 102, 105, 103, 46, 66, 117, 105, 108, 100, 95, + 80, 114, 111, 102, 105, 108, 101, 59, 10, 32, 32, 32, 102, 111, + 114, 32, 67, 114, 101, 97, 116, 101, 95, 77, 105, 115, 115, 105, + 110, 103, 95, 68, 105, 114, 115, 32, 117, 115, 101, 32, 34, 84, + 114, 117, 101, 34, 59, 10, 32, 32, 32, 102, 111, 114, 32, 69, + 120, 101, 99, 95, 68, 105, 114, 32, 117, 115, 101, 32, 34, 98, + 105, 110, 34, 59, 10, 32, 32, 32, 102, 111, 114, 32, 77, 97, + 105, 110, 32, 117, 115, 101, 32, 64, 95, 67, 65, 80, 73, 84, + 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, 64, 95, 84, + 101, 115, 116, 115, 95, 76, 105, 115, 116, 95, 67, 111, 110, 102, + 105, 103, 46, 84, 101, 115, 116, 95, 70, 105, 108, 101, 115, 59, + 10, 10, 32, 32, 32, 112, 97, 99, 107, 97, 103, 101, 32, 67, + 111, 109, 112, 105, 108, 101, 114, 32, 105, 115, 10, 32, 32, 32, + 32, 32, 32, 102, 111, 114, 32, 68, 101, 102, 97, 117, 108, 116, + 95, 83, 119, 105, 116, 99, 104, 101, 115, 32, 40, 34, 65, 100, + 97, 34, 41, 32, 117, 115, 101, 10, 32, 32, 32, 32, 32, 32, + 32, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, 90, 69, + 58, 78, 65, 77, 69, 95, 64, 95, 84, 101, 115, 116, 115, 95, + 67, 111, 110, 102, 105, 103, 46, 65, 100, 97, 95, 67, 111, 109, + 112, 105, 108, 101, 114, 95, 83, 119, 105, 116, 99, 104, 101, 115, + 59, 10, 32, 32, 32, 101, 110, 100, 32, 67, 111, 109, 112, 105, + 108, 101, 114, 59, 10, 10, 32, 32, 32, 112, 97, 99, 107, 97, + 103, 101, 32, 66, 105, 110, 100, 101, 114, 32, 105, 115, 10, 32, + 32, 32, 32, 32, 32, 102, 111, 114, 32, 83, 119, 105, 116, 99, + 104, 101, 115, 32, 40, 34, 65, 100, 97, 34, 41, 32, 117, 115, + 101, 32, 40, 34, 45, 69, 115, 34, 41, 59, 32, 45, 45, 32, + 32, 83, 121, 109, 98, 111, 108, 105, 99, 32, 116, 114, 97, 99, + 101, 98, 97, 99, 107, 10, 32, 32, 32, 101, 110, 100, 32, 66, + 105, 110, 100, 101, 114, 59, 10, 101, 110, 100, 32, 64, 95, 67, + 65, 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, + 95, 64, 95, 84, 101, 115, 116, 115, 59, 10); + +end r.crate_test_tests_crate_test_tests_gpr; diff --git a/src/templates/r-crate_test_tests_src_name_testsxexample_test_adb.ads b/src/templates/r-crate_test_tests_src_name_testsxexample_test_adb.ads new file mode 100644 index 00000000..24c9d347 --- /dev/null +++ b/src/templates/r-crate_test_tests_src_name_testsxexample_test_adb.ads @@ -0,0 +1,30 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with Ada.Streams; + +package r.crate_test_tests_src_name_testsxexample_test_adb is + + use Ada.Streams; + + Content : aliased constant Stream_Element_Array := + (119, 105, 116, 104, 32, 65, 100, 97, 46, 65, 115, 115, 101, 114, + 116, 105, 111, 110, 115, 59, 10, 10, 112, 114, 111, 99, 101, 100, + 117, 114, 101, 32, 64, 95, 67, 65, 80, 73, 84, 65, 76, 73, + 90, 69, 58, 78, 65, 77, 69, 95, 64, 95, 84, 101, 115, 116, + 115, 46, 69, 120, 97, 109, 112, 108, 101, 95, 84, 101, 115, 116, + 32, 105, 115, 10, 98, 101, 103, 105, 110, 10, 32, 32, 32, 65, + 100, 97, 46, 65, 115, 115, 101, 114, 116, 105, 111, 110, 115, 46, + 65, 115, 115, 101, 114, 116, 32, 40, 84, 114, 117, 101, 41, 59, + 10, 32, 32, 32, 45, 45, 32, 32, 69, 120, 105, 116, 32, 119, + 105, 116, 104, 32, 99, 111, 100, 101, 32, 47, 61, 32, 48, 32, + 111, 114, 32, 114, 97, 105, 115, 101, 32, 101, 120, 99, 101, 112, + 116, 105, 111, 110, 32, 116, 111, 32, 102, 97, 105, 108, 32, 97, + 32, 116, 101, 115, 116, 10, 101, 110, 100, 32, 64, 95, 67, 65, + 80, 73, 84, 65, 76, 73, 90, 69, 58, 78, 65, 77, 69, 95, + 64, 95, 84, 101, 115, 116, 115, 46, 69, 120, 97, 109, 112, 108, + 101, 95, 84, 101, 115, 116, 59, 10); + +end r.crate_test_tests_src_name_testsxexample_test_adb; diff --git a/src/templates/r.adb b/src/templates/r.adb new file mode 100644 index 00000000..e76e725d --- /dev/null +++ b/src/templates/r.adb @@ -0,0 +1,80 @@ +pragma Warnings (Off); + +-- Generated by awsres from /support/embedder/embedder.sh + +pragma Style_Checks (Off); + +with r.crate_bin_alire_toml; +with r.crate_bin_name_gpr; +with r.crate_bin_src_name_adb; +with r.crate_common_gitignore_hidden; +with r.crate_lib_alire_toml; +with r.crate_lib_name_gpr; +with r.crate_lib_src_name_ads; +with r.crate_test_tests_common_name_tests_ads; +with r.crate_test_tests_alire_toml; +with r.crate_test_tests_crate_test_tests_gpr; +with r.crate_test_tests_src_name_testsxexample_test_adb; + +with Alire.Templates; +with GNAT.Calendar; + +package body r is + + Initialized : Boolean := False; + + procedure Init is + use Alire.Templates; + begin + if not Initialized then + Initialized := True; + Register + ("crate_bin/alire.toml", + r.crate_bin_alire_toml.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_bin/name.gpr", + r.crate_bin_name_gpr.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_bin/src/name.adb", + r.crate_bin_src_name_adb.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_common/gitignore.hidden", + r.crate_common_gitignore_hidden.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_lib/alire.toml", + r.crate_lib_alire_toml.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_lib/name.gpr", + r.crate_lib_name_gpr.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_lib/src/name.ads", + r.crate_lib_src_name_ads.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 19, 0.0)); + Register + ("crate_test/tests/common/name_tests.ads", + r.crate_test_tests_common_name_tests_ads.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 36, 0.0)); + Register + ("crate_test/tests/alire.toml", + r.crate_test_tests_alire_toml.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 53, 26, 0.0)); + Register + ("crate_test/tests/crate_test_tests.gpr", + r.crate_test_tests_crate_test_tests_gpr.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 36, 0.0)); + Register + ("crate_test/tests/src/name_tests-example_test.adb", + r.crate_test_tests_src_name_testsxexample_test_adb.Content'Access, + GNAT.Calendar.Time_Of (2025, 03, 23, 12, 22, 36, 0.0)); + end if; + end Init; + +begin + Init; +end r; diff --git a/src/templates/r.ads b/src/templates/r.ads new file mode 100644 index 00000000..c7715587 --- /dev/null +++ b/src/templates/r.ads @@ -0,0 +1,9 @@ + +-- Generated by awsres from /support/embedder/embedder.sh + +package r is + + procedure Init; + -- Register all resources files + +end r; diff --git a/support/embedder/.gitignore b/support/embedder/.gitignore new file mode 100644 index 00000000..04f964ca --- /dev/null +++ b/support/embedder/.gitignore @@ -0,0 +1 @@ +awsres diff --git a/support/embedder/embedder.sh b/support/embedder/embedder.sh new file mode 100755 index 00000000..b56f080f --- /dev/null +++ b/support/embedder/embedder.sh @@ -0,0 +1,122 @@ +#!/usr/bin/bash + +# Harden the script + +trap 'cd "$startdir"' EXIT +trap 'echo "ERROR at line ${LINENO} (code: $?)" >&2' ERR +trap 'echo "Interrupted" >&2 ; exit 1' INT + +set -o errexit +set -o nounset + +# Function that recursively hashes a directory and prints the hash +function hashdir() { + local dir="$1" # Directory to hash + find "$dir" -type f -exec sha256sum {} + | cut -d' ' -f1 | sort | sha256sum | cut -d' ' -f1 +} + +# Start by entering the directory of the script +startdir=$PWD +pushd "$(dirname "$0")" +scriptdir=$PWD + +# Identify the base dir of the project +base=$(git rev-parse --show-toplevel) + +# Check whether we need to regenerate, based on the hash of the templates +# stored in ./templates.hash + +old_hash=$(cat ./templates.hash 2>/dev/null || echo "missing") +new_hash=$(hashdir "$base/templates") +if [ "$old_hash" = "$new_hash" ]; then + echo "No changes in templates, skipping generation" + exit 0 +else + echo "Changes detected in templates, regenerating" + echo "Old hash: $old_hash" + echo "New hash: $new_hash" +fi + +# Location of generated files +generated=$base/src/templates + +# Build awsres from AWS only if awsres is not yet available here or in path + +if [ ! -f awsres ] && ! command -v awsres &> /dev/null; then + + echo "Building awsres from AWS..." + + workdir=$PWD + tmp=$(mktemp -d) + pushd "$tmp" + + alr get --build aws^24 + find . -name awsres -exec cp {} "$workdir" \; + + # Clean up + popd + rm -rf "$tmp" +fi + +# Actually generate the embedded resources + +export PATH+=":$PWD" + +# Clean up old resources +rm -rf $generated +mkdir -p $generated + +# AWSRes - Resource Creator v1.3 +# Usage : awsres [-hopqrRzu] file1/dir1 [-zu] [file2/dir2...] +# -a : packages are named after the actual filenames +# -o dir : specify the output directory +# -p str : prefix all resource names with the given string +# -R : activate recursivity +# -r name : name of the root package (default res) +# -z : enable compression of following resources +# -u : disable compression of following resources +# -q : quiet mode + +# We change momentarily into the templates folder to shorten generated filenames +# and avoid problems with ".." in paths that confuse awsres. +pushd "$base/templates" && \ +awsres \ + -a \ + -o $generated \ + -R \ + -r r \ + . && \ +popd + +# We use actual file names rather than hashes so changes in version control, and +# detecting missing resources, is easier. + +# Fix bad package names (two __ in a row) for some files (like .gitignore) +find $generated -type f -exec sed -i 's/__/_/g' {} \; + +# Likewise, but for file names +find $generated -type f -name '*__*' -exec \ + bash -c 'mv "$1" "${1//__/_}"' _ {} \; + +# Since we don't want to depend on superheavy AWS, we replace calls to it with +# our own registering procedure. +find $generated -type f -exec \ + sed -i 's/AWS\.Resources\.Embedded/Alire.Templates/g' {} \; + +# Silence warnings in generated registering code +sed -i '1s/^/pragma Warnings (Off);\n/' $generated/r.adb + +# Replace awsres-inserted timestamp of the kind +# -- AWSRes v1.3 - Generated on ... +# with a more generic one that doesn't insert a timestamp, so unchanged +# resources don't pollute our commits (we can always track changes in git). +find $generated -type f -exec \ + sed -i 's/-- AWSRes v1.3 - Generated on .*/-- Generated by awsres from \/support\/embedder\/embedder.sh/g' {} + + +# GENERATION DONE + +# Write hash after successful generation +echo "$new_hash" > "$scriptdir"/templates.hash +echo "Templates hash updated in $scriptdir/templates.hash with value $new_hash" + +echo "Resources created successfully" \ No newline at end of file diff --git a/support/embedder/templates.hash b/support/embedder/templates.hash new file mode 100644 index 00000000..93037fcd --- /dev/null +++ b/support/embedder/templates.hash @@ -0,0 +1 @@ +bd09b5bb86786de540ea1abb442a642c0f9b363321c3c40b40a4b86a6d94cd27 diff --git a/templates/crate_bin/alire.toml b/templates/crate_bin/alire.toml new file mode 100644 index 00000000..0efd1f29 --- /dev/null +++ b/templates/crate_bin/alire.toml @@ -0,0 +1,19 @@ +name = "@_LOWER:NAME_@" +description = "@_DESCRIPTION_@" +version = "0.1.0-dev" + +authors = ["@_USERNAME_@"] +maintainers = ["@_USERNAME_@ <@_EMAIL_@>"] +@@IF@@ @_LOGIN_@ /= "" +maintainers-logins = ["@_LOGIN_@"] +@@END_IF@@ +licenses = "MIT OR Apache-2.0 WITH LLVM-exception" +website = "@_WEBSITE_@" +tags = [@_TAGS_@] + +executables = ["@_LOWER:NAME_@"] +@@IF@@ @_WITH_TEST_@ + +[test] +runner = "alire" +@@END_IF@@ diff --git a/templates/crate_bin/name.gpr b/templates/crate_bin/name.gpr new file mode 100644 index 00000000..041bfe1e --- /dev/null +++ b/templates/crate_bin/name.gpr @@ -0,0 +1,23 @@ +with "config/@_NAME_@_config.gpr"; + +project @_CAPITALIZE:NAME_@ is + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & @_CAPITALIZE:NAME_@_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Exec_Dir use "bin"; + for Main use ("@_NAME_@.adb"); + + package Compiler is + for Default_Switches ("Ada") use @_CAPITALIZE:NAME_@_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 @_CAPITALIZE:NAME_@; diff --git a/templates/crate_bin/src/name.adb b/templates/crate_bin/src/name.adb new file mode 100644 index 00000000..33652219 --- /dev/null +++ b/templates/crate_bin/src/name.adb @@ -0,0 +1,4 @@ +procedure @_CAPITALIZE:NAME_@ is +begin + null; +end @_CAPITALIZE:NAME_@; diff --git a/templates/crate_common/gitignore.hidden b/templates/crate_common/gitignore.hidden new file mode 100644 index 00000000..ac5f821e --- /dev/null +++ b/templates/crate_common/gitignore.hidden @@ -0,0 +1,10 @@ +/alire/ +/bin/ +/config/ +/lib/ +/obj/ + +*.a +*.ali +*.o +*.so \ No newline at end of file diff --git a/templates/crate_lib/alire.toml b/templates/crate_lib/alire.toml new file mode 100644 index 00000000..0b028d8d --- /dev/null +++ b/templates/crate_lib/alire.toml @@ -0,0 +1,17 @@ +name = "@_LOWER:NAME_@" +description = "@_DESCRIPTION_@" +version = "0.1.0-dev" + +authors = ["@_USERNAME_@"] +maintainers = ["@_USERNAME_@ <@_EMAIL_@>"] +@@IF@@ @_LOGIN_@ /= "" +maintainers-logins = ["@_LOGIN_@"] +@@END_IF@@ +licenses = "MIT OR Apache-2.0 WITH LLVM-exception" +website = "@_WEBSITE_@" +tags = [@_TAGS_@] +@@IF@@ @_WITH_TEST_@ + +[test] +runner = "alire" +@@END_IF@@ diff --git a/templates/crate_lib/name.gpr b/templates/crate_lib/name.gpr new file mode 100644 index 00000000..73ac23ec --- /dev/null +++ b/templates/crate_lib/name.gpr @@ -0,0 +1,30 @@ +with "config/@_NAME_@_config.gpr"; +project @_CAPITALIZE:NAME_@ is + + for Library_Name use "@_CAPITALIZE:NAME_@"; + for Library_Version use + Project'Library_Name & ".so." & @_CAPITALIZE:NAME_@_Config.Crate_Version; + + for Source_Dirs use ("src/", "config/"); + for Object_Dir use "obj/" & @_CAPITALIZE:NAME_@_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Library_Dir use "lib"; + + type Library_Type_Type is ("relocatable", "static", "static-pic"); + Library_Type : Library_Type_Type := + external ("@_UPPER:NAME_@_LIBRARY_TYPE", external ("LIBRARY_TYPE", "static")); + for Library_Kind use Library_Type; + + package Compiler is + for Default_Switches ("Ada") use @_CAPITALIZE:NAME_@_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 @_CAPITALIZE:NAME_@; diff --git a/templates/crate_lib/src/name.ads b/templates/crate_lib/src/name.ads new file mode 100644 index 00000000..e6906406 --- /dev/null +++ b/templates/crate_lib/src/name.ads @@ -0,0 +1,3 @@ +package @_CAPITALIZE:NAME_@ is + +end @_CAPITALIZE:NAME_@; diff --git a/templates/crate_test/tests/alire.toml b/templates/crate_test/tests/alire.toml new file mode 100644 index 00000000..f045cdf5 --- /dev/null +++ b/templates/crate_test/tests/alire.toml @@ -0,0 +1,13 @@ +name = "@_NAME_@_tests" +description = "Tests for the built-in Alire test runner" +version = "0.0.0-test" + +[[depends-on]] +@_NAME_@ = "*" + +[[pins]] +@_NAME_@ = { path = ".." } + +[build-profiles] +@_NAME_@ = "validation" +@_NAME_@_tests = "validation" diff --git a/templates/crate_test/tests/common/name_tests.ads b/templates/crate_test/tests/common/name_tests.ads new file mode 100644 index 00000000..32042840 --- /dev/null +++ b/templates/crate_test/tests/common/name_tests.ads @@ -0,0 +1,3 @@ +package @_CAPITALIZE:NAME_@_Tests is + +end @_CAPITALIZE:NAME_@_Tests; diff --git a/templates/crate_test/tests/crate_test_tests.gpr b/templates/crate_test/tests/crate_test_tests.gpr new file mode 100644 index 00000000..2234cf81 --- /dev/null +++ b/templates/crate_test/tests/crate_test_tests.gpr @@ -0,0 +1,19 @@ +with "config/@_NAME_@_tests_config.gpr"; +with "config/@_NAME_@_tests_list_config.gpr"; + +project @_CAPITALIZE:NAME_@_Tests is + for Source_Dirs use ("src/**", "common/", "config/"); + for Object_Dir use "obj/" & @_CAPITALIZE:NAME_@_Tests_Config.Build_Profile; + for Create_Missing_Dirs use "True"; + for Exec_Dir use "bin"; + for Main use @_CAPITALIZE:NAME_@_Tests_List_Config.Test_Files; + + package Compiler is + for Default_Switches ("Ada") use + @_CAPITALIZE:NAME_@_Tests_Config.Ada_Compiler_Switches; + end Compiler; + + package Binder is + for Switches ("Ada") use ("-Es"); -- Symbolic traceback + end Binder; +end @_CAPITALIZE:NAME_@_Tests; diff --git a/templates/crate_test/tests/src/name_tests-example_test.adb b/templates/crate_test/tests/src/name_tests-example_test.adb new file mode 100644 index 00000000..78ac5f4b --- /dev/null +++ b/templates/crate_test/tests/src/name_tests-example_test.adb @@ -0,0 +1,7 @@ +with Ada.Assertions; + +procedure @_CAPITALIZE:NAME_@_Tests.Example_Test is +begin + Ada.Assertions.Assert (True); + -- Exit with code /= 0 or raise exception to fail a test +end @_CAPITALIZE:NAME_@_Tests.Example_Test; diff --git a/testsuite/tests/workflows/init-with-pin/test.py b/testsuite/tests/workflows/init-with-pin/test.py index 166071c3..276dfd07 100644 --- a/testsuite/tests/workflows/init-with-pin/test.py +++ b/testsuite/tests/workflows/init-with-pin/test.py @@ -4,14 +4,13 @@ Test a basic init-with-pin-run workflow. import os -from drivers.alr import run_alr, alr_pin +from drivers.alr import run_alr, alr_pin, init_local_crate from drivers.asserts import assert_eq from drivers.helpers import check_line_in # Create a new "xxx" program project -run_alr('init', '--bin', 'xxx') -os.chdir('xxx') +init_local_crate(binary=True) # Make it depend on libhello, it is auto-narrowed down to ^1 session_file = os.path.join('alire.toml') -- 2.39.5