Skip to content

Commit 57fa3fa

Browse files
committed
Handle include starting with ./ as relative to current directory.
A template file starting with ./ is now properly handled as relative to the server current working directory. Fixes a regression. Add corresponding regression test. For T305-015.
1 parent 897e519 commit 57fa3fa

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is header
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@@IF@@ @_FILE_EXISTS:HEAD_FILE1_@
2+
0:
3+
@@INCLUDE@@ @_HEAD_FILE1_@
4+
@@END_IF@@
5+
6+
1: @_HEAD_FILE1_@ - @_FILE_EXISTS:HEAD_FILE1_@
7+
@@INCLUDE@@ @_HEAD_FILE1_@
8+
9+
10+
2: @_HEAD_FILE2_@ - @_FILE_EXISTS:HEAD_FILE2_@
11+
@@INCLUDE@@ @_HEAD_FILE2_@
12+
13+
14+
3: @_HEAD_FILE3_@ - @_FILE_EXISTS:HEAD_FILE3_@
15+
@@INCLUDE@@ @_HEAD_FILE3_@
16+
17+
18+
4: @_HEAD_FILE4_@ - @_FILE_EXISTS:HEAD_FILE4_@
19+
@@INCLUDE@@ @_HEAD_FILE4_@
20+
21+
22+
DONE
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
------------------------------------------------------------------------------
2+
-- Templates Parser --
3+
-- --
4+
-- Copyright (C) 2020, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it --
7+
-- under terms of the GNU General Public License as published by the --
8+
-- Free Software Foundation; either version 3, or (at your option) any --
9+
-- later version. This software is distributed in the hope that it will --
10+
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
11+
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
12+
-- General Public License for more details. --
13+
-- --
14+
-- You should have received a copy of the GNU General Public License --
15+
-- distributed with this software; see file COPYING3. If not, go --
16+
-- to http://www.gnu.org/licenses for a complete copy of the license. --
17+
------------------------------------------------------------------------------
18+
19+
with Ada.Strings.Unbounded;
20+
with Ada.Text_IO;
21+
22+
with Templates_Parser;
23+
24+
procedure Ii is
25+
26+
use Ada;
27+
use Ada.Strings.Unbounded;
28+
use Templates_Parser;
29+
30+
R : Unbounded_String;
31+
V : Vector_Tag;
32+
T : Translate_Table (1 .. 4);
33+
34+
begin
35+
T (1) := Assoc ("HEAD_FILE1", "/content/header.tmplt");
36+
T (2) := Assoc ("HEAD_FILE2", "header.tmplt");
37+
T (3) := Assoc ("HEAD_FILE3", "../content/header.tmplt");
38+
T (4) := Assoc ("HEAD_FILE4", "./content/header.tmplt");
39+
R := Parse ("content/ii.tmplt", T);
40+
41+
Text_IO.Put_Line (To_String (R));
42+
end Ii;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
------------------------------------------------------------------------------
2+
-- Templates Parser --
3+
-- --
4+
-- Copyright (C) 2020, AdaCore --
5+
-- --
6+
-- This is free software; you can redistribute it and/or modify it --
7+
-- under terms of the GNU General Public License as published by the --
8+
-- Free Software Foundation; either version 3, or (at your option) any --
9+
-- later version. This software is distributed in the hope that it will --
10+
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty --
11+
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
12+
-- General Public License for more details. --
13+
-- --
14+
-- You should have received a copy of the GNU General Public License --
15+
-- distributed with this software; see file COPYING3. If not, go --
16+
-- to http://www.gnu.org/licenses for a complete copy of the license. --
17+
------------------------------------------------------------------------------
18+
19+
with "templates_parser";
20+
21+
project Ii is
22+
23+
for Source_Dirs use (".");
24+
for Main use ("ii.adb");
25+
26+
end Ii;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
1: /content/header.tmplt - FALSE
3+
This is header
4+
5+
2: header.tmplt - FALSE
6+
This is header
7+
8+
3: ../content/header.tmplt - FALSE
9+
This is header
10+
11+
4: ./content/header.tmplt - TRUE
12+
This is header
13+
14+
DONE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from test_support import *
2+
3+
gprbuild('ii')
4+
run('ii')

src/templates_parser.adb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- Templates Parser --
33
-- --
4-
-- Copyright (C) 1999-2019, AdaCore --
4+
-- Copyright (C) 1999-2020, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify --
77
-- it under terms of the GNU General Public License as published by the --
@@ -1520,6 +1520,13 @@ package body Templates_Parser is
15201520
return Include_Filename
15211521
(Include_Filename'First + 1 .. Include_Filename'Last);
15221522

1523+
elsif Include_Filename'Length > 2
1524+
and then Include_Filename (Include_Filename'First) = '.'
1525+
and then Maps.Is_In
1526+
(Include_Filename (Include_Filename'First + 1), Dir_Seps)
1527+
then
1528+
return Include_Filename;
1529+
15231530
else
15241531
declare
15251532
K : constant Natural :=

0 commit comments

Comments
 (0)