Skip to content

Commit 4140d71

Browse files
Merge branch 'topic/alire_integration' into 'master'
Create Build Targets for Alire See merge request eng/ide/gnatstudio!479
2 parents 1decad7 + 8bf5275 commit 4140d71

File tree

6 files changed

+348
-63
lines changed

6 files changed

+348
-63
lines changed

builder/src/builder_facility_module-scripts.adb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@ package body Builder_Facility_Module.Scripts is
132132
Data.Set_Return_Value (Arg.all);
133133
end loop;
134134
end;
135+
elsif Command = "set_as_alias" then
136+
declare
137+
Inst : constant Class_Instance :=
138+
Nth_Arg (Data, 1, Target_Class);
139+
Target_Name : constant String := Get_Target_Name (Inst);
140+
Target : constant Target_Access :=
141+
Get_Target_From_Name
142+
(Registry => Registry,
143+
Name => Target_Name,
144+
Resolve_Alias => False);
145+
Aliased_Target_Name : constant String := Nth_Arg (Data, 2, "");
146+
Aliased_Target : constant Target_Access :=
147+
Get_Target_From_Name (Registry, Aliased_Target_Name);
148+
begin
149+
-- The given alias target does not exist: return an error message
150+
if Aliased_Target = null and then Aliased_Target_Name /= "" then
151+
Set_Error_Msg
152+
(Data,
153+
-"Invalid alias: no target has been registered "
154+
& "with this name: '"
155+
& Aliased_Target_Name
156+
& "'");
157+
return;
158+
end if;
159+
160+
Set_As_Alias
161+
(Target => Target,
162+
Aliased_Target => Aliased_Target);
163+
end;
135164

136165
elsif Command = "get_expanded_command_line" then
137166
declare
@@ -268,6 +297,14 @@ package body Builder_Facility_Module.Scripts is
268297
Class => Target_Class,
269298
Handler => Shell_Handler'Access);
270299

300+
Register_Command
301+
(Repo => Kernel.Scripts,
302+
Command => "set_as_alias",
303+
Params =>
304+
(1 => Param ("aliased_target_name", Optional => True)),
305+
Class => Target_Class,
306+
Handler => Shell_Handler'Access);
307+
271308
Register_Command
272309
(Kernel, "get_command_line",
273310
Minimum_Args => 0,

common/core/src/build_configurations.adb

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,34 @@ package body Build_Configurations is
827827
--------------------------
828828

829829
function Get_Target_From_Name
830-
(Registry : Build_Config_Registry_Access;
831-
Name : String) return Target_Access
830+
(Registry : Build_Config_Registry_Access;
831+
Name : String;
832+
Resolve_Alias : Boolean := True) return Target_Access
832833
is
833834
C : Cursor;
835+
Target : Target_Access;
834836
begin
835837
C := Registry.Targets.First;
836838

837839
while Has_Element (C) loop
838-
if To_String (Element (C).Name) = Name then
839-
return Element (C);
840+
Target := Element (C);
841+
842+
if To_String (Target.Name) = Name then
843+
844+
-- Check if we are dealing with an alias.
845+
-- If it's the case, return the aliased target when asked.
846+
if not Resolve_Alias
847+
or else
848+
Target.Properties.Aliased_Target_Name = Null_Unbounded_String
849+
then
850+
return Target;
851+
else
852+
return Get_Target_From_Name
853+
(Registry => Registry,
854+
Name =>
855+
To_String (Target.Properties.Aliased_Target_Name),
856+
Resolve_Alias => False);
857+
end if;
840858
end if;
841859

842860
Next (C);
@@ -1969,6 +1987,22 @@ package body Build_Configurations is
19691987
Target.Properties.Launch_Mode := Launch_Mode;
19701988
end Set_Launch_Mode;
19711989

1990+
------------------
1991+
-- Set_As_Alias --
1992+
------------------
1993+
1994+
procedure Set_As_Alias
1995+
(Target : not null Target_Access;
1996+
Aliased_Target : Target_Access := null) is
1997+
begin
1998+
if Aliased_Target /= null then
1999+
Target.Properties.Aliased_Target_Name := Aliased_Target.Name;
2000+
else
2001+
Target.Properties.Aliased_Target_Name :=
2002+
Ada.Strings.Unbounded.Null_Unbounded_String;
2003+
end if;
2004+
end Set_As_Alias;
2005+
19722006
----------
19732007
-- Free --
19742008
----------

common/core/src/build_configurations.ads

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ package Build_Configurations is
143143
-- Remove target named Target_Name from registry
144144

145145
function Get_Target_From_Name
146-
(Registry : Build_Config_Registry_Access;
147-
Name : String) return Target_Access;
146+
(Registry : Build_Config_Registry_Access;
147+
Name : String;
148+
Resolve_Alias : Boolean := True) return Target_Access;
148149
-- Get the target corresponding to Name in the Registry; return null if
149150
-- no such target was found.
151+
-- If the target refered by Name is an alias on another target, the
152+
-- aliased target is returned instead if Resolve_Alias is set to True.
150153

151154
procedure Duplicate_Target
152155
(Registry : Build_Config_Registry_Access;
@@ -327,6 +330,9 @@ package Build_Configurations is
327330

328331
Project_Switches : Unbounded_String;
329332
-- Project switches relevant for this target, if any.
333+
334+
Aliased_Target_Name : Unbounded_String;
335+
-- The name of the target being aliased, if any.
330336
end record;
331337

332338
function Get_Properties (Target : Target_Access) return Target_Properties;
@@ -447,6 +453,21 @@ package Build_Configurations is
447453
(Target : Target_Access; Launch_Mode : Launch_Mode_Type);
448454
-- Change Launch_Mode value
449455

456+
procedure Set_As_Alias
457+
(Target : not null Target_Access;
458+
Aliased_Target : Target_Access := null);
459+
-- Set the given target as an alias for Aliased_Target.
460+
-- Aliases are used to temporarily replace a build target
461+
-- (e.g: "Build All") by another one (e.g: "My Custom Build All").
462+
--
463+
-- This can be used by plugins to execute their own custom build targets
464+
-- while the user interacts with the default GNAT Studio build targets,
465+
-- either via the UI or through the GPS.BuildTarget Python API.
466+
-- In the example given above, clicking on the "Build All" toolbar button
467+
-- will actually execute "My Custom Build All" instead.
468+
--
469+
-- Giving a null aliased target will unset any existing alias.
470+
450471
function Apply_Mode_Args
451472
(Target : access Target_Type;
452473
Mode : String;

docs/users_guide/GPS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ Classes
186186

187187
.. automethod:: GPS.BuildTarget.remove
188188

189+
.. automethod:: GPS.BuildTarget.set_as_alias
190+
189191
.. automethod:: GPS.BuildTarget.show
190192

191193
:class:`GPS.Button`

docs/users_guide/GPS/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,26 @@ def show(self):
986986
"""
987987
pass # implemented in Ada
988988

989+
def set_as_alias(aliased_target_name=""):
990+
"""
991+
Set the given target as an alias for target designated by `alias_target_name`.
992+
Aliases are used to temporarily replace a build target
993+
(e.g: "Build All") by another one (e.g: "My Custom Build All").
994+
995+
This can be used by plugins to execute their own custom build targets
996+
while the user interacts with the default GNAT Studio build targets,
997+
either via the UI or through the GPS.BuildTarget Python API.
998+
In the example given above, clicking on the "Build All" toolbar button
999+
will actually execute "My Custom Build All" instead.
1000+
1001+
To unset an just give an empty string for the `aliased_target_name`
1002+
parameter
1003+
1004+
:param str aliased_target_name: The name of the aliased target, or an
1005+
empty string to unset the alias.
1006+
"""
1007+
pass # implemented in Ada
1008+
9891009
@staticmethod
9901010
def expand_macros(cmd_line):
9911011
"""

0 commit comments

Comments
 (0)