comp.lang.ada
 help / color / mirror / Atom feed
* Raising "exception" in a .gpr file
@ 2021-08-13  7:23 mockturtle
  2021-08-13  7:44 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: mockturtle @ 2021-08-13  7:23 UTC (permalink / raw)


Dear.all,
I am linting an old library of mine (suid_helper) thought to help in writing setuid programs. (Basically, it drops suid privileges when program starts and allows to run in privileged mode only via few selected procedures, see https://gitlab.com/mockturtle/suid-helper  if you are curious).

At the moment the library works for Linux (since I use Linux) and I guess it could work with most other *nixes (but setuid stuff portability is tricky).  
As you can imagine, there is a part that is OS-dependent.  I isolated it into a directory that is selected in the gpr files on the basis of the current OS 

(BTW: I am using an external value for this, there is some more "standard" way to get the OS within the gpr file?)

For sure it does not work with Windows since that OS does not have the concept of "setuid executable" (as far as I know).  
It would be nice to be able to "raise an exception" when the OS is Windows, in the sense that the user that tries to compile (by mistake) the library under Windows  gets a message like 

"You cannot compile this in Windows since Windows has no setuid concept"

rather than getting some mysterious compile error later.

Just to be clear, I am thinking to something like


  case OS is
  ...when "linux" =>
   ......Arch_Sources := "src/Linux";

  ...when "macos" =>
   ......Arch_Sources := "src/Mac";

  ...when "windows" =>
   ......raise "This library makes no sense with this OS";
    end case;

I tried to look in the manual, this newsgroup and googled a bit, but I did not find anything.  I am afraid that this is not possible (although I think it could be a nice addition).

Do you know if this is possible and how?

Thank you in advance

Riccardo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13  7:23 Raising "exception" in a .gpr file mockturtle
@ 2021-08-13  7:44 ` Dmitry A. Kazakov
  2021-08-13  8:11   ` mockturtle
  2021-08-15 16:21 ` Britt
  2021-08-16 13:13 ` Fabien Chouteau
  2 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2021-08-13  7:44 UTC (permalink / raw)


On 2021-08-13 09:23, mockturtle wrote:

> Just to be clear, I am thinking to something like
> 
>    case OS is
>    ...when "linux" =>
>     ......Arch_Sources := "src/Linux";
> 
>    ...when "macos" =>
>     ......Arch_Sources := "src/Mac";
> 
>    ...when "windows" =>
>     ......raise "This library makes no sense with this OS";
>      end case;
> 
> I tried to look in the manual, this newsgroup and googled a bit, but I did not find anything.  I am afraid that this is not possible (although I think it could be a nice addition).

There are many nice addition they could have, starting with predefined 
variables for the host OS, host machine and a sane set of operations 
defined on strings.

> Do you know if this is possible and how?

You could refer to an non-existing source file in the choice:

    when "windows" =>
       for Source_Files use ("This library makes no sense with this OS");

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13  7:44 ` Dmitry A. Kazakov
@ 2021-08-13  8:11   ` mockturtle
  2021-08-13 15:40     ` Björn Lundin
  0 siblings, 1 reply; 7+ messages in thread
From: mockturtle @ 2021-08-13  8:11 UTC (permalink / raw)


On Friday, August 13, 2021 at 9:44:13 AM UTC+2, Dmitry A. Kazakov wrote:
> There are many nice addition they could have, starting with predefined 
> variables for the host OS, host machine and a sane set of operations 
> defined on strings.

I agree. With just few additions the project files would much more powerful and easier to use.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13  8:11   ` mockturtle
@ 2021-08-13 15:40     ` Björn Lundin
  2021-08-15 16:00       ` Mark Lorenzen
  0 siblings, 1 reply; 7+ messages in thread
From: Björn Lundin @ 2021-08-13 15:40 UTC (permalink / raw)


Den 2021-08-13 kl. 10:11, skrev mockturtle:
> On Friday, August 13, 2021 at 9:44:13 AM UTC+2, Dmitry A. Kazakov wrote:
>> There are many nice addition they could have, starting with predefined
>> variables for the host OS, host machine and a sane set of operations
>> defined on strings.
> 
> I agree. With just few additions the project files would much more powerful and easier to use.
> 


I autogenerate such a file via a tcl-script as part of calling make.
It has to be done at least once - GPS it uses the file as is
(they are on 1 line but Thunderbird thinks they are too long)


--This file is autogenerated - DO NOT EDIT
--contents is from ada -z and ada -Z and some environment variables
--generated 2021-06-21 19:21:34

project Environment is
   for Source_Dirs use (); -- to avoid warnings about no source files in 
THIS project

   type Compiler_Version_Type is ("2015", "2016", "2017", "2018", 
"4.9.2", "6.0.2", "7.1.1", "7.3.2", "7.4.1", "7.4.2", "7.4lts", 
"7.4ltsw", "17.2", "19.0w", "19.1", "19.2", "20.1", "20.2", "8.2.0", 
"9.3.0");

   type OS_Version_Type       is ("AIX_7.1", "AIX_7.2", "windows_6.2", 
"windows_10.0", "Linux_x86_64", "Linux_aarch64");

   type Database_Type         is ("oracle_10", "oracle_11", "oracle_12", 
"sqlserver", "oci", "odbc_oracle", "odbc_postgresql", "postgresql");

   type OS_Architecture_Type  is ("aix_ppc", "win_x86", "lnx_x64", 
"win_x64", "lnx_a64");

   type IPC_Type              is ("classic", "pipe", "rabbitmq");

   OS_Version       : OS_Version_Type       := "Linux_x86_64";
   OS_Architecture  : OS_Architecture_Type  := "lnx_x64";
   IPC              : IPC_Type              := "pipe";

   Compiler_Version : Compiler_Version_Type := "20.2";

   Database         : Database_Type     := "oci";
   Database_Version                     := "12";

   Source_Dir                           := "/usr2/wcs/some_project/source";
   Target_Dir                           := "/usr2/wcs/some_project/target";
   Ada_Library_Root                     := 
"/usr2/wcs/some_project/target/adalib";
   Ada_Library_Global                   := 
"/usr2/wcs/some_project/target/adalib/global_gpr";

end Environment;



Environment is then withed by other gpr files and used as

with "environment";
...

project Global is

    Target_Machine   : Environment.OS_Version_Type       := 
Environment.Os_Version;
    Compiler_Version : Environment.Compiler_Version_Type := 
Environment.Compiler_Version;
    Data_Base        : Environment.Database_Type         := 
Environment.Database;
    IPC              : Environment.IPC_Type              := Environment.IPC;

...

       when "Linux_x86_64" =>
         case Database is
             when "oci"  => Database_Libs := ("-L" & SOMEPATHE & "/lib", 
"-lclntsh", "-L" & SATTMATE_OCILIB & "/lib", "-locilib");
             when "sqlserver"   => Data_Base_Libs := ("-lodbc");
             when "odbc_oracle" => Data_Base_Libs := ("-lodbc");
             when "odbc_postgresql" => Data_Base_Libs := ("-lodbc");
             when others => null;
         end case;

         Platform_Dependent_Compiler_Switches := ();

         case IPC is
            when "classic" | "pipe" =>
               case RPC_Enabled is
                  when "false" => null;
                  when "true" =>





-- 
Björn

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13 15:40     ` Björn Lundin
@ 2021-08-15 16:00       ` Mark Lorenzen
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Lorenzen @ 2021-08-15 16:00 UTC (permalink / raw)


On Friday, August 13, 2021 at 5:40:05 PM UTC+2, björn lundin wrote:
> project Environment is 
> for Source_Dirs use (); -- to avoid warnings about no source files in 
> THIS project 

You can declare the project as "abstract" and then you do not need to define Source_Dirs i.e:

abstract project Environment is
...
end Environment;

See https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html#sharing-between-projects

Regards,
Mark L

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13  7:23 Raising "exception" in a .gpr file mockturtle
  2021-08-13  7:44 ` Dmitry A. Kazakov
@ 2021-08-15 16:21 ` Britt
  2021-08-16 13:13 ` Fabien Chouteau
  2 siblings, 0 replies; 7+ messages in thread
From: Britt @ 2021-08-15 16:21 UTC (permalink / raw)


Since sometime in 2018, gpr files have supported a "Warning_Message" attribute" than can be used in a case statement, e.g.,

  for Warning_Message use "This scenario variable combination is not  supported.";

Unfortunately this feature is still not documented in the GPRbuild User's Guide.

- Britt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Raising "exception" in a .gpr file
  2021-08-13  7:23 Raising "exception" in a .gpr file mockturtle
  2021-08-13  7:44 ` Dmitry A. Kazakov
  2021-08-15 16:21 ` Britt
@ 2021-08-16 13:13 ` Fabien Chouteau
  2 siblings, 0 replies; 7+ messages in thread
From: Fabien Chouteau @ 2021-08-16 13:13 UTC (permalink / raw)


On Friday, August 13, 2021 at 9:23:15 AM UTC+2, mockturtle wrote:
> Do you know if this is possible and how? 

You are already using types:

   type OS_Type is ("linux", "ms", "macos");
   OS : OS_Type :=  external("OS", "linux");

If the external is set to a value that is not part of the type, gprbuild will fail with an error:
 value "Windows_NT" is illegal for typed string "os_type"

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-16 13:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13  7:23 Raising "exception" in a .gpr file mockturtle
2021-08-13  7:44 ` Dmitry A. Kazakov
2021-08-13  8:11   ` mockturtle
2021-08-13 15:40     ` Björn Lundin
2021-08-15 16:00       ` Mark Lorenzen
2021-08-15 16:21 ` Britt
2021-08-16 13:13 ` Fabien Chouteau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox