libgpr2_24.0.0_eda3c693/src/lib/gpr2-project-source-artifact.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--

--  The artifacts that are generated by the compilation of a source file of a
--  given project.

with Ada.Containers.Ordered_Maps;

with GPR2.Path_Name.Set;

package GPR2.Project.Source.Artifact is

   type Category is
     (Object_File,
      Dependency_File,
      Callgraph,
      Switches,
      Preprocessed_Source,
      Coverage);

   type Filter is array (Category) of Boolean;

   All_Artifacts : constant Filter;

   type Object is tagged private;

   Undefined : constant Object;
   --  This constant is equal to any object declared without an explicit
   --  initializer.

   type Dependency_Location is (In_Library, In_Objects, In_Both);
   --  Kind of the dependency files location.
   --  The Ada dependency files can be either in object directory or/and
   --  in Library directory.

   function Is_Defined (Self : Object) return Boolean;
   --  Returns true if Self is defined

   function Create
     (Source     : Project.Source.Object;
      Force_Spec : Boolean := False;
      Filter     : Artifact.Filter := All_Artifacts) return Artifact.Object
     with Pre => Source.Is_Defined;
   --  Constructor for Object defining the artifacts for the given Source.
   --  Force_Spec is for the case when specification has implementation part
   --  but artifact names need to be created from specification base name. It
   --  is necessary when body and spec have different base names due to naming
   --  exception and gprinstall installing only specifications with -m option.

   function Source (Self : Object) return Project.Source.Object
     with Pre => Self.Is_Defined;
   --  The project's source used to generate the artifacts

   function Has_Object_Code
     (Self : Object; Index : Unit_Index := No_Index) return Boolean
     with Pre => Self.Is_Defined;
   --  Returns True if an object-code path is defined at Index.
   --  If Index = 0 returns True on any object file defined.

   function Object_Code
     (Self  : Object;
      Index : Unit_Index := No_Index) return GPR2.Path_Name.Object
     with Pre => Self.Is_Defined and then Self.Has_Object_Code (Index);
   --  The target-dependent code (generally .o or .obj).
   --  If Index = 0 then returns first available object file path.

   function Has_Dependency
     (Self     : Object;
      Index    : Unit_Index          := No_Index;
      Location : Dependency_Location := In_Both) return Boolean
     with Pre => Self.Is_Defined;
   --  Returns True if a dependency path is defined.
   --  The Location parameter defines are we looking for dependency files in
   --  the object directory, library directory, or in both directories.
   --  If Index = 0 returns True if dependency exists at any index.

   function Dependency
     (Source        : Project.Source.Object;
      Index         : Unit_Index          := No_Index;
      Location      : Dependency_Location := In_Both;
      Actual_File   : Boolean             := False;
      Maybe_No_Body : Boolean             := False)
      return GPR2.Path_Name.Object
     with Pre => Source.Is_Defined;
   --  Retrieve just the dependency file (LI file) corresponding to the unit
   --  in Source at Index (if any).
   --  This file can be searched in Library_ALI_Dir or Object_Dir or in both,
   --  this is specified by the location parameter.
   --  If Actual_File is set, then only files that actually exist on the hard
   --  drive are returned. else file that could exist if a compilation occurred
   --  will also be returned, even if they're not available.
   --  If Maybe_No_Body is set, then the LI file is looked for even for units
   --  that have a S_Spec kind. Else only Body_Kind and S_Spec_Only are
   --  considered.

   function Dependency
     (Self     : Object;
      Index    : Unit_Index          := No_Index;
      Location : Dependency_Location := In_Both)
      return GPR2.Path_Name.Object
     with Pre  => Self.Is_Defined
                  and then Self.Has_Dependency (Index, Location),
          Post => Dependency'Result.Is_Defined;
   --  A file containing information (.ali for GNAT, .d for GCC) like
   --  cross-reference, units used by the source, etc.
   --  The Location parameter defines are we looking for dependency files in
   --  the object directory, library directory, or in both directories.
   --  In case of Location = In_Both, the returning priority is for existing
   --  files. If Index = 0 returns dependency with first available index.

   function Has_Preprocessed_Source (Self : Object) return Boolean
     with Pre => Self.Is_Defined;
   --  Returns True if a preprocessed-source is defined

   function Preprocessed_Source (Self : Object) return GPR2.Path_Name.Object
     with Pre => Self.Is_Defined and then Self.Has_Preprocessed_Source;
   --  Returns the file containing the preprocessed source

   function Has_Callgraph
     (Self  : Object;
      Index : Unit_Index := No_Index) return Boolean
     with Pre => Self.Is_Defined;
   --  Returns True if a callgraph is defined

   function Callgraph
     (Self  : Object;
      Index : Unit_Index := No_Index) return GPR2.Path_Name.Object
     with Pre => Self.Is_Defined and then Self.Has_Callgraph (Index);
   --  Returns the callgraph file

   function Has_Coverage
     (Self : Object;
      Index : Unit_Index := No_Index) return Boolean
     with Pre => Self.Is_Defined;
   --  Returns True if a coverage is defined

   function Coverage
     (Self  : Object;
      Index : Unit_Index := No_Index) return GPR2.Path_Name.Object
     with Pre => Self.Is_Defined and then Self.Has_Coverage (Index);
   --  Returns the coverage file

   function List (Self : Object) return GPR2.Path_Name.Set.Object
     with Pre => Self.Is_Defined;
   --  Returns all artifacts

   function List_To_Clean (Self : Object) return GPR2.Path_Name.Set.Object
     with Pre => Self.Is_Defined;
   --  Returns artifacts for gprclean

private

   use type GPR2.Path_Name.Object;

   All_Artifacts : constant Filter := (others => True);

   package Index_Path_Name_Map is new Ada.Containers.Ordered_Maps
     (Unit_Index, GPR2.Path_Name.Object);

   type Object is tagged record
      Source           : Project.Source.Object;
      Object_Files     : Index_Path_Name_Map.Map;
      Deps_Lib_Files   : Index_Path_Name_Map.Map;
      Deps_Obj_Files   : Index_Path_Name_Map.Map;
      Callgraph        : Index_Path_Name_Map.Map;
      Switches         : Index_Path_Name_Map.Map;
      Preprocessed_Src : GPR2.Path_Name.Object;
      Coverage         : Index_Path_Name_Map.Map;
   end record;

   Undefined : constant Object := (others => <>);

   function Is_Defined (Self : Object) return Boolean is
     (Self /= Undefined);

   function Has_Object_Code
     (Self : Object; Index : Unit_Index := No_Index) return Boolean
   is
     (if Index = No_Index
      then not Self.Object_Files.Is_Empty
      else Self.Object_Files.Contains (Index));

   function Has_Preprocessed_Source (Self : Object) return Boolean is
     (Self.Preprocessed_Src.Is_Defined);

   function Has_Callgraph
     (Self  : Object;
      Index : Unit_Index := No_Index) return Boolean
   is
     (Self.Callgraph.Contains (Index));

   function Has_Coverage
     (Self  : Object;
      Index : Unit_Index := No_Index) return Boolean
   is
     (Self.Coverage.Contains (Index));

end GPR2.Project.Source.Artifact;