Skip to content

Commit f0c573d

Browse files
committed
Write file with templating
1 parent 947d1db commit f0c573d

16 files changed

+150
-42
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@
6969
[submodule "deps/yeison"]
7070
path = deps/yeison
7171
url = https://github.com/mosteo/yeison
72+
[submodule "deps/templates-parser"]
73+
path = deps/templates-parser
74+
url = https://github.com/AdaCore/templates-parser
75+
[submodule "deps/xmlada"]
76+
path = deps/xmlada
77+
url = https://github.com/AdaCore/xmlada

TODO

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Put all GPR externals in alr_env.gpr in alire.toml

alire.gpr

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ with "simple_logging";
1717
with "si_units";
1818
with "spdx";
1919
with "stopwatch";
20+
with "templates_parser";
2021
with "toml_slicer";
2122
with "uri_ada";
2223
with "xml_ez_out";

alr_env.gpr

+23-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ aggregate project Alr_Env is
2828
"deps/simple_logging",
2929
"deps/spdx",
3030
"deps/stopwatch",
31+
"deps/templates-parser",
3132
"deps/toml_slicer",
3233
"deps/umwi",
3334
"deps/uri-ada",
35+
"deps/xmlada",
36+
"deps/xmlada/dom",
37+
"deps/xmlada/input_sources",
38+
"deps/xmlada/sax",
39+
"deps/xmlada/unicode",
3440
"deps/xmlezout",
3541
"deps/yeison/yeison_12"
3642
);
@@ -39,12 +45,24 @@ aggregate project Alr_Env is
3945

4046
-- Set environment variables for dependencies
4147

48+
for External ("XMLADA_BUILD_MODE") use "Production";
49+
4250
case Alire_Common.Host_Os is
43-
when "freebsd" => for External ("GNATCOLL_OS") use "unix";
44-
when "openbsd" => for External ("GNATCOLL_OS") use "unix";
45-
when "linux" => for External ("GNATCOLL_OS") use "unix";
46-
when "macos" => for External ("GNATCOLL_OS") use "osx";
47-
when "windows" => for External ("GNATCOLL_OS") use "windows";
51+
when "freebsd" =>
52+
for External ("GNATCOLL_OS") use "unix";
53+
for External ("PRJ_TARGET") use "FreeBSD"; -- used by templates_parser
54+
when "openbsd" =>
55+
for External ("GNATCOLL_OS") use "unix";
56+
for External ("PRJ_TARGET") use "UNIX";
57+
when "linux" =>
58+
for External ("GNATCOLL_OS") use "unix";
59+
for External ("PRJ_TARGET") use "Linux";
60+
when "macos" =>
61+
for External ("GNATCOLL_OS") use "osx";
62+
for External ("PRJ_TARGET") use "macOS";
63+
when "windows" =>
64+
for External ("GNATCOLL_OS") use "windows";
65+
for External ("PRJ_TARGET") use "Windows";
4866
end case;
4967

5068
for External ("LIBRARY_TYPE") use "static";

deps/templates-parser

Submodule templates-parser added at 645536c

deps/xmlada

Submodule xmlada added at 97bb055

src/alire/alire-templates.adb

+43
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
11
with Ada.Streams.Stream_IO;
2+
with Ada.Wide_Wide_Text_IO;
3+
4+
with LML;
25

36
package body Alire.Templates is
47

8+
---------------
9+
-- as_string --
10+
---------------
11+
12+
function As_String (Data : Embedded) return String is
13+
Fake_String : aliased String (1 .. Data'Length);
14+
for Fake_String'Address use Data (Data'First)'Address;
15+
begin
16+
return Fake_String;
17+
end As_String;
18+
19+
--------------------
20+
-- Translate_File --
21+
--------------------
22+
23+
procedure Translate_File (Src : Embedded;
24+
Dst : Relative_File;
25+
Map : Translations)
26+
is
27+
use Ada.Wide_Wide_Text_IO;
28+
File : File_Type;
29+
begin
30+
Create (File, Name => Dst);
31+
Put (File,
32+
LML.Decode
33+
(Templates_Parser.Translate
34+
(As_String (Src), Map.Set)));
35+
Close (File);
36+
exception
37+
when E : others =>
38+
Log_Exception (E);
39+
40+
if Is_Open (File) then
41+
Close (File);
42+
end if;
43+
44+
raise;
45+
end Translate_File;
46+
547
----------------
648
-- Write_File --
749
----------------
@@ -14,6 +56,7 @@ package body Alire.Templates is
1456
begin
1557
Create (File, Name => Dst);
1658
Write (File, Src.all);
59+
Close (File);
1760
exception
1861
when E : others =>
1962
Log_Exception (E);

src/alire/alire-templates.ads

+37
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
with Ada.Calendar;
22
with Ada.Streams;
33

4+
private with Templates_Parser;
5+
46
package Alire.Templates with Elaborate_Body is
57

68
type Embedded is access constant Ada.Streams.Stream_Element_Array;
79

10+
type Translations (<>) is tagged private;
11+
12+
function New_Translation return Translations;
13+
14+
function Append (This : Translations;
15+
Var : String;
16+
Val : String) return Translations;
17+
818
procedure Register (File : Relative_Path;
919
Data : Embedded;
1020
Stamp : Ada.Calendar.Time) is null;
@@ -13,4 +23,31 @@ package Alire.Templates with Elaborate_Body is
1323
Dst : Relative_File);
1424
-- Write an embedded file on disk. Does not perform any translations.
1525

26+
procedure Translate_File (Src : Embedded;
27+
Dst : Relative_File;
28+
Map : Translations);
29+
30+
private
31+
32+
type Translations is tagged record
33+
Set : Templates_Parser.Translate_Set;
34+
end record;
35+
36+
---------------------
37+
-- New_Translation --
38+
---------------------
39+
40+
function New_Translation return Translations
41+
is (Set => Templates_Parser.Null_Set);
42+
43+
----------
44+
-- This --
45+
----------
46+
47+
function Append (This : Translations;
48+
Var : String;
49+
Val : String) return Translations
50+
is (Set => Templates_Parser."&"
51+
(This.Set, Templates_Parser.Assoc (Var, Val)));
52+
1653
end Alire.Templates;

src/alr/alr-main.adb

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ with r.crate_bin_alire_toml;
1111

1212
procedure Alr.Main is
1313
begin
14-
Alire.Templates.Write_File (r.crate_bin_alire_toml.Content'Access,
15-
"/tmp/al.to");
14+
Alire.Templates.Translate_File
15+
(r.crate_bin_alire_toml.Content'Access,
16+
"/tmp/al.to",
17+
Alire.Templates.New_Translation
18+
.Append ("NAME", "mycrate")
19+
);
1620

1721
Trace.Debug ("alr platform configured");
1822

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
2+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
33

44
pragma Style_Checks (Off);
55

@@ -10,28 +10,27 @@ package r.crate_bin_alire_toml is
1010
use Ada.Streams;
1111

1212
Content : aliased constant Stream_Element_Array :=
13-
(110, 97, 109, 101, 32, 61, 32, 34, 99, 114, 97, 116, 101, 95,
14-
98, 105, 110, 34, 10, 100, 101, 115, 99, 114, 105, 112, 116, 105,
15-
111, 110, 32, 61, 32, 34, 34, 10, 118, 101, 114, 115, 105, 111,
16-
110, 32, 61, 32, 34, 48, 46, 49, 46, 48, 45, 100, 101, 118,
17-
34, 10, 10, 97, 117, 116, 104, 111, 114, 115, 32, 61, 32, 91,
18-
34, 65, 108, 101, 106, 97, 110, 100, 114, 111, 32, 82, 46, 32,
19-
77, 111, 115, 116, 101, 111, 34, 93, 10, 109, 97, 105, 110, 116,
20-
97, 105, 110, 101, 114, 115, 32, 61, 32, 91, 34, 65, 108, 101,
21-
106, 97, 110, 100, 114, 111, 32, 82, 46, 32, 77, 111, 115, 116,
22-
101, 111, 32, 60, 97, 108, 101, 106, 97, 110, 100, 114, 111, 64,
23-
109, 111, 115, 116, 101, 111, 46, 99, 111, 109, 62, 34, 93, 10,
24-
109, 97, 105, 110, 116, 97, 105, 110, 101, 114, 115, 45, 108, 111,
25-
103, 105, 110, 115, 32, 61, 32, 91, 34, 109, 111, 115, 116, 101,
26-
111, 34, 93, 10, 108, 105, 99, 101, 110, 115, 101, 115, 32, 61,
27-
32, 34, 77, 73, 84, 32, 79, 82, 32, 65, 112, 97, 99, 104,
28-
101, 45, 50, 46, 48, 32, 87, 73, 84, 72, 32, 76, 76, 86,
29-
77, 45, 101, 120, 99, 101, 112, 116, 105, 111, 110, 34, 10, 119,
30-
101, 98, 115, 105, 116, 101, 32, 61, 32, 34, 34, 10, 116, 97,
31-
103, 115, 32, 61, 32, 91, 93, 10, 10, 101, 120, 101, 99, 117,
32-
116, 97, 98, 108, 101, 115, 32, 61, 32, 91, 34, 99, 114, 97,
33-
116, 101, 95, 98, 105, 110, 34, 93, 10, 10, 91, 116, 101, 115,
34-
116, 93, 10, 114, 117, 110, 110, 101, 114, 32, 61, 32, 34, 97,
35-
108, 105, 114, 101, 34, 10);
13+
(110, 97, 109, 101, 32, 61, 32, 34, 64, 95, 76, 79, 87, 69,
14+
82, 58, 78, 65, 77, 69, 95, 64, 34, 10, 100, 101, 115, 99,
15+
114, 105, 112, 116, 105, 111, 110, 32, 61, 32, 34, 34, 10, 118,
16+
101, 114, 115, 105, 111, 110, 32, 61, 32, 34, 48, 46, 49, 46,
17+
48, 45, 100, 101, 118, 34, 10, 10, 97, 117, 116, 104, 111, 114,
18+
115, 32, 61, 32, 91, 34, 65, 108, 101, 106, 97, 110, 100, 114,
19+
111, 32, 82, 46, 32, 77, 111, 115, 116, 101, 111, 34, 93, 10,
20+
109, 97, 105, 110, 116, 97, 105, 110, 101, 114, 115, 32, 61, 32,
21+
91, 34, 65, 108, 101, 106, 97, 110, 100, 114, 111, 32, 82, 46,
22+
32, 77, 111, 115, 116, 101, 111, 32, 60, 97, 108, 101, 106, 97,
23+
110, 100, 114, 111, 64, 109, 111, 115, 116, 101, 111, 46, 99, 111,
24+
109, 62, 34, 93, 10, 109, 97, 105, 110, 116, 97, 105, 110, 101,
25+
114, 115, 45, 108, 111, 103, 105, 110, 115, 32, 61, 32, 91, 34,
26+
109, 111, 115, 116, 101, 111, 34, 93, 10, 108, 105, 99, 101, 110,
27+
115, 101, 115, 32, 61, 32, 34, 77, 73, 84, 32, 79, 82, 32,
28+
65, 112, 97, 99, 104, 101, 45, 50, 46, 48, 32, 87, 73, 84,
29+
72, 32, 76, 76, 86, 77, 45, 101, 120, 99, 101, 112, 116, 105,
30+
111, 110, 34, 10, 119, 101, 98, 115, 105, 116, 101, 32, 61, 32,
31+
34, 34, 10, 116, 97, 103, 115, 32, 61, 32, 91, 93, 10, 10,
32+
101, 120, 101, 99, 117, 116, 97, 98, 108, 101, 115, 32, 61, 32,
33+
91, 34, 64, 95, 76, 79, 87, 69, 82, 58, 78, 65, 77, 69,
34+
95, 64, 34, 93, 10);
3635

3736
end r.crate_bin_alire_toml;

src/templates/r-crate_bin_crate_bin_gpr.ads

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
2+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
33

44
pragma Style_Checks (Off);
55

src/templates/r-crate_bin_gitignore.ads

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
2+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
33

44
pragma Style_Checks (Off);
55

src/templates/r-crate_bin_src_crate_bin_adb.ads

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
2+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
33

44
pragma Style_Checks (Off);
55

src/templates/r.adb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pragma Warnings (Off);
22

3-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
3+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
44

55
pragma Style_Checks (Off);
66

@@ -36,7 +36,7 @@ package body r is
3636
Register
3737
("crate_bin/alire.toml",
3838
r.crate_bin_alire_toml.Content'Access,
39-
GNAT.Calendar.Time_Of (2025, 03, 09, 09, 27, 18, 0.0));
39+
GNAT.Calendar.Time_Of (2025, 03, 09, 20, 11, 29, 0.0));
4040
end if;
4141
end Init;
4242

src/templates/r.ads

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
-- AWSRes v1.3 - Generated on March 09 2025 at 20:09:52
2+
-- AWSRes v1.3 - Generated on March 09 2025 at 21:11:43
33

44
package r is
55

templates/crate_bin/alire.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "crate_bin"
1+
name = "@_LOWER:NAME_@"
22
description = ""
33
version = "0.1.0-dev"
44

@@ -9,7 +9,4 @@ licenses = "MIT OR Apache-2.0 WITH LLVM-exception"
99
website = ""
1010
tags = []
1111

12-
executables = ["crate_bin"]
13-
14-
[test]
15-
runner = "alire"
12+
executables = ["@_LOWER:NAME_@"]

0 commit comments

Comments
 (0)