Skip to content

Commit 5ae4b4f

Browse files
committed
Merge branch 'topic/vadim/image' into 'master'
Report error when image directory is parent of output directory Closes #139 and #140 See merge request eng/ide/gnatdoc!200
2 parents 178ef72 + adeda27 commit 5ae4b4f

File tree

9 files changed

+62
-6
lines changed

9 files changed

+62
-6
lines changed

source/backend/gnatdoc-backend-html.adb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ with GNATCOLL.VFS;
2323
with Input_Sources.File;
2424

2525
with VSS.HTML.Writers;
26+
with VSS.Strings.Formatters.Virtual_Files;
2627
with VSS.Strings.Conversions;
28+
with VSS.Strings.Templates;
2729
with VSS.String_Vectors;
2830
with VSS.XML.Templates.Processors;
2931
with VSS.XML.Templates.Proxies.Booleans;
3032
with VSS.XML.XmlAda_Readers;
3133

3234
with GNATdoc.Entities.Proxies;
35+
with GNATdoc.Messages;
3336
with Streams;
3437

3538
package body GNATdoc.Backend.HTML is
@@ -419,7 +422,19 @@ package body GNATdoc.Backend.HTML is
419422
Images_Dir.Make_Dir;
420423

421424
for Directory of reverse Self.Image_Directories loop
422-
Directory.Copy (Images_Dir.Full_Name.all, Success);
425+
if GNATCOLL.VFS.Greatest_Common_Path
426+
([Self.Output_Root, Directory]) = Directory
427+
then
428+
GNATdoc.Messages.Report_Warning
429+
(VSS.Strings.Templates.To_Virtual_String_Template
430+
("image directory `{:fullname}` can't be parent of"
431+
& " output directory").Format
432+
(VSS.Strings.Formatters.Virtual_Files.Image
433+
(Directory)));
434+
435+
else
436+
Directory.Copy (Images_Dir.Full_Name.all, Success);
437+
end if;
423438
end loop;
424439
end;
425440
end if;

source/gnatdoc/gnatdoc-projects.adb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ package body GNATdoc.Projects is
206206

207207
if Directory.Is_Directory then
208208
Result.Append (Directory);
209+
210+
else
211+
GNATdoc.Messages.Report_Warning
212+
(VSS.Strings.Templates.Virtual_String_Template'
213+
("`{:fullname}` is not a directory").Format
214+
(VSS.Strings.Formatters.Virtual_Files.Image
215+
(Directory)));
209216
end if;
210217
end loop;
211218
end;

source/vss-strings-formatters-virtual_files.adb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------------
22
-- GNAT Documentation Generation Tool --
33
-- --
4-
-- Copyright (C) 2024, AdaCore --
4+
-- Copyright (C) 2024-2025, AdaCore --
55
-- --
66
-- This is free software; you can redistribute it and/or modify it under --
77
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -28,9 +28,19 @@ package body VSS.Strings.Formatters.Virtual_Files is
2828
Format : VSS.Strings.Formatters.Format_Information)
2929
return VSS.Strings.Virtual_String is
3030
begin
31-
return
32-
VSS.Strings.Conversions.To_Virtual_String
33-
(Self.Value.Display_Base_Name);
31+
if Format.Format.Is_Empty or Format.Format = "basename" then
32+
return
33+
VSS.Strings.Conversions.To_Virtual_String
34+
(Self.Value.Display_Base_Name);
35+
36+
elsif Format.Format = "fullname" then
37+
return
38+
VSS.Strings.Conversions.To_Virtual_String
39+
(Self.Value.Display_Full_Name);
40+
41+
else
42+
raise Program_Error;
43+
end if;
3444
end Format;
3545

3646
-----------
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
project Default is
3+
4+
package Documentation is
5+
for Image_Dirs ("html") use (".", "images");
6+
end Documentation;
7+
8+
end Default;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
package P is
3+
4+
end P;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
warning: `<<WORKING_DIR>>/images` is not a directory
2+
warning: image directory `<<WORKING_DIR>>/./` can't be parent of output directory
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$GNATDOC4 default.gpr
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: Check that message is reported when image directory is parent of output directory
2+
driver: executable

testsuite/testsuite.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from os import environ
44
from os.path import abspath, dirname, join
55
import sys
6+
from typing import List
67

78
from e3.testsuite import Testsuite
8-
from e3.testsuite.driver.diff import DiffTestDriver
9+
from e3.testsuite.driver.diff import DiffTestDriver, OutputRefiner, ReplacePath
910

1011

1112
class LibGNATdocExtractorDriver(DiffTestDriver):
@@ -49,6 +50,12 @@ def run(self):
4950

5051
self.shell(args=["bash", script_path], env=self.test_environ)
5152

53+
@property
54+
def output_refiners(self) -> List[OutputRefiner]:
55+
return super(GNATdocExecutableDriver, self).output_refiners + [
56+
ReplacePath(self.working_dir(), "<<WORKING_DIR>>")
57+
]
58+
5259

5360
class LibGNATdocTestsuite(Testsuite):
5461
"""Testsuite for the LibGNATdoc library"""

0 commit comments

Comments
 (0)