Archive:PackagingDrafts/Ada Guidelines Changes

From FedoraProject

(Difference between revisions)
Jump to: navigation, search
(copied the current text)
(Merged changes into the text.)
Line 20: Line 20:
  
 
Maintainers of some secondary architectures want to prevent build attempts that would always fail because they haven't bootstrapped GNAT on their architectures. A macro has been defined to help with this. I propose to add the following paragraph to the Compilation section:
 
Maintainers of some secondary architectures want to prevent build attempts that would always fail because they haven't bootstrapped GNAT on their architectures. A macro has been defined to help with this. I propose to add the following paragraph to the Compilation section:
+
 
The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. When there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this '''MUST''' be done with "ExclusiveArch: %{GNAT_arches}".
+
The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. When there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this '''MUST''' be done with "<code>ExclusiveArch: %{GNAT_arches}</code>".
  
 
==Category==
 
==Category==
Line 37: Line 37:
 
== Compilation ==
 
== Compilation ==
  
Ada code in Fedora '''MUST''' be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code MUST have "<code>BuildRequires: gcc-gnat</code>" to ensure that the compiler is available. The RPM macro %{GNAT_optflags} '''MUST''' be used in the compilation. It contains the standard Fedora optimization flags adapted to GNAT.
+
* Ada code in Fedora '''MUST''' be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code MUST have "<code>BuildRequires: gcc-gnat</code>" to ensure that the compiler is available.
 +
 
 +
* The RPM macros Gnatmake_optflags and GPRbuild_optflags expand to Fedora's standard compiler and linker flags adapted for Gnatmake and GPRbuild respectively. These macros '''MUST''' be used in packages that are built with Gnatmake or GPRbuild. In case the package's build system invokes the underlying GNAT tools without using Gnatmake or GPRbuild, then the appropriate macro for each tool '''MUST''' be used. If for example Gnatlink is invoked directly, then the expansion of Gnatlink_flags shall be passed to it.
 +
 
 +
* The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. When there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this '''MUST''' be done with "<code>ExclusiveArch: %{GNAT_arches}</code>".
  
All packages that contain Ada code '''MUST''' have "<code>BuildRequires: fedora-gnat-project-common</code>" to ensure that the necessary RPM macros are defined.
+
* All packages that contain Ada code '''MUST''' have "<code>BuildRequires: fedora-gnat-project-common</code>" to ensure that the necessary RPM macros are defined.
  
If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.
+
* If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.
  
 
== Devel packages ==
 
== Devel packages ==
  
 
* Ada library packages '''MUST''' have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr).
 
* Ada library packages '''MUST''' have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr).
* The -devel package '''MUST NOT''' contain all the source files of the library, only those that are necessary for compilation of code that uses the library.
 
 
* The -devel package '''MUST NOT''' contain any makefiles or other files that are only used for recompiling the library.
 
* The -devel package '''MUST NOT''' contain any makefiles or other files that are only used for recompiling the library.
 
* The -devel package '''MUST NOT''' contain any *.o files.
 
* The -devel package '''MUST NOT''' contain any *.o files.

Revision as of 22:28, 13 February 2012

Contents

Discussion

This is a draft proposal to make some changes to the Ada packaging guidelines. The changes are not yet ready for review by the Packaging Committee.

Source code in -devel packages

There is currently a rule that a -devel package must not contain all the source files of the library, only those that are necessary for compilation of code that uses the library. I think that this rule costs more than it's worth. It's very difficult for a reviewer to know which files are needed and which ones aren't. The GNAT tools know of course, and will install only the needed files, but not all Ada projects use the GNAT tools to do the installation. Manually keeping track of which body files are needed for recompilation can be error-prone even for upstream developers, so Make-based build systems are likely to just install the complete sources, and it would be a lot of work for a packager to rework makefiles to make them follow the rule.

The code is free so we have no reason to hide it, and disk space won't be an issue on developers' workstations or on build servers. Thus I think the rule should be removed. We could keep it as a "should not", but then I expect that the guideline would be followed only when the upstream buildsystem follows it. Such a guideline wouldn't make any difference, so it's better to remove it.

Macros with compiler and linker flags

When RPMbuild was packaged it turned out that passing the same command line parameters to RPMbuild as to Gnatmake wasn't optimal, so we replaced GNAT_optflags with two different macros: Gnatmake_optflags and GPRbuild_optflags. It might also happen that some package's build system invokes the underlying GNAT tools directly for some reason, without using Gnatmake or GPRbuild, in which case the packager may need to add some parameters for those tools.

The sentences "The RPM macro %{GNAT_optflags} MUST be used in the compilation. It contains the standard Fedora optimization flags adapted to GNAT." should be replaced with the following paragraph:

The RPM macros Gnatmake_optflags and GPRbuild_optflags expand to Fedora's standard compiler and linker flags adapted for Gnatmake and GPRbuild respectively. These macros MUST be used in packages that are built with Gnatmake or GPRbuild. In case the package's build system invokes the underlying GNAT tools without using Gnatmake or GPRbuild, then the appropriate macro for each tool MUST be used. If for example Gnatlink is invoked directly, then the expansion of Gnatlink_flags shall be passed to it.

GNAT_arches

Maintainers of some secondary architectures want to prevent build attempts that would always fail because they haven't bootstrapped GNAT on their architectures. A macro has been defined to help with this. I propose to add the following paragraph to the Compilation section:

The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. When there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this MUST be done with "ExclusiveArch: %{GNAT_arches}".

Category

Although the current Ada guidelines were approved on the 23rd of February 2011, the page is still in the Packaging guidelines drafts category. If I understand the process right it should be moved to the Packaging guidelines category.

Proposed new wording

The full text with the proposed changes follows below.

Packaging Ada programs and libraries

This document describes the current policies for packaging Ada programs and libraries for Fedora. These are Ada-specific amendments to the generic Packaging Guidelines. Ada packages must also conform to the Packaging Guidelines and the Review Guidelines.

Compilation

  • Ada code in Fedora MUST be compiled using GNAT, the default Ada compiler in Fedora. All packages that contain Ada code MUST have "BuildRequires: gcc-gnat" to ensure that the compiler is available.
  • The RPM macros Gnatmake_optflags and GPRbuild_optflags expand to Fedora's standard compiler and linker flags adapted for Gnatmake and GPRbuild respectively. These macros MUST be used in packages that are built with Gnatmake or GPRbuild. In case the package's build system invokes the underlying GNAT tools without using Gnatmake or GPRbuild, then the appropriate macro for each tool MUST be used. If for example Gnatlink is invoked directly, then the expansion of Gnatlink_flags shall be passed to it.
  • The macro GNAT_arches expands to a list of architectures where GNAT packages are available in Fedora. When there is a need to prevent attempts to build an Ada package on secondary architectures where GNAT has not been bootstrapped, this MUST be done with "ExclusiveArch: %{GNAT_arches}".
  • All packages that contain Ada code MUST have "BuildRequires: fedora-gnat-project-common" to ensure that the necessary RPM macros are defined.
  • If the upstream source package comes with a build system, for example a GNAT project file or makefiles and a configuration script, then it's probably best to use that if possible. If not, it is recommended that the packager write a GNAT project file to control the compilation.

Devel packages

  • Ada library packages MUST have a -devel subpackage containing all the files that are necessary for compilation of code that uses the library. This includes Ada specification files (*.ads), Ada body files (*.adb), Ada library information files (*.ali) and GNAT project files (*.gpr).
  • The -devel package MUST NOT contain any makefiles or other files that are only used for recompiling the library.
  • The -devel package MUST NOT contain any *.o files.

GNAT project files

  • The -devel package MUST contain one or more GNAT project files to be imported by other projects that use the library.
  • Project files MUST be architecture-independent. This means that the same project file must point to libraries in /usr/lib or /usr/lib64 depending on what target architecture the compiler is currently compiling for. This SHOULD be done by importing the "directories" project (that is, the project file directories.gpr) and using the variable Directories.Libdir which is defined there. The value of Directories.Libdir is set to either "/usr/lib" or "/usr/lib64" depending on the hardware platform.
  • Project files MUST NOT contain hard-coded directory names, neither absolute nor relative; they should get them from some source. The source may be an Autoconf-generated configuration script or other build system. Project files that aren't pre-processed by such a build system SHOULD use the variable Directories.Includedir rather than a hard-coded "/usr/include".
  • If the "directories" project is used, then the -devel package MUST have an explicit "Requires: fedora-gnat-project-common >= 2".
  • Project files MUST have an Externally_Built attribute equal to "true".

Here's an example of what a project file installed with a library may look like:

with "directories";
project Example is
   for Library_Name use "example";
   for Source_Dirs use (Directories.Includedir & "/example");
   for Library_Dir use Directories.Libdir;
   for Library_ALI_Dir use Directories.Libdir & "/example";
   for Externally_Built use "true";
end Example;

File placement

  • Ada source files in -devel packages (*.ads and *.adb) MUST be placed in the %{_includedir} directory or a subdirectory thereof. Placing them directly in %{_includedir} may be appropriate if there are very few of them in the package and their names include the name of the library. Otherwise they should usually be placed in a subdirectory, for example %{_includedir}/%{name}.
  • Ada library information files (*.ali) MUST be placed in a subdirectory of %{_libdir}, for example %{_libdir}/%{name}.
  • GNAT projects files (*.gpr) MUST be placed in the %{_GNAT_project_dir} directory or a subdirectory thereof. A subdirectory, for example %{_GNAT_project_dir}/%{name}, may be a good idea if there are lots of project files in the same package or if they have generic names. Otherwise they should usually be placed directly in %{_GNAT_project_dir}. The name of the library MUST be included either in the name of each project file or in the name of the subdirectory where the project files are placed.
Note.png
Note
The current value of %{_GNAT_project_dir} is /usr/lib/gnat. We intend to change it to /usr/share/gpr, which is more in line with FHS, if we can get GNAT to use that directory.

Rpmlint and Ada packages

Rpmlint is a program that checks packages for common problems. For Ada packages, some of the rpmlint messages, such as "executable-stack", can be disregarded, because GNAT uses trampolines for pointers to nested functions. (See for example this entry in the GCC Bugzilla.)