Perl Example: Hello World Perl Script Package With a Data File

This next example has hello-world.pl reading a data file. The main problem here is that because of relocatability, the script cannot know where the data file is located. To solve this the script reads the environmental variable $GPT_INSTALL_LOCATION[3] to find the file. The new script looks like this:

#! /usr/bin/env perl

print "Hello World\n";

# Get the value of the $GPT_INSTALL_LOCATION variable
my $installdir= $ENV{'GPT_INSTALL_LOCATION'};

die "Need to set \$GPT_INSTALL_LOCATION\n" if ! defined $installdir;

open CFG, "$installdir/etc/hello_world.data";

my @contents =  <CFG> ;

print @contents;

The filelist needs to list the new data file which we will install in $GPT_INSTALL_LOCATION/etc. The packaging data file also needs to change. In this file, the first thing to do is to increment the minor version number. We do this because we want to make sure that when the package is built or installed, it will replace the package from the previous example.

Incrementing Major and Minor version numbers is a judgement call. The rule of the thumb is that the Major number is incremented if the runtime interface changes. In this case, the run time interface is the command line invocation of the script. If we add command switches to the script, change its name, or add another script then the Major number should be incremented[4]. The new header looks like this:


<gpt_package_metadata Name="hello_world" Format_Version="0.02">

    <Aging_Version Major="0" Minor="1" Age="0"/>
    <Description >Simple Packaging Example</Description>
    <Version_Stability Release="Experimental"/>

Running gpt-build on these new changes produces the following:

bash$ gpt-build
gpt-build ====> CHECKING BUILD DEPENDENCIES FOR hello_world
gpt-build ====> Changing to /home/mbletzin/nmi/gpt-docs/examples/hello_world2
gpt-build ====> BUILDING FLAVOR 
gpt-build ====> Changing to /home/mbletzin/install/globus/etc
gpt-build ====> REMOVING empty package hello_world-noflavor-dev
WARNING: "/home/mbletzin/install/globus/etc/hello_world.data" not found
gpt-build ====> REMOVING empty package hello_world-noflavor-rtl

This shows that we forgot to add an installation command for the data file. GPT will produce warnings for any files listed in the filelist that are missing from the installation. When the packaged is archived, these missing files produce errors because native package managers cannot handle missing files[5].

Here are the fixed build instructions:



    <Build_Instructions>

      <Build_Step>mkdir -p INSTALLDIR_GPTMACRO/bin</Build_Step>
      <Build_Step>cp hello-world.pl INSTALLDIR_GPTMACRO/bin</Build_Step>
      <Build_Step>mkdir -p INSTALLDIR_GPTMACRO/etc</Build_Step>
      <Build_Step>cp hello_world.data INSTALLDIR_GPTMACRO/etc</Build_Step>
      <Build_Step>chmod 755 INSTALLDIR_GPTMACRO/bin/hello-world.pl</Build_Step>

    </Build_Instructions>

The complete set of files for this package can be found here.



[3] Any variable will do but this one is already set.

[4] When the Major number changes then the Age also may need to be adjusted to indicate backwards compatibility. Of the three interface changes mentioned, The script addition is backwards compatible, the name change is not, and the command switch addition can be if the default invocation has not changed. If the change is backwards compatible then the Age is also incremented.

[5] On a related issue GPT has no way of checking if a file is missing from the filelist and so it is always a good idea to test an installation created from binary packages to make sure nothing is missing.