diff mbox

[Ada] gnatname creates backup copy of project file

Message ID 20130411094152.GA24010@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 11, 2013, 9:41 a.m. UTC
When invoked with an existing project file, gnatname now creates a backup
copy of the project file before modifying it, unless it is invoked with
the new switch --no-backup.

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-11  Vincent Celier  <celier@adacore.com>

	* gnatname.adb (Scan_Args): Recognize new switch --no-backup
	(Usage): Add line for --no-backup.
	* opt.ads (No_Nackup): New Boolean variable, initialized to False.
	* prj-makr.adb (Initialize): Create a backup for an existing
	project file if gnatname is not invoked with --no-backup.

Comments

Arnaud Charlet April 11, 2013, 9:44 a.m. UTC | #1
Another important change was done in this commit, I've updated the changelog
accordingly:

        (Ada_Version_Default): Switch to Ada 2012 by default.

Since Ada 2012 is the new Ada standard, GNAT is switched to Ada 2012 instead of
Ada 2005 by default.

> Index: opt.ads
> ===================================================================
> 
> --- opt.ads	(revision 197743)
> +++ opt.ads	(working copy)
> @@ -119,14 +119,11 @@
>     --  Think twice before using "="; Ada_Version >= Ada_2012 is more likely
>     --  what you want, because it will apply to future versions of the
>     language.
>  
> -   Ada_Version_Default : constant Ada_Version_Type := Ada_2005;
> +   Ada_Version_Default : constant Ada_Version_Type := Ada_2012;
>     pragma Warnings (Off, Ada_Version_Default);
>     --  GNAT
>     --  Default Ada version if no switch given. The Warnings off is to kill
>     --  constant condition warnings.
diff mbox

Patch

Index: prj-makr.adb
===================================================================
--- prj-makr.adb	(revision 197743)
+++ prj-makr.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -24,6 +24,7 @@ 
 ------------------------------------------------------------------------------
 
 with Csets;
+with Hostparm;
 with Opt;
 with Output;
 with Osint;    use Osint;
@@ -1047,6 +1048,39 @@ 
            Project_File_Extension;
          Output_Name_Last := Output_Name_Last + Project_File_Extension'Length;
 
+         --  Back up project file if it already exists
+
+         if not Hostparm.OpenVMS
+           and then not Opt.No_Backup
+           and then
+             Is_Regular_File (Path_Name (1 .. Path_Last))
+         then
+            declare
+               Discard : Boolean;
+               Saved_Path : constant String :=
+                 Path_Name (1 .. Path_Last) & ".saved_";
+               Nmb : Natural := 0;
+            begin
+               loop
+                  declare
+                     Img : constant String := Nmb'Img;
+                  begin
+                     if not Is_Regular_File
+                             (Saved_Path & Img (2 .. Img'Last))
+                     then
+                        Copy_File
+                          (Name => Path_Name (1 .. Path_Last),
+                           Pathname => Saved_Path & Img (2 .. Img'Last),
+                           Mode => Overwrite,
+                           Success => Discard);
+                        exit;
+                     end if;
+
+                     Nmb := Nmb + 1;
+                  end;
+               end loop;
+            end;
+         end if;
       end if;
 
       --  Change the current directory to the directory of the project file,
Index: opt.ads
===================================================================
--- opt.ads	(revision 197743)
+++ opt.ads	(working copy)
@@ -119,14 +119,11 @@ 
    --  Think twice before using "="; Ada_Version >= Ada_2012 is more likely
    --  what you want, because it will apply to future versions of the language.
 
-   Ada_Version_Default : constant Ada_Version_Type := Ada_2005;
+   Ada_Version_Default : constant Ada_Version_Type := Ada_2012;
    pragma Warnings (Off, Ada_Version_Default);
    --  GNAT
    --  Default Ada version if no switch given. The Warnings off is to kill
    --  constant condition warnings.
-   --
-   --  WARNING: some scripts rely on the format of this line of code. Any
-   --  change must be coordinated with the scripts requirements.
 
    Ada_Version : Ada_Version_Type := Ada_Version_Default;
    --  GNAT
@@ -986,6 +983,11 @@ 
    --  in this variable (e.g. 2 = select second unit in file). A value of
    --  zero indicates that we are in normal (one unit per file) mode.
 
+   No_Backup : Boolean := False;
+   --  GNATNAME
+   --  Set by switch --no-backup.
+   --  Do not create backup copies of project files.
+
    No_Deletion : Boolean := False;
    --  GNATPREP
    --  Set by preprocessor switch -a. Do not eliminate any source text. Implies
Index: gnatname.adb
===================================================================
--- gnatname.adb	(revision 197743)
+++ gnatname.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2013, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -346,6 +346,11 @@ 
                   Subdirs :=
                     new String'(Arg (Subdirs_Switch'Length + 1 .. Arg'Last));
 
+               --  --no-backup
+
+               elsif Arg = "--no-backup" then
+                  Opt.No_Backup := True;
+
                --  -c
 
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-c" then
@@ -515,6 +520,7 @@ 
          Display_Usage_Version_And_Help;
 
          Write_Line ("  --subdirs=dir real obj/lib/exec dirs are subdirs");
+         Write_Line ("  --no-backup   do not create backup of project file");
          Write_Eol;
 
          Write_Line ("  --and        use different patterns");