Skip to content

Commit

Permalink
Merge branch 'topic/ada2022' into 'master'
Browse files Browse the repository at this point in the history
Enable Ada 2022 for Spawn

See merge request eng/ide/spawn!48
  • Loading branch information
reznikmm committed May 18, 2023
2 parents fcd3c70 + 4d80ffb commit 2642bd6
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif

all:
gprbuild $(GPRBUILD_FLAGS) -P gnat/spawn.gpr
gprbuild $(GPRBUILD_FLAGS) -P gnat/spawn_tests.gpr -XSPAWN_LIBRARY_TYPE=static
gprbuild $(GPRBUILD_FLAGS) -P gnat/tests/spawn_tests.gpr -XSPAWN_LIBRARY_TYPE=static

check:
export LD_LIBRARY_PATH=.libs/spawn/relocatable; \
Expand Down
6 changes: 5 additions & 1 deletion alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ project-files = ["gnat/spawn.gpr"]
tags = ["process", "launch", "pipe"]

[configuration]
disabled = true
generate_ada = false
generate_c = false

[build-switches]
"*".ada_version = "Ada2022"

[gpr-externals]
OS = ["unix", "osx", "Windows_NT"]
Expand Down
118 changes: 118 additions & 0 deletions config/spawn_config.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
--
-- Copyright (C) 2020-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--

-- This file is stub to build Spawn outside of the Alire environment. Alire
-- will overwrite it during builds.
--
-- Set of switches for all build modes are the same with Alire. Project
-- specific switches should be added in Spawn project file itself.

abstract project Spawn_Config is
Crate_Version := "wavefront";
Crate_Name := "spawn";

Alire_Host_OS := "linux";

Alire_Host_Arch := "x86_64";

Alire_Host_Distro := "ubuntu";
External_Ada_Compiler_Switches := External_As_List ("ADAFLAGS", " ");
Development_Ada_Compiler_Switches :=
(
"-Og" -- Optimize for debug
,"-ffunction-sections" -- Separate ELF section for each function
,"-fdata-sections" -- Separate ELF section for each variable
,"-g" -- Generate debug info
,"-gnatwa" -- Enable all warnings
,"-gnatw.X" -- Disable warnings for No_Exception_Propagation
,"-gnatVa" -- All validity checks
,"-gnaty3" -- Specify indentation level of 3
,"-gnatya" -- Check attribute casing
,"-gnatyA" -- Use of array index numbers in array attributes
,"-gnatyB" -- Check Boolean operators
,"-gnatyb" -- Blanks not allowed at statement end
,"-gnatyc" -- Check comments
,"-gnaty-d" -- Disable check no DOS line terminators present
,"-gnatye" -- Check end/exit labels
,"-gnatyf" -- No form feeds or vertical tabs
,"-gnatyh" -- No horizontal tabs
,"-gnatyi" -- Check if-then layout
,"-gnatyI" -- check mode IN keywords
,"-gnatyk" -- Check keyword casing
,"-gnatyl" -- Check layout
,"-gnatym" -- Check maximum line length
,"-gnatyn" -- Check casing of entities in Standard
,"-gnatyO" -- Check that overriding subprograms are explicitly marked as such
,"-gnatyp" -- Check pragma casing
,"-gnatyr" -- Check identifier references casing
,"-gnatyS" -- Check no statements after THEN/ELSE
,"-gnatyt" -- Check token spacing
,"-gnatyu" -- Check unnecessary blank lines
,"-gnatyx" -- Check extra parentheses
,"-gnat2022" -- Ada 2022 Mode
);
Validation_Ada_Compiler_Switches :=
(
"-O3" -- Optimize for performance
,"-gnatn" -- Enable inlining
,"-ffunction-sections" -- Separate ELF section for each function
,"-fdata-sections" -- Separate ELF section for each variable
,"-g" -- Generate debug info
,"-gnato" -- Enable numeric overflow checking
,"-gnatwa" -- Enable all warnings
,"-gnatw.X" -- Disable warnings for No_Exception_Propagation
,"-gnatVa" -- All validity checks
,"-gnatwe" -- Warnings as errors
,"-gnata" -- Enable assertions and contracts
,"-gnaty3" -- Specify indentation level of 3
,"-gnatya" -- Check attribute casing
,"-gnatyA" -- Use of array index numbers in array attributes
,"-gnatyB" -- Check Boolean operators
,"-gnatyb" -- Blanks not allowed at statement end
,"-gnatyc" -- Check comments
,"-gnaty-d" -- Disable check no DOS line terminators present
,"-gnatye" -- Check end/exit labels
,"-gnatyf" -- No form feeds or vertical tabs
,"-gnatyh" -- No horizontal tabs
,"-gnatyi" -- Check if-then layout
,"-gnatyI" -- check mode IN keywords
,"-gnatyk" -- Check keyword casing
,"-gnatyl" -- Check layout
,"-gnatym" -- Check maximum line length
,"-gnatyn" -- Check casing of entities in Standard
,"-gnatyO" -- Check that overriding subprograms are explicitly marked as such
,"-gnatyp" -- Check pragma casing
,"-gnatyr" -- Check identifier references casing
,"-gnatyS" -- Check no statements after THEN/ELSE
,"-gnatyt" -- Check token spacing
,"-gnatyu" -- Check unnecessary blank lines
,"-gnatyx" -- Check extra parentheses
,"-gnat2022" -- Ada 2022 Mode
);
Release_Ada_Compiler_Switches :=
(
"-O3" -- Optimize for performance
,"-gnatn" -- Enable inlining
,"-ffunction-sections" -- Separate ELF section for each function
,"-fdata-sections" -- Separate ELF section for each variable
,"-gnat2022" -- Ada 2022 Mode
);

type Build_Profile_Kind is ("release", "validation", "development");
Build_Profile : Build_Profile_Kind :=
external ("SPAWN_BUILD_PROFILE", external ("BUILD_PROFILE", "development"));

Ada_Compiler_Switches := ();
case Build_Profile is
when "release" =>
Ada_Compiler_Switches := External_Ada_Compiler_Switches & Release_Ada_Compiler_Switches;
when "validation" =>
Ada_Compiler_Switches := External_Ada_Compiler_Switches & Validation_Ada_Compiler_Switches;
when "development" =>
Ada_Compiler_Switches := External_Ada_Compiler_Switches & Development_Ada_Compiler_Switches;
end case;

end Spawn_Config;
35 changes: 15 additions & 20 deletions gnat/spawn.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
-- SPDX-License-Identifier: Apache-2.0
--

with "../config/spawn_config.gpr";

library project Spawn is

type OS_API_Kind is ("unix", "osx", "Windows_NT");
Expand All @@ -19,13 +21,6 @@ library project Spawn is

Superproject := external ("SUPERPROJECT", "");

-- By default, treat warnings as errors in dev mode, but not in prod
-- mode. Let users override this default using the SPAWN_WARN_ERRORS
-- environment variable.

type Any_Boolean is ("false", "true");
Warnings_As_Errors : Any_Boolean := external ("SPAWN_WARN_ERRORS", "true");

for Library_Kind use Library_Type;
for Object_Dir use "../.obj/" & Superproject & "/spawn/" & Library_Type;
for Library_Dir use "../.libs/" & Superproject & "/spawn/" & Library_Type;
Expand Down Expand Up @@ -60,16 +55,13 @@ library project Spawn is
"spawn-internal-windows.adb");
end case;

Ada_Switches := ();
Spawn_Ada_Compiler_Switches := ();
Coverage_Ada_Compiler_Switches := ();
Linker_Options := ();
case Warnings_As_Errors is
when "true" => Ada_Switches := Ada_Switches & ("-gnatwe");
when "false" => null;
end case;

case Build_Mode is
when "prod" =>
Ada_Switches := Ada_Switches & (
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & (
-- Compile with optimizations
"-O2",

Expand All @@ -79,7 +71,7 @@ library project Spawn is
);

when "dev" =>
Ada_Switches := Ada_Switches & (
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & (
-- Compile with no optimization and with debug information to ease
-- investigation in debuggers.
"-O0", "-g",
Expand All @@ -96,18 +88,16 @@ library project Spawn is
);

when "coverage" =>
Ada_Switches := Ada_Switches & (
-- Compile with no optimization and with debug information to ease
-- investigation in debuggers.
"-O0", "-g",
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & ();
Coverage_Ada_Compiler_Switches := (

-- Enable coverage code instrumentation.
"--coverage");

Linker_Options := Linker_Options & ("--coverage");

when "AddressSanitizer" =>
Ada_Switches := Ada_Switches & (
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & (
-- Standard development flags
"-O0", "-g",
-- Enable the AddressSanitizer
Expand All @@ -116,8 +106,13 @@ library project Spawn is
Linker_Options := Linker_Options & ("-fsanitize=address");
end case;

Ada_Compiler_Switches :=
Spawn_Config.Ada_Compiler_Switches
& Spawn_Ada_Compiler_Switches
& Coverage_Ada_Compiler_Switches;

package Compiler is
for Switches ("ada") use Ada_Switches;
for Switches ("ada") use Spawn_Ada_Compiler_Switches;
end Compiler;

package Linker is
Expand Down
32 changes: 13 additions & 19 deletions gnat/spawn_glib.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--

with "gtkada";
with "../config/spawn_config.gpr";

library project Spawn_Glib is

Expand All @@ -19,13 +20,6 @@ library project Spawn_Glib is
Build_Mode : Spawn_Glib_Build_Kind :=
external ("SPAWN_GLIB_BUILD_MODE", external ("BUILD_MODE", "prod"));

-- By default, treat warnings as errors in dev mode, but not in prod
-- mode. Let users override this default using the SPAWN_WARN_ERRORS
-- environment variable.

type Any_Boolean is ("false", "true");
Warnings_As_Errors : Any_Boolean := external ("SPAWN_WARN_ERRORS", "true");

for Library_Kind use Library_Type;
for Object_Dir use "../.obj/spawn_glib/" & Library_Type;
for Library_Dir use "../.libs/spawn_glib/" & Library_Type;
Expand Down Expand Up @@ -63,16 +57,13 @@ library project Spawn_Glib is
"posix_const.c");
end case;

Ada_Switches := ();
Spawn_Ada_Compiler_Switches := ();
Coverage_Ada_Compiler_Switches := ();
Linker_Options := ();
case Warnings_As_Errors is
when "true" => Ada_Switches := Ada_Switches & ("-gnatwe");
when "false" => null;
end case;

case Build_Mode is
when "prod" =>
Ada_Switches := Ada_Switches & (
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & (
-- Compile with optimizations
"-O2",

Expand All @@ -82,7 +73,7 @@ library project Spawn_Glib is
);

when "dev" =>
Ada_Switches := Ada_Switches & (
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & (
-- Compile with no optimization and with debug information to ease
-- investigation in debuggers.
"-O0", "-g",
Expand All @@ -99,19 +90,22 @@ library project Spawn_Glib is
);

when "coverage" =>
Ada_Switches := Ada_Switches & (
-- Compile with no optimization and with debug information to ease
-- investigation in debuggers.
"-O0", "-g",
Spawn_Ada_Compiler_Switches := Spawn_Ada_Compiler_Switches & ();
Coverage_Ada_Compiler_Switches := (

-- Enable coverage code instrumentation.
"--coverage");

Linker_Options := Linker_Options & ("--coverage");
end case;

Ada_Compiler_Switches :=
Spawn_Config.Ada_Compiler_Switches
& Spawn_Ada_Compiler_Switches
& Coverage_Ada_Compiler_Switches;

package Compiler is
for Switches ("ada") use Ada_Switches;
for Switches ("ada") use Spawn_Ada_Compiler_Switches;
end Compiler;

package Linker is
Expand Down
6 changes: 3 additions & 3 deletions gnat/spawn_glib_tests.gpr → gnat/tests/spawn_glib_tests.gpr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
-- Copyright (C) 2018, AdaCore
-- Copyright (C) 2018-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
Expand All @@ -8,8 +8,8 @@ with "spawn_glib";

project Spawn_Glib_Tests is

for Source_Dirs use ("../testsuite/spawn");
for Object_Dir use "../.obj/spawn_test";
for Source_Dirs use ("../../testsuite/spawn");
for Object_Dir use "../../.obj/spawn_test";
for Main use ("spawn_glib_test.adb", "spawn_glib_args_test.adb");

package Compiler renames Spawn_Glib.Compiler;
Expand Down
6 changes: 3 additions & 3 deletions gnat/spawn_tests.gpr → gnat/tests/spawn_tests.gpr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
-- Copyright (C) 2018-2021, AdaCore
-- Copyright (C) 2018-2023, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0
--
Expand All @@ -20,8 +20,8 @@ project Spawn_Tests is
null;
end case;

for Source_Dirs use ("../testsuite/spawn");
for Object_Dir use "../.obj/spawn_test";
for Source_Dirs use ("../../testsuite/spawn");
for Object_Dir use "../../.obj/spawn_test";
for Main use Main;

package Compiler renames Spawn.Compiler;
Expand Down
6 changes: 4 additions & 2 deletions testsuite/spawn/spawn_glib_args_test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ procedure Spawn_Glib_Args_Test is
is
Data : Ada.Streams.Stream_Element_Array (1 .. 256);
Last : Ada.Streams.Stream_Element_Count;
Ok : Boolean := True;

begin
Self.Process.Read_Standard_Error (Data, Last);
Self.Process.Read_Standard_Error (Data, Last, Ok);

for X of Data (1 .. Last) loop
Ada.Text_IO.Put (Character'Val (X));
Expand All @@ -96,9 +97,10 @@ procedure Spawn_Glib_Args_Test is
is
Data : Ada.Streams.Stream_Element_Array (1 .. 256);
Last : Ada.Streams.Stream_Element_Count;
Ok : Boolean := True;

begin
Self.Process.Read_Standard_Output (Data, Last);
Self.Process.Read_Standard_Output (Data, Last, Ok);

for X of Data (1 .. Last) loop
Ada.Text_IO.Put (Character'Val (X));
Expand Down
6 changes: 4 additions & 2 deletions testsuite/spawn/spawn_glib_test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ procedure Spawn_Glib_Test is
use type Ada.Streams.Stream_Element_Offset;
Data : Ada.Streams.Stream_Element_Array (1 .. 16);
Last : Ada.Streams.Stream_Element_Count;
Ok : Boolean := True;
begin
Ada.Text_IO.Put_Line ("Standard_Output_Available");
loop
P.Read_Standard_Output (Data, Last);
P.Read_Standard_Output (Data, Last, Ok);

exit when Last in 0;

Expand Down Expand Up @@ -95,9 +96,10 @@ procedure Spawn_Glib_Test is
2 => Character'Pos ('K'),
3 => 10);
Last : Ada.Streams.Stream_Element_Count;
Ok : Boolean := True;
begin
Ada.Text_IO.Put_Line ("Standard_Input_Available");
P.Write_Standard_Input (Data, Last);
P.Write_Standard_Input (Data, Last, Ok);
end Standard_Input_Available;

overriding procedure Started (Self : in out Listener) is
Expand Down

0 comments on commit 2642bd6

Please sign in to comment.