comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier write-only address <gautier_niouzes@hotmail.com>
Subject: Re: Build order with gprbuild
Date: Wed, 1 Mar 2023 12:08:50 -0800 (PST)	[thread overview]
Message-ID: <018c257d-44cd-49cd-aac8-8c2b2cf616c4n@googlegroups.com> (raw)
In-Reply-To: <ttltvi$3i87j$1@dont-email.me>

Between normal Ada projects, everything works as you describe (and as expected).
However, in the special case where project B, instead of transforming Ada files into .o files, transforms other kind of files into Ada files that are with-ed by units of project A, things get off the road: project A doesn't see out-of-date Ada files produced by project B.

Here is a full example. Files are reproduced below (they are meant to land into the same directory).
Then you do the following commands:

gprbuild -P fuzzy_gen.gpr
gprbuild -P code_generation.gpr
gnatstudio -P main.gpr

First build launched from GNAT Studio does the following on my machine:

    Compile
    [Ada]          main.adb
    [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
    [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
    [Fuzzy]        x123.cfg
    Ada file "fuzzy_x123.adb" is up to date
    [Ada]          fuzzy_x123.adb
    [Ada]          fuzzy_x456.adb
    [Ada]          fuzzy_x789.adb
    Bind
    [gprbind]      main.bexch
    [Ada]          main.ali
    Link
    [link]         main.adb

Second build has an expected output as well:

    Compile
       [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
       [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
       [Fuzzy]        x123.cfg
    Ada file "fuzzy_x123.adb" is up to date
    gprbuild: "main.exe" up to date

Now, say you modify x123.cfg and save it.
    Compile
       [Fuzzy]        x789.cfg
    Ada file "fuzzy_x789.adb" is up to date
       [Fuzzy]        x456.cfg
    Ada file "fuzzy_x456.adb" is up to date
       [Fuzzy]        x123.cfg
    Converting "x123.cfg" into "fuzzy_x123.adb"...
    gprbuild: "main.exe" up to date

That's *not* what I would like: gprbuild did not detect the out-of-date file "fuzzy_x123.adb" in time.
A second call to gprbuild compiles the changed "fuzzy_x123.adb" and all is well, but it is one step too late.

The files
=========

1) The code generator
=====================

fuzzy_gen.gpr:
-------------

project Fuzzy_Gen is
  for Object_Dir use "obj";
  for Exec_Dir use "gen";
  for Create_Missing_Dirs use "True";
  for Main use ("fuzzy_gen.adb");
end Fuzzy_Gen;

fuzzy_gen.adb:
-------------

with Ada.Calendar,
     Ada.Command_Line,
     Ada.Directories,
     Ada.Text_IO;

procedure Fuzzy_Gen is
  use Ada.Command_Line, Ada.Directories, Ada.Text_IO;

  procedure Convert (arg : String) is
    cfg : constant String := Simple_Name (arg);
    cfg_file_name : constant String := "../" & cfg;
    ada_unit_name : constant String :=
      "fuzzy_" & cfg (cfg'First .. cfg'Last - 4);
    ada_file_name : constant String := ada_unit_name & ".adb";
    cfg_in, ada_out : File_Type;
    use type Ada.Calendar.Time;
  begin
    if Exists (ada_file_name) and then
       Modification_Time (ada_file_name) >=
       Modification_Time (cfg_file_name)
    then
      Put_Line ("Ada file """ & ada_file_name & """ is up to date");
      return;
    end if;
    Put_Line
      ("Converting """ & cfg & """ into """ & ada_file_name & """...");
    Open (cfg_in, In_File, cfg_file_name);
    Create (ada_out, Out_File, ada_file_name);
    Put_Line
      (ada_out, "function " & ada_unit_name & " return String is");
    Put_Line (ada_out, "begin");
    Put_Line (ada_out, "  return """ & Get_Line (cfg_in) & """;");
    Put_Line (ada_out, "end;");
    Close (cfg_in);
    Close (ada_out);
  end Convert;


begin
  if Argument_Count = 0 then
    Put_Line (Current_Error, "config file name missing");
  else
    Convert (Argument (1));
  end if;
end Fuzzy_Gen;

2) The project that generates Ada files ("project B")
=====================================================

code_generation.gpr:
-------------------
project Code_Generation is

   for Languages use ("Fuzzy");
   for Source_Dirs use (".");
   for Object_Dir use "gen";
   for Objects_Linked  ("Fuzzy") use "False";

   package Naming is
      for Body_Suffix ("Fuzzy") use ".cfg";
   end Naming;

   package Compiler is
      for Driver ("Fuzzy") use "fuzzy_gen";
   end Compiler;

end Code_Generation;

x123.cfg:
--------
123

x456.cfg:
--------
456

x789.cfg:
--------
789

3) The main project (project A)
===============================

main.gpr:
--------
with "code_generation.gpr";

project Main is
  for Source_Dirs use (".", "gen");
  for Object_Dir use "obj";
  for Create_Missing_Dirs use "True";
  for Main use ("main.adb");
end Main;

main.adb:
--------
with Ada.Text_IO;
with Fuzzy_X123,
     Fuzzy_X456,
     Fuzzy_X789;

procedure Main is
begin
  Ada.Text_IO.Put
    ("Messages from elsewhere:" &
     " """ & Fuzzy_X123 & '"' &
     " """ & Fuzzy_X456 & '"' &
     " """ & Fuzzy_X789 & '"');
end;

  reply	other threads:[~2023-03-01 20:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 21:10 Build order with gprbuild Gautier write-only address
2023-02-28 22:07 ` Dmitry A. Kazakov
2023-03-01 20:08   ` Gautier write-only address [this message]
2023-03-02 14:11     ` AdaMagica
2023-03-02 16:54       ` AdaMagica
2023-03-02 22:29 ` Simon Wright
2023-03-04 19:01   ` AdaMagica
2023-03-05 18:35     ` AdaMagica
replies disabled

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