Subversion Repositories DevTools

Rev

Rev 6898 | Rev 7326 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
6177 dpurdie 3
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description:
11
#       This is a wrapper script to simplify access to the jats
12
#       build system
13
#
14
# Usage:        jats build | make | install | help | ...
15
#
229 dpurdie 16
# Package: PACKAGE_TAG
17
# Version: VERSION_TAG
227 dpurdie 18
#......................................................................#
19
 
261 dpurdie 20
require 5.008_002;
227 dpurdie 21
use strict;
22
use warnings;
23
 
24
use Cwd;
25
use File::Copy;
26
use Getopt::Long qw(:config require_order);     # Stop on non-option
27
use FindBin;                                    # Determine the current directory
28
use lib "$FindBin::Bin/LIB";                    # Allow JATS libraries
29
use Config;
30
use Sys::Hostname;                              # For hostname
31
 
315 dpurdie 32
use Pod::Usage;                                 # For help support
227 dpurdie 33
use JatsError;                                  # Common error reporting
34
use DescPkg;                                    # Package Descriptor processing
35
use JatsSystem;                                 # System call interface
245 dpurdie 36
use JatsBuildFiles;                             # Parse Build Files
227 dpurdie 37
 
229 dpurdie 38
my $GBE_VERSION = "VERSION_TAG";                # Will be re-written when released
399 dpurdie 39
my $GBE_NOT_RELEASED = "RELEASE_TAG";           # Will be re-written (to empty) when released
227 dpurdie 40
my $opr_done;
41
my $opt_here = 0;
42
my $BUILD_FILE      = "build.pl";
43
my @BUILD_FILE_ALT  = qw(auto.pl build_test.pl);
44
my $BUILD_FILE_SET;
45
my $RESULT = 0;
46
my $PSPLIT = ':';                               # Win/Unix path splitter
47
my $opt_time = 0;
48
my $opt_help = 0;
49
my $opt_locate = 0;
50
my $opt_locate_file;
245 dpurdie 51
my $opt_locate_package;
319 dpurdie 52
my $opt_locate_dir;
227 dpurdie 53
my $opt_dir;
54
my $opt_java;
277 dpurdie 55
my $opt_export_vars = 1;
227 dpurdie 56
my $result;
379 dpurdie 57
my $opt_logfile;
6177 dpurdie 58
my $opt_script;
4902 dpurdie 59
my $notaBuildMachine = 0;
5848 dpurdie 60
my @opt_buildfilter;
227 dpurdie 61
 
62
#
63
#   Grab a copy of ALL the environment variable that will be used
64
#   This will simplify the script a great deal
65
#
66
 
279 dpurdie 67
our $GBE_JATS_VERSION   = $ENV{'GBE_JATS_VERSION'}   || '';
227 dpurdie 68
our $GBE_JATS_SANE      = $ENV{'GBE_JATS_SANE'}      || 0;
279 dpurdie 69
our $GBE_CORE           = $ENV{'GBE_CORE'}           || '';
70
our $GBE_BIN            = $ENV{'GBE_BIN'}            || '';
71
our $GBE_CONFIG         = $ENV{'GBE_CONFIG'}         || '';
72
our $GBE_DPLY           = $ENV{'GBE_DPLY'}           || '';
73
our $GBE_DPKG           = $ENV{'GBE_DPKG'}           || '';
4688 dpurdie 74
our $GBE_DPKG_REPLICA   = $ENV{'GBE_DPKG_REPLICA'}   || '';
279 dpurdie 75
our $GBE_DPKG_STORE     = $ENV{'GBE_DPKG_STORE'}     || '';
76
our $GBE_DPKG_LOCAL     = $ENV{'GBE_DPKG_LOCAL'}     || '';
6276 dpurdie 77
our $GBE_DPKG_ESCROW    = $ENV{'GBE_DPKG_ESCROW'}    || '';
279 dpurdie 78
our $GBE_DPKG_CACHE     = $ENV{'GBE_DPKG_CACHE'}     || '';
79
our $GBE_DPKG_SBOX      = $ENV{'GBE_DPKG_SBOX'}      || '';
80
our $GBE_SANDBOX        = $ENV{'GBE_SANDBOX'}        || '';
81
our $GBE_PERL           = $ENV{'GBE_PERL'}           || '';
82
our $GBE_TOOLS          = $ENV{'GBE_TOOLS'}          || '';
83
our $GBE_MACHTYPE       = $ENV{'GBE_MACHTYPE'}       || '';
273 dpurdie 84
our $GBE_HOSTMACH       = $ENV{'GBE_HOSTMACH'}       || $GBE_MACHTYPE;
279 dpurdie 85
our $GBE_PLATFORM       = $ENV{'GBE_PLATFORM'}       || '';
86
our $GBE_BUILDFILTER    = $ENV{'GBE_BUILDFILTER'}    || '';
227 dpurdie 87
our $GBE_DEBUG          = $ENV{'GBE_DEBUG'}          || 0;
88
our $GBE_VERBOSE        = $ENV{'GBE_VERBOSE'}        || 0;
279 dpurdie 89
our $GBE_DRV            = $ENV{'GBE_DRV'}            || '';
90
our $GBE_HOSTNAME       = $ENV{'GBE_HOSTNAME'}       || hostname || '';
91
our $USER               = $ENV{'USER'}               || '';
92
our $PERL5LIB           = $ENV{'PERL5LIB'}           || '';
93
our $JAVA_HOME          = $ENV{'JAVA_HOME'}          || '';
94
our $GBE_ABT            = $ENV{'GBE_ABT'}            || '';
343 dpurdie 95
our $GBE_VIEWBASE       = $ENV{'GBE_VIEWBASE'}       || '';
3967 dpurdie 96
our $GBE_VCS            = $ENV{'GBE_VCS'}            || 'SVN';
399 dpurdie 97
our $GBE_UNIX           = $^O ne "MSWin32" ;
227 dpurdie 98
our $CWD;
99
 
100
#-------------------------------------------------------------------------------
101
#   Clean up some environment variables
245 dpurdie 102
#       GBE_BUILDFILTER - may be space or comma separated list
103
#       GBE_PLATFORM - may be space or comma separated list
104
#       GBE_ABT - may be space or comma separated list
279 dpurdie 105
#       GBE_HOSTNAME - No whitespace
361 dpurdie 106
#       GBE_VCS - lowercase to match command ccrelease and others
227 dpurdie 107
#
108
$GBE_BUILDFILTER = join (' ', split( /[,\s]+/, $GBE_BUILDFILTER));
109
$GBE_PLATFORM    = join (' ', split( /[,\s]+/, $GBE_PLATFORM));
110
$GBE_ABT         = join (' ', split( /[,\s]+/, $GBE_ABT));
279 dpurdie 111
$GBE_HOSTNAME    =~ s~\s+~~g;
361 dpurdie 112
$GBE_VCS         = lc( $GBE_VCS );
227 dpurdie 113
 
4902 dpurdie 114
# Capture NON Build Machine config before parsing the command line
4928 dpurdie 115
#   Yes the user can still fudge the environment
116
if (exists $ENV{GBE_ABT} && $ENV{GBE_ABT} eq 'NONE' )
117
{
118
    $GBE_ABT = '';
119
    $notaBuildMachine = 1;
120
}
4902 dpurdie 121
 
227 dpurdie 122
#-------------------------------------------------------------------------------
123
#   Parse the user options
124
#   GetOptions has been configured so that it will stop parsing on the first
125
#   non-options. This allows the command syntax to the script to have options
126
#   that are directed to this script before the command keyword, and command
127
#   options to the subcommand to be after the keyword.
128
#
129
$result = GetOptions (
261 dpurdie 130
            "help|h:+"          => \$opt_help,
131
            "manual:3"          => \$opt_help,
132
            "verbose|v:+"       => \$GBE_VERBOSE,
133
            "debug:+"           => \$GBE_DEBUG,
227 dpurdie 134
            "cd|changedir=s"    => \$opt_dir,
135
            "locate"            => \$opt_locate,
136
            "locatefile=s"      => \$opt_locate_file,
245 dpurdie 137
            "locatepkg=s"       => \$opt_locate_package,
319 dpurdie 138
            "locatedir=s"       => \$opt_locate_dir,
227 dpurdie 139
            "here"              => \$opt_here,
140
            "time"              => \$opt_time,
141
            "b|buildfile=s"     => \&opts_buildfile,
245 dpurdie 142
            "java=s"            => \$opt_java,
227 dpurdie 143
            "version=s",        => \&opts_version,
144
            "platform:s",       => sub{ opts_extend( \$GBE_PLATFORM, @_ )},
5848 dpurdie 145
            "buildfilter:s"     => \@opt_buildfilter,
227 dpurdie 146
            "abt:s"             => sub{ opts_extend( \$GBE_ABT, @_ )},
277 dpurdie 147
            "exportvars!"       => \$opt_export_vars,
379 dpurdie 148
            "logfile=s",        => \$opt_logfile,
6177 dpurdie 149
            "script!",          => \$opt_script,
227 dpurdie 150
            );
151
 
152
#
153
#   Configure the error reporting process now that we have the user options
154
#
155
ErrorConfig( 'name'    => 'JATS',
156
             'debug'   => $GBE_DEBUG,
157
             'verbose' => $GBE_VERBOSE );
158
#
159
#   Post process some of the options
160
#
161
Error ("Options not parsed. Use -help for help") unless $result;
263 dpurdie 162
Verbose3 ('ARGS', @ARGV);
227 dpurdie 163
 
164
#
165
#   Option Helper Routine
166
#   Save alternate buildfile. Flag that it has been set
167
#
168
sub opts_buildfile
169
{
283 dpurdie 170
    my ($junk, $bf) = @_;
171
    $BUILD_FILE = $bf;
227 dpurdie 172
    $BUILD_FILE_SET = 1;
173
    Verbose ("Use alternate buildfile: $BUILD_FILE");
283 dpurdie 174
    return;
227 dpurdie 175
}
176
 
177
#
178
#   Options Helper Routine
179
#   Collect a space/comma delimited list and replace/append to string
180
#   Allows the string to be reset
181
#   Use of a +" will append to existing value
182
#
183
#       arg1 - Ref to string to store data
184
#       arg2 - Option name
185
#       arg3 - Option value
186
#
187
sub opts_extend
188
{
189
    my( $ref, $name, $value) = @_;
190
    if ( $value )
191
    {
192
        $value =~ s/,/ /g;
193
        $value = ${$ref} . ' ' . $value
194
            if ( $value =~ s/\+/ /g );
195
        $value =~ s/^\s+//;
196
        $value =~ s/\s+/ /;
197
    }
198
    ${$ref} = $value;
283 dpurdie 199
    return;
227 dpurdie 200
}
201
 
202
#
203
#   Options Helper routine
204
#   Collect --version=version, then stop processing of the command line
205
#   This will simulate a '--'
206
#
207
sub opts_version
208
{
283 dpurdie 209
    my ($junk, $vn) = @_;
210
    $GBE_JATS_VERSION = $vn;
211
    die("!FINISH\n");
227 dpurdie 212
}
213
 
214
################################################################################
215
#
216
#   Ensure that essential environment variables are present and that they
217
#   do not contain spaces.
218
#
219
ReportError('Set env-var GBE_PERL (typically "/usr/bin/perl")')   unless ( $GBE_PERL );
229 dpurdie 220
ReportError('Set env-var GBE_DPKG (typically "/devl/dpkg_archive")') unless ( $GBE_DPKG );
221
ReportError('Set env-var GBE_CORE (typically "/devl/dpkg_archive/PACKAGE_TAG/VERSION_TAG")')  unless ( $GBE_CORE );
279 dpurdie 222
ReportError('Hostname cannot be determined') unless ( $GBE_HOSTNAME );
227 dpurdie 223
 
229 dpurdie 224
################################################################################
225
#
226
#   Warn if using a version of perl that is newer than expected
227
#   The 'require' does a lower limit test
228
#
341 dpurdie 229
#   Notes:
230
#       Ubuntu 9.04 provides Perl 10 - don't complain
231
#       PDK is only available on Windows
232
#
233
if ( ! $GBE_JATS_SANE && ! $GBE_UNIX)
283 dpurdie 234
{
235
    Warning ("Perl Version may not be compatible",
236
             "Jats has been tested with: 5.8.8",
237
             "This version is: $]",
238
            ) if ( $] > 5.010000 );
227 dpurdie 239
 
399 dpurdie 240
    Warning ("The PDK, as used by some deployed packages does not work with",
241
             "this version of perl. VIX only has a licence for PDK V5 and",
242
             "this only works with Perl 5.6 and 5.8.",
283 dpurdie 243
             "This version is: $]",
244
            ) if ( $] > 5.009000 );
245
}
229 dpurdie 246
 
247
#
248
#   Warn if this is not an active state release
249
#
250
#   Would be nice, but I can't figure out how to do it - yet
251
#   The following does not work on all platforms
252
#
253
#unless ( $ActivePerl::VERSION )
254
#{
255
#    Warning ("Perl does not appear to be an ActiveState Release", "Jats may not function as expected");
256
#}
257
#else
258
#{
259
#    Verbose ("ActiveState Version: $ActivePerl::VERSION");
260
#}
261
 
227 dpurdie 262
################################################################################
229 dpurdie 263
#
245 dpurdie 264
#   Warn if this version of JATS is not correctly versioned
229 dpurdie 265
#   Users should be using correctly versioned copies of JATS. These come
266
#   from dpkg_archive.
267
#
399 dpurdie 268
#   Display warnings at the end of the run
269
#   This is an attempt to make them visible to the user
270
#
271
my @endWarnings;
272
if ( ! $GBE_JATS_SANE && $GBE_NOT_RELEASED ) {
273
    @endWarnings = ( "*** Unofficial version of JATS ***");
274
} else {
229 dpurdie 275
 
399 dpurdie 276
    #
277
    #   Windows only
278
    #   Attempt to detect JATS no being run via the jats2_current link
279
    #
1329 dpurdie 280
    unless  ( $GBE_UNIX || $GBE_JATS_SANE || $GBE_ABT || $GBE_CORE =~ m~core_devl[/\\]jats2_current~ ) {
399 dpurdie 281
        @endWarnings =
282
            ("***",
283
             "*** Jats is being invoked from a batch file that does not ",
284
             "*** automatically track the latest version. Update jats.bat",
285
             "*** so that GBE_CORE references core_devl/jats2_current",
286
             "***"
287
             );
288
    }
289
}
290
 
291
#-------------------------------------------------------------------------------
292
# Function        : END
293
#
294
# Description     : Display user warnings at the end of the processing
6177 dpurdie 295
#                   unless we are processing with a script
399 dpurdie 296
#
297
# Inputs          : global: @endWarnings
298
#
299
END
300
{
301
    Message (@endWarnings)
6177 dpurdie 302
        if ( @endWarnings && !$opt_script );
399 dpurdie 303
}
304
 
229 dpurdie 305
################################################################################
227 dpurdie 306
#   If running with cygwin then warn if the CYGWIN environment variable
307
#   contains "tty". tty mode causes some strange behaviour such as:
308
#       1) Non flushing of perl scripts under some conditions (eg:create_dpkg)
309
#
310
if ( $ENV{'CYGWIN'} && $ENV{'CYGWIN'} =~ m/tty/ )
311
{
312
    Warning ("The CYGWIN variable contains \"tty\".",
313
             "This can cause strange behaviour with interactive scripts");
314
}
315
 
316
#
317
#   Remove CDPATH - this breaks things when cygwin is running
318
#   even if we are not running under cygwin perl
319
#
320
delete $ENV{'CDPATH'};
321
 
322
 
323
################################################################################
324
#   Sanitize GBE_CORE and others for internal Perl use
325
#   It may contain \ to be added to PATH but within perl is needs /
326
#
327
$PERL5LIB =~ tr~\\/~/~s;
328
 
329
TestDirectoryConfig( 'GBE_CORE' );
330
TestDirectoryConfig( 'GBE_BIN' );
331
TestDirectoryConfig( 'GBE_PERL' );
332
TestDirectoryConfig( 'GBE_DPLY' );
333
TestDirectoryConfig( 'GBE_DPKG' );
334
TestDirectoryConfig( 'GBE_DPKG_CACHE' );
335
TestDirectoryConfig( 'GBE_DPKG_LOCAL' );
336
TestDirectoryConfig( 'GBE_DPKG_STORE' );
4688 dpurdie 337
TestDirectoryConfig( 'GBE_DPKG_REPLICA' );
6276 dpurdie 338
TestDirectoryConfig( 'GBE_DPKG_ESCROW' );
227 dpurdie 339
TestDirectoryConfig( 'GBE_DPKG_SBOX' );
340
TestDirectoryConfig( 'GBE_SANDBOX' );
341
 
342
################################################################################
343
#   Setup the Machine Type
344
#
345
#   GBE_MACHTYPE is used to determine the BIN directory from which JATS will
346
#   pull local binary executables from. The directory must exist.
347
#
348
#   We need GBE_MACHTYPE to be correctly defined by the user
349
#   This is machine specific and should be done in jats.sh/jats.bat
350
#
351
unless ( $GBE_MACHTYPE )
352
{
353
    $GBE_MACHTYPE = 'win32' if ( $^O eq "cygwin" );
354
    $GBE_MACHTYPE = 'win32' if ( $^O eq "MSWin32" );
355
    $GBE_MACHTYPE = 'win32' if ( $^O eq "win95" );
7009 dpurdie 356
    $GBE_HOSTMACH = $GBE_MACHTYPE;
227 dpurdie 357
    Verbose ("Setting GBE_MACHTYPE: $GBE_MACHTYPE") ;
358
}
359
 
360
ReportError ('Set env-var GBE_MACHTYPE (typically "win32")') unless ( $GBE_MACHTYPE );
361
ErrorDoExit();
362
 
7009 dpurdie 363
if ( $GBE_HOSTMACH eq 'win32' )
227 dpurdie 364
{
365
    $PSPLIT = ';';
366
    $GBE_UNIX = 0;
367
}
368
 
369
################################################################################
370
#   Windows: If the user is running JATS from within the development view
371
#   then they may not provide a drive letter in the full name of GBE_CORE
372
#   For correct operation GBE_CORE needs to be able to run programs and
373
#   scripts from any other drive
374
#
375
#   If GBE_CORE does not have a driver letter - then add one
376
#   Note: Use the CWD before any CD operations
377
#
7009 dpurdie 378
if ( $GBE_HOSTMACH eq 'win32'  && $GBE_CORE !~ m/^\w\:/ )
227 dpurdie 379
{
380
        my $cwd = getcwd();
381
        $GBE_CORE = substr( $cwd, 0, 2 ) . '/' . $GBE_CORE;
382
        $GBE_CORE =~ s~//~/~g;
383
        Verbose2 ("Setting GBE_CORE drive: $GBE_CORE");
384
}
385
 
386
################################################################################
387
#   Attempt to run JATS from a local cache
388
#   This mechanism allows JATS to be a link to a desired version on a network
389
#   drive, but to have the version transferred locally if required
390
#
229 dpurdie 391
#   The transfer/check is only done on the first invocation of jats. If jats uses
245 dpurdie 392
#   jats to perform functions, then it will not be performed.
229 dpurdie 393
#
245 dpurdie 394
#   If we want to run an alternate version of JATS, then don't attempt to
229 dpurdie 395
#   cache the initial version of JATS.
396
#
227 dpurdie 397
if ( $ENV{GBE_CACHE_JATS} && ! $GBE_JATS_SANE && ! $GBE_JATS_VERSION)
398
{
399
    my $state = "Not Cached: Not running from dpkg_archive";
400
    #
401
    #   Must have the DPKG_ARCHIVE cache
229 dpurdie 402
    #   Must be running from DPKG_ARCHIVE - prevent messing with local copies
227 dpurdie 403
    #
404
    if ( $GBE_DPKG_CACHE )
405
    {
229 dpurdie 406
        #
407
        #   JATS must be running from an archive, otherwise we assume that its
408
        #   a local copy. Detected by:
409
        #       GBE_NOT_RELEASED being set
410
        #       Lack of descpkg file
411
        #
412
        if ( ! $GBE_NOT_RELEASED  && -f "$GBE_CORE/descpkg" )
227 dpurdie 413
        {
4688 dpurdie 414
            my ($archive, $package, $aName) = LocateJatsVersion( $GBE_VERSION );
229 dpurdie 415
            if ( $archive )
416
            {
417
                #
4688 dpurdie 418
                #   If the required version is found in the cache, then use it
419
                #   This will bypass the slowish process of invoking cache_dpkg
420
                #   at the expense of not being able to handle situations where
421
                #   version is updated on the fly
229 dpurdie 422
                #
4688 dpurdie 423
                if (($aName ne 'GBE_DPKG_CACHE') && ( $ENV{GBE_CACHE_JATS} < 2))
283 dpurdie 424
                {
4688 dpurdie 425
                    Verbose ("Update cached version of JATS: $GBE_VERSION");
426
                    #
427
                    #   Attempt to cache the package
428
                    #   Need enough JATS environment to run the cache_dpkg utility
429
                    #
430
                    {
431
                        local %ENV = %ENV;
227 dpurdie 432
 
4688 dpurdie 433
                        $ENV{GBE_TOOLS} = "$GBE_CORE/TOOLS";
434
                        $ENV{PERL5LIB} = "$GBE_CORE/TOOLS/LIB" ;
7009 dpurdie 435
                        $ENV{GBE_BIN}  = "$GBE_CORE/BIN.$GBE_HOSTMACH";
4688 dpurdie 436
                        $ENV{GBE_VERBOSE}  = $GBE_VERBOSE;
227 dpurdie 437
 
4688 dpurdie 438
                        etool ( 'cache_dpkg.pl', $package );
439
                    }
283 dpurdie 440
                }
4688 dpurdie 441
                else
442
                {
443
                    Verbose("Required version found in cache");
444
                }
227 dpurdie 445
 
229 dpurdie 446
                my $tgt = "$GBE_DPKG_CACHE/$package";
447
                if ( -d $tgt )
448
                {
449
                    Verbose ("Using cached version of JATS: $GBE_VERSION");
450
                    $GBE_CORE = $tgt;
451
                    $state = "Cached";
452
                }
453
                else
454
                {
455
                    $state = "Not Cached: Copy Failure";
456
                }
227 dpurdie 457
            }
458
            else
459
            {
229 dpurdie 460
                $state = "Not Cached: Not found in archives";
227 dpurdie 461
            }
462
        }
463
    }
464
    else
465
    {
466
        $state = "Not Cached: No GBE_DPKG_CACHE";
467
    }
468
 
469
    #
470
    #   Flag JATS having been cached on the machine
471
    #
472
    $ENV{GBE_CACHE_JATS} = $state;
473
}
474
 
475
 
476
################################################################################
477
#   Establish a relationship between GBE_BIN, GBE_TOOLS and GBE_CONFIG
478
#   unless the user has already provided one.
479
#
480
#   Only NEED GBE_CORE - the others will be derived
481
#
482
unless ( $GBE_BIN )
483
{
484
    $GBE_BIN = "$GBE_CORE/BIN.$GBE_MACHTYPE";
485
    Verbose2 ("Setting GBE_BIN: $GBE_BIN");
486
}
487
ReportError ('GBE_MACHTYPE is not valid.',
488
             'There must be a corresponding BIN directory in GBE_CORE',
489
             "GBE_BIN     : $GBE_BIN",
490
             "GBE_MACHTYPE: $GBE_MACHTYPE"
491
             ) unless ( -d $GBE_BIN );
492
 
493
ReportError ('Machine specific binary directory does not appear to setup',
494
             'After JATS is installed the PostInstall script must be run',
495
             "GBE_BIN     : $GBE_BIN"
496
             ) unless ( -x $GBE_BIN . '/sh' || -x $GBE_BIN . '/sh.exe'  );
497
 
498
unless ( $GBE_TOOLS )
499
{
500
    $GBE_TOOLS = "$GBE_CORE/TOOLS";
501
    Verbose2 ("Setting GBE_TOOLS: $GBE_TOOLS");
502
}
503
 
504
unless ( $GBE_CONFIG )
505
{
506
    $GBE_CONFIG = "$GBE_CORE/CFG";
507
    Verbose2 ("Setting GBE_CONFIG: $GBE_CONFIG");
508
}
509
 
510
#
511
#   Extend the PERL5 with our own Module Repository
512
#
513
$PERL5LIB = join( $PSPLIT, split( $PSPLIT, $PERL5LIB), "$GBE_CORE/TOOLS/LIB" );
514
 
515
 
516
################################################################################
517
#   Sanity Test
518
#   The ABT environment requires several parameters to specify the location
519
#   of the Release/Deployment Managers
520
#
521
#   GBE_DM_LOCATION will be set GBE_RM_LOCATION, if not set
522
#
523
#   Only perform the test:
524
#       - On the first invocation of JATS, not nested invocations
525
#       - Based on the EnvVar, not the user option. This will allow a user
526
#         to invoke ABT without the need for these values to be present
527
#
528
if ( ! $GBE_JATS_SANE && $ENV{GBE_RM_LOCATION} && ! $ENV{GBE_DM_LOCATION} )
529
{
530
    $ENV{GBE_DM_LOCATION} = $ENV{GBE_RM_LOCATION};
531
}
532
 
533
if ( ! $GBE_JATS_SANE && $ENV{GBE_ABT} )
534
{
535
    foreach my $var ( qw(GBE_DM_LOCATION GBE_DM_USERNAME GBE_DM_PASSWORD GBE_RM_URL))
536
    {
537
        Warning("Deployment Manager EnvVar may need to be defined: $var") unless ( $ENV{$var} );
538
    }
539
 
540
    foreach my $var ( qw(GBE_RM_LOCATION GBE_RM_USERNAME GBE_RM_PASSWORD GBE_DM_URL))
541
    {
542
        ReportError("Release Manager EnvVar needs to be defined: $var") unless ( $ENV{$var} );
543
    }
544
}
545
 
546
################################################################################
319 dpurdie 547
#   Locate a specified directory - normally a view root
548
#   Scan upwards from the current directory loccing for the specified path
227 dpurdie 549
#
319 dpurdie 550
if ( $opt_locate_dir )
551
{
552
    my ($path) = scan_for_dir ($opt_locate_dir);
553
    Error ("Cannot locate directory: $opt_locate_dir") unless ( $path );
554
    change_dir ( $path );
555
}
556
 
557
################################################################################
558
#
227 dpurdie 559
#   Change to the required root directory
560
#       The user may specify a start directory( -c )
561
#
562
change_dir ( $opt_dir );
245 dpurdie 563
 
564
################################################################################
565
#   Locate the root of the build - if required
566
#   This is used by the autobuild tools to:
567
#       1) Locate the build.pl file for JATS based builds
568
#          The name of the target package can be provided to resolve
569
#          cases of multiple build files.
570
#
571
#       2) Locate the <ProjectName>depends.xml file for ANT based builds
572
#          The name of the buildfile will be specified
573
#          There must be only one file of this name in the tree
574
#
575
#   Note: If only one build file is found, then it will be used
576
#         It will not be sanity tested. This is intentional
577
#         for backward compatability.
578
#
579
if ( $opt_locate || $opt_locate_file || $opt_locate_package )
227 dpurdie 580
{
245 dpurdie 581
    #
582
    #   Allow the user to specify the name of the build file
583
    #   This will be used in ANT builds as the name changes
584
    #   but it can be predetermined
585
    #
227 dpurdie 586
    $opt_locate_file = $BUILD_FILE unless ( $opt_locate_file );
587
 
245 dpurdie 588
    #
589
    #   Create a Build File Scanner object
590
    #   This will be used to locate a suitable build file
591
    #
227 dpurdie 592
    Verbose ("Autolocate the build file: $opt_locate_file");
593
 
245 dpurdie 594
    my $bscanner = BuildFileScanner ( '.', $opt_locate_file );
595
    my $count = $bscanner->locate();
596
 
597
    Error ("Autolocate. Build file not found: $opt_locate_file" )
598
        if ( $count <= 0 );
599
 
227 dpurdie 600
    #
245 dpurdie 601
    #   If multiple build files have been found
602
    #   If $opt_locate_package is set then we can attempt to resolve the package
227 dpurdie 603
    #
245 dpurdie 604
    #   Scan the buildfiles and determine the names of the packages that will
605
    #   be built. This can be used to generate nice error messages
606
    if ( $count > 1 )
607
    {
608
        $bscanner->scan();
609
        $count = $bscanner->match( $opt_locate_package );
610
#DebugDumpData ("Bscan", \$bscanner );
227 dpurdie 611
 
245 dpurdie 612
        my $errmess;
613
        unless ( $opt_locate_package ) {
614
            $errmess = "Use -locatepkg=pkg to resolve required package";
615
 
616
        } elsif ( $count <= 0 ) {
617
            $errmess = "None found that build package: $opt_locate_package";
618
 
619
        } elsif ( $count > 1 ) {
620
            $errmess = "Multiple build files build the required package: $opt_locate_package";
621
        }
622
 
623
        #
624
        #   Pretty error display
625
        #   Display build directory and the package name (mangled)
626
        #
627
        if ( $errmess )
628
        {
629
            Error ("Autolocate. Multiple build files found.",
630
                   $errmess,
631
                   "Build files found in:", $bscanner->formatData() );
632
        }
633
    }
634
 
227 dpurdie 635
    #
245 dpurdie 636
    #   Extract the required build file directory
227 dpurdie 637
    #
245 dpurdie 638
    my $dir = $bscanner->getMatchDir() || '';
639
    Verbose ("Autolocate. Found $count build files: $dir");
227 dpurdie 640
 
641
    #
642
    #   Select the one true build directory
643
    #
245 dpurdie 644
    change_dir ( $dir );
227 dpurdie 645
 
646
    #
647
    #   Kill location scan as we have already located the build file
648
    #
649
    $opt_here = 1;
650
}
651
 
652
################################################################################
653
#   Version redirection
654
#   JATS allows the version of JATS to be used to be specified
655
#   This mechanism operates on the assumption that the required version is
656
#   present in dpkg_archive. If a specific version is required then the bulk
657
#   of this script is bypassed and the arguments passed directly to the required
658
#   target
659
#
660
if ( $GBE_JATS_VERSION && $GBE_JATS_VERSION eq $GBE_VERSION )
661
{
662
    Message("Using current JATS version: $GBE_JATS_VERSION" );
663
    $GBE_JATS_VERSION = undef;
664
}
665
 
666
if ( $GBE_JATS_VERSION )
667
{
668
    #
669
    #   Report any errors detected
670
    #
671
    ErrorDoExit();
672
    Message("Using JATS version: $GBE_JATS_VERSION");
673
 
674
    #
245 dpurdie 675
    #   If we have a cache available, then attempt to transfer the required
676
    #   version into the cache. If we don't have a cache, then don't even try.
229 dpurdie 677
    #
245 dpurdie 678
    if ( $GBE_DPKG_CACHE )
679
    {
680
        #
681
        #   Attempt to locate the desired version in one of the well known
682
        #   package archives. This will give us its package name.
683
        #
684
        my ($archive, $package) = LocateJatsVersion ($GBE_JATS_VERSION);
685
        Error("Cannot find JATS version: $GBE_JATS_VERSION") unless $archive;
229 dpurdie 686
 
245 dpurdie 687
        #
688
        #   Do NOT propagate GBE_JATS_VERSION in the environment
689
        #   This will only cause problem in recursion
690
        #
691
        delete $ENV{GBE_JATS_VERSION};
227 dpurdie 692
 
245 dpurdie 693
        #
694
        #   Attempt to cache the package
695
        #   Need enough JATS environment to run the utility
696
        #
283 dpurdie 697
        {
698
            local %ENV = %ENV;
227 dpurdie 699
 
283 dpurdie 700
            $ENV{PERL5LIB} = $PERL5LIB;
701
            $ENV{GBE_BIN}  = $GBE_BIN;
702
            $ENV{GBE_VERBOSE}  = $GBE_VERBOSE;
703
            $ENV{GBE_TOOLS}  = $GBE_TOOLS;
227 dpurdie 704
 
283 dpurdie 705
            etool ( 'cache_dpkg.pl', $package );
706
        }
245 dpurdie 707
    }
227 dpurdie 708
 
709
    #
229 dpurdie 710
    #   Locate the version of JATS to be run (again)
227 dpurdie 711
    #   It should be in the cache, but it may not be
712
    #
245 dpurdie 713
    my ($archive, $package) = LocateJatsVersion ($GBE_JATS_VERSION);
229 dpurdie 714
    Error("Cannot find JATS version: $GBE_JATS_VERSION") unless $archive;
715
 
716
    $GBE_CORE = "$archive/$package";
227 dpurdie 717
    Verbose2 ("Using alternate version: $GBE_CORE");
718
 
719
    #
720
    #   Run the specified version of JATS
721
    #   Force the required version of GBE_CORE and invoke the wrapper script
722
    #
723
    $ENV{GBE_CORE} = $GBE_CORE;
724
 
725
    Verbose("Use ARGV: @ARGV");
726
    $RESULT = System ($GBE_PERL, "$GBE_CORE/TOOLS/jats.pl", @ARGV );
727
    do_exit();
728
}
729
 
730
################################################################################
731
#   Determine the current directory
732
#   Note: Don't use `pwd`. This sucks for so many reasons including
733
#         the fact that it may not be available until this wrapper
734
#         script has done it job.
735
#
736
$CWD = getcwd();
367 dpurdie 737
Error ("Cannot determine current directory - may be protected" )unless ( defined $CWD );
363 dpurdie 738
$CWD =~tr~\\/~/~s;
227 dpurdie 739
Verbose ("Current Working Directory: $CWD");
740
 
741
################################################################################
742
#   Setup drive
743
#   This is only required under windows
744
#   Purpose is unclear, but under windows it is required, so lets create one
745
#   if its not present
746
#
747
unless ( $GBE_UNIX )
748
{
749
    unless ( $GBE_DRV )
750
    {
751
        ($GBE_DRV = $CWD ) =~ s~[^:]*$~~;
752
        $GBE_DRV = "c:" if ( $GBE_DRV !~ m/:/ );
753
        Verbose2( "Setting GBE_DRV: $GBE_DRV" );
754
    }
755
}
756
 
757
################################################################################
758
#   Sanity test the main archive variable
759
#   This MUST address one archive
760
#
761
 
762
Error ("GBE_DPKG must not be a path list: $GBE_DPKG")
763
    if ( $GBE_DPKG =~ /$PSPLIT/ );
764
Error ("GBE_DPKG is not a directory : $GBE_DPKG")
765
    unless( -d $GBE_DPKG );
766
 
767
################################################################################
768
#   Sanity test the cache
769
#
770
Error ("GBE_DPKG_CACHE is not a directory : $GBE_DPKG_CACHE")
771
    if ( $GBE_DPKG_CACHE && ! -d $GBE_DPKG_CACHE );
772
 
773
################################################################################
774
#   Sanity test the global store
775
#
776
Error ("GBE_DPKG_STORE is not a directory : $GBE_DPKG_STORE")
777
    if ( $GBE_DPKG_STORE && ! -d $GBE_DPKG_STORE );
778
 
779
Error ("GBE_DPLY is not a directory : $GBE_DPLY")
780
    if ( $GBE_DPLY && ! -d $GBE_DPLY );
4688 dpurdie 781
 
782
Error ("GBE_DPKG_REPLICA is not a directory : $GBE_DPKG_REPLICA")
783
    if ( $GBE_DPKG_REPLICA && ! -d $GBE_DPKG_REPLICA );
6276 dpurdie 784
 
785
Error ("GBE_DPKG_ESCROW is not a directory : $GBE_DPKG_ESCROW")
786
    if ( $GBE_DPKG_ESCROW && ! -d $GBE_DPKG_ESCROW );
227 dpurdie 787
 
788
########################################################################
789
#
790
#       Locate a local_dpkg_archive directory, by searching from the CWD
791
#       to the root of the file system
792
#
793
unless ( $GBE_DPKG_LOCAL )
794
{
283 dpurdie 795
    ($GBE_DPKG_LOCAL) = scan_for_dir ('local_dpkg_archive');
227 dpurdie 796
}
797
else
798
{
799
    Error ("GBE_DPKG_LOCAL is not a directory : $GBE_DPKG_LOCAL")
800
        unless( -d $GBE_DPKG_LOCAL );
801
}
802
 
803
########################################################################
804
#
805
#       Locate a sandbox_dpkg_archive directory by searching from the CWD
806
#       to the root of the file system
807
#
241 dpurdie 808
#       sandbox_dpkg_archive is a dpkg_archive for packages that are being
809
#       co-developed. Package Versions within the sandbox are ignored
227 dpurdie 810
#
241 dpurdie 811
 
812
#
813
#   Ensure that the user does not set $GBE_SANDBOX or $GBE_DPKG_SBOX
814
#   $GBE_JATS_SANE will be set for multiple invocations, thus it is cleared
815
#   for the first one (unless the user messes with it).
816
#
817
unless ( $GBE_JATS_SANE )
227 dpurdie 818
{
241 dpurdie 819
    Error ("GBE_SANDBOX must not be set by the user") if ( $GBE_SANDBOX );
820
    Error ("GBE_DPKG_SBOX must not be set by the user") if ( $GBE_DPKG_SBOX );
821
 
822
    #
823
    #   The ABT does not use the sandbox
824
    #   It will never be found and will be ignored
825
    #
826
    unless ( $GBE_ABT )
827
    {
277 dpurdie 828
        ($GBE_DPKG_SBOX,$GBE_SANDBOX)  = scan_for_dir ('sandbox_dpkg_archive');
227 dpurdie 829
    }
3559 dpurdie 830
 
831
    #
832
    #   Support sandbox specific buildfilter
833
    #   Remove comments(#) and empty lines
834
    #
6198 dpurdie 835
    my $sbBuildFilter = $GBE_DPKG_SBOX . '/buildfilter';
836
    if ( $GBE_SANDBOX && -f $sbBuildFilter )
3559 dpurdie 837
    {
6198 dpurdie 838
        Verbose("sbBuildFilter:$sbBuildFilter");
839
        if ( open (my $BF, $sbBuildFilter ))
3559 dpurdie 840
        {
841
            my @bf;
842
            while ( <$BF> )
843
            {
844
                s~\s$~~;
845
                s~^\s~~;
846
                next unless ( $_ );
847
                next if ( m~^#~ );
848
                push @bf,$_;
849
            }
850
            close $BF;
851
            if ( @bf )
852
            {
853
                $GBE_BUILDFILTER = join (' ', split( /[,\s]+/, join(',', @bf)));
854
                Verbose ("Local BuildFilter: $GBE_BUILDFILTER");
855
            }
856
        }
857
    }
227 dpurdie 858
}
859
 
6403 dpurdie 860
#
861
#   Base buildfilter will be Machine or Sandbox
862
#   Now merge in user specified build filters
863
#
864
map opts_extend( \$GBE_BUILDFILTER, '', $_ ) , @opt_buildfilter;
865
 
227 dpurdie 866
########################################################################
867
#
868
#   Ensure that the user has been set
869
#   Under windows USER may not be set, but USERNAME may be
299 dpurdie 870
#   As a last resort, use getlogin data
227 dpurdie 871
#
872
$USER = $ENV{ 'USERNAME' } || '' unless ( $USER );
873
$USER = $ENV{ 'LOGNAME' }  || '' unless ( $USER );
299 dpurdie 874
$USER = getlogin()         || '' unless ( $USER );
301 dpurdie 875
ReportError ('Cannot determine USER name, via USER, USERNAME, LOGNAME or getlogin')
876
    unless ( $USER );
299 dpurdie 877
#Debug ("User: ", $USER, $ENV{ 'USERNAME'}, $ENV{ 'LOGNAME' }, getlogin() );
878
 
227 dpurdie 879
################################################################################
375 dpurdie 880
#   Sanitize the EnvVars for Windows
227 dpurdie 881
#
375 dpurdie 882
#   It appears the %ENV is magical (in Win32)
883
#   The keys are case insensitive, even though the underlying env is not
884
#       Some of the Win32 binary tools used by JATS cannot handle lower
1329 dpurdie 885
#       case envVars. In particular Path/PATH.
375 dpurdie 886
#       This will also fix some issues within MAKE
227 dpurdie 887
#
375 dpurdie 888
#   Force all EnvVars to be uppercase
889
#       Need to delete the entry then reset it
227 dpurdie 890
#
4192 dpurdie 891
#   Note: Under windows the %ENV hash is special. Inserts are forced to uppercase
892
#   Note: Have issues with VS2012 and Cygwin. We end up with EnvVar tmp and TMP
893
#         This causes VS2012 to fail.
894
#
375 dpurdie 895
unless ( $GBE_JATS_SANE || $GBE_UNIX )
896
{
4969 dpurdie 897
    foreach my $var (keys %ENV)
375 dpurdie 898
    {
4969 dpurdie 899
        my $val = $ENV{$var};
375 dpurdie 900
        delete $ENV{$var};
4192 dpurdie 901
        delete $ENV{lc($var)};
375 dpurdie 902
        $ENV{$var} = $val;
903
    }
904
}
1329 dpurdie 905
 
906
#
907
#   Have a very strange issue with Solaris X86 and the buildtool
908
#   The GBE_MACHTYPE disappears from the environment
909
#   For some reason, deleting the PATH EnvVar and recreating it will fix it.
910
#
375 dpurdie 911
my $PATH = $ENV{'PATH'};
1329 dpurdie 912
delete $ENV{'PATH'};
913
$ENV{'PATH'} = $PATH;
227 dpurdie 914
 
1329 dpurdie 915
 
227 dpurdie 916
################################################################################
917
#   There is some really ugly interaction between Cygwin, ActiveState Perl 5.8.2
918
#   and xmake. Even if none of the cygwin bits are used within JATS the fact that
919
#   Cygwin is in the path causes problems.
920
#
921
#   Problems seen:
922
#       1) "jats build"     xmake fails with a segment fault. Possibly when
923
#                           displaying an error message
924
#       2) Warnings and messages generated from within Perl don't always appear
925
#          In particular. The output from a Message() within a PLATFORM/xxx file
926
#          does not get displayed.
927
#
928
#   Solution:
929
#       Remove cygwin from the PATH
930
#
931
$PATH =~ s~c:\\cygwin[^;]*;~~ig;
932
 
933
################################################################################
297 dpurdie 934
#   Setup the default JAVA_HOME
935
#   User should specify 1.4, 1.5,1.6 ....
936
#
6898 dpurdie 937
$JAVA_HOME = get_java_home ($opt_java) if ( $opt_java );
938
PathPrepend ("$JAVA_HOME/bin") if ( -d $JAVA_HOME );
297 dpurdie 939
 
343 dpurdie 940
################################################################################
941
#   Setup GBE_VIEWBASE
942
#   Ideally this should be configured externally
943
#
944
unless ( $GBE_VIEWBASE )
945
{
946
    if ( $GBE_UNIX ){
947
        my $HOME = $ENV{'HOME'};
948
        Error ("Unix HOME EnvVar not defined" ) unless ( $HOME );
949
        Error ("Unix HOME directory not found: $HOME" ) unless (-d $HOME );
950
        $GBE_VIEWBASE= "$HOME/jats_cbuilder";
951
    } else {
952
        $GBE_VIEWBASE= 'c:/clearcase';
953
    }
954
}
297 dpurdie 955
 
956
################################################################################
227 dpurdie 957
#   Ensure that the PATH contains the PERL executable
958
#   Need to true path to the PERL executable so that the user has access to some
959
#   of the perl utility programs such as pod2html
960
#
299 dpurdie 961
PathPrepend ($Config{'binexp'});
227 dpurdie 962
 
963
################################################################################
964
#   There is more ugliness if GBE_BIN is not in the users path
965
#   I suspect that it something within xmake (under win32) and that it needs
966
#   to be able to find sh within the path - even though its fully pathed
967
#
968
#   Add GBE_BIN to the start of the path to assist in searching
969
#   Also ensure that we pickup our version of utilities instead of random
970
#   versions.
971
#
297 dpurdie 972
PathPrepend ($GBE_BIN);
227 dpurdie 973
 
6898 dpurdie 974
 
227 dpurdie 975
################################################################################
6898 dpurdie 976
# Under Windows - ensure that cmd.exe (or equivelent) is in the PATH
977
# Cygwin may remove it
978
# 
979
unless ( $GBE_JATS_SANE || $GBE_UNIX ) {
980
    if (exists $ENV{COMSPEC}) {
981
        $ENV{COMSPEC} =~ m~(.*)[\\/][^\\/]+~;
982
        $PATH = $PATH . $PSPLIT . $1;
983
    }
984
}
985
 
986
################################################################################
227 dpurdie 987
#   Clean PATH
988
#       Remove duplicates
989
#       Remove empty elements
990
#       Clean path endings
245 dpurdie 991
#       Place non-existent paths at the end. They will be seen, but not scanned
227 dpurdie 992
#
993
{
994
    my @new_path;
995
    my @non_exist;
996
    my %seen;
6898 dpurdie 997
    foreach ( split($PSPLIT, $PATH) )
227 dpurdie 998
    {
999
        s~[/\\]+$~~;                                # Remove trailing / or \
1000
        my $name = ( $GBE_UNIX ) ? $_ : lc ($_);    # Windows is case insensitive
1001
        next unless ( $_ );                         # Remove empty elements
1002
        next if ( /^\.+$/ );                        # Remove . and ..
1003
        next if ( exists $seen{$name} );            # Remove duplicates
1004
        if ( -d $_ ) {
1005
            push @new_path, $_;                     # Exists
1006
        } else {
245 dpurdie 1007
            push @non_exist, $_;                    # Place non existent paths at the end
227 dpurdie 1008
        }
1009
        $seen{$name} = 1;
1010
    }
1011
    $PATH = join( $PSPLIT, @new_path, @non_exist );
1012
}
1013
 
1014
################################################################################
1015
#   Windows: Ensure that cmd.exe is in the users PATH
1016
#            If cmd.exe cannot be found then the 'system' command will not work
1017
#
317 dpurdie 1018
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 1019
{
1020
    my $cmd_found;
1021
    foreach ( split $PSPLIT, $PATH )
1022
    {
1023
        my $file = $_ . "/cmd.exe";
1024
        Verbose2 ("Look for: $file");
1025
        if ( -x $file  )
1026
        {
1027
            $cmd_found = 1;
1028
            Verbose ("Found: $file");
1029
            last;
1030
        }
1031
    }
1032
 
1033
    Warning( "Users PATH does not contain \"cmd.exe\"",
1034
             "System commands may not work" ) unless $cmd_found;
1035
}
1036
 
1037
################################################################################
1038
#   Sanitize the Microsoft Visual Studio environment variables LIB and INCLUDE.
1039
#   If these have a trailing \ then the generated makefiles
1040
#   will fail. This is impossible to detect and fix within make so do it here
1041
#
1042
#   Note: JATS no longer allows these environment variables through to the
1043
#         makefiles.
1044
#
317 dpurdie 1045
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 1046
{
369 dpurdie 1047
    for my $var (qw ( LIB INCLUDE ))
227 dpurdie 1048
    {
1049
        my $evar = $ENV{$var};
1050
        if ( $evar )
1051
        {
1052
            $evar =~ s~\\;~;~g;         # Remove trailing \ from components \; -> ;
1053
            $evar =~ s~\\$~~;           # Remove trailing \
1054
            $evar =~ s~;$~~;            # Remove trailing ;
1055
            $evar =~ s~;;~;~g;          # Remove empty items ;;
1056
            $ENV{$var} = $evar;
1057
        }
1058
    }
1059
}
1060
 
1061
################################################################################
297 dpurdie 1062
#   Update the environment variables used by JATS, unless requested otherwise.
227 dpurdie 1063
#
277 dpurdie 1064
#   If JATS is being used to startup build daemons, then we don't want to
1065
#   export many of the calculated values into the environment. In particular
1066
#   GBE_CORE, GBE_BIN, GBE_CONFIG and GBE_TOOLS must not be exported as it will
1067
#   prevent the daemon from picking up the 'current' version of JATS
1068
#
1069
#
287 dpurdie 1070
 
277 dpurdie 1071
if ( $opt_export_vars )
1072
{
1073
    $ENV{'PATH'}              = $PATH;
1074
    $ENV{'GBE_VERSION'}       = $GBE_VERSION;
1075
    $ENV{'GBE_CORE'}          = $GBE_CORE;
1076
    $ENV{'GBE_BIN'}           = $GBE_BIN;
1077
    $ENV{'GBE_CONFIG'}        = $GBE_CONFIG;
1078
    $ENV{'GBE_DPLY'}          = $GBE_DPLY;
1079
    $ENV{'GBE_DPKG'}          = $GBE_DPKG;
1080
    $ENV{'JATS_HOME'}         = $GBE_DPKG;
6276 dpurdie 1081
    $ENV{'GBE_DPKG_ESCROW'}   = $GBE_DPKG_ESCROW;
277 dpurdie 1082
    $ENV{'GBE_DPKG_CACHE'}    = $GBE_DPKG_CACHE;
4688 dpurdie 1083
    $ENV{'GBE_DPKG_REPLICA'}  = $GBE_DPKG_REPLICA;
277 dpurdie 1084
    $ENV{'GBE_DPKG_STORE'}    = $GBE_DPKG_STORE;
1085
    $ENV{'GBE_DPKG_LOCAL'}    = $GBE_DPKG_LOCAL;
1086
    $ENV{'GBE_SANDBOX'}       = $GBE_SANDBOX;
1087
    $ENV{'GBE_DPKG_SBOX'}     = $GBE_DPKG_SBOX;
1088
    $ENV{'GBE_PERL'}          = $GBE_PERL;
1089
    $ENV{'GBE_TOOLS'}         = $GBE_TOOLS;
1090
    $ENV{'GBE_MACHTYPE'}      = $GBE_MACHTYPE;
1091
    $ENV{'GBE_HOSTMACH'}      = $GBE_HOSTMACH;
1092
    $ENV{'GBE_PLATFORM'}      = $GBE_PLATFORM;
1093
    $ENV{'GBE_DRV'}           = $GBE_DRV;
1094
    $ENV{'PERL5LIB'}          = $PERL5LIB;
1095
    $ENV{'JAVA_HOME'}         = $JAVA_HOME if ($JAVA_HOME);
1096
    $ENV{'GBE_JATS_SANE'}     = 1;
1097
}
287 dpurdie 1098
else
1099
{
1100
    #
1101
    #   Delete, from the environment, values that are related to selecting
1102
    #   the version of JATS being used
1103
    #
5891 dpurdie 1104
    foreach ( qw( GBE_VERSION GBE_CORE GBE_BIN GBE_CONFIG GBE_TOOLS GBE_DRV PERL5LIB GBE_DPKG_SBOX GBE_SANDBOX GBE_PLATFORM GBE_JATS_SANE GBE_MAXMAKE ) )
287 dpurdie 1105
    {
1106
        delete $ENV{$_};
1107
    }
1108
}
277 dpurdie 1109
 
1110
#
1111
#   The following don't affect the operation of the build daemons selecting
1112
#   the current version of JATS. Some need to be passed through anyway
1113
#
227 dpurdie 1114
$ENV{'GBE_BUILDFILTER'}   = $GBE_BUILDFILTER;
277 dpurdie 1115
$ENV{'GBE_ABT'}           = $GBE_ABT if ($GBE_ABT);
227 dpurdie 1116
$ENV{'GBE_DEBUG'}         = $GBE_DEBUG;
1117
$ENV{'GBE_VERBOSE'}       = $GBE_VERBOSE;
1118
$ENV{'GBE_UNIX'}          = $GBE_UNIX;
1119
$ENV{'USER'}              = $USER;
279 dpurdie 1120
$ENV{'GBE_HOSTNAME'}      = $GBE_HOSTNAME;
343 dpurdie 1121
$ENV{'GBE_VIEWBASE'}      = $GBE_VIEWBASE;
361 dpurdie 1122
$ENV{'GBE_VCS'}           = $GBE_VCS;
227 dpurdie 1123
 
363 dpurdie 1124
#
1125
#   Warn users of potential problem
375 dpurdie 1126
#   Only do once. May change directory while getting here
1127
unless ( $GBE_JATS_SANE )
363 dpurdie 1128
{
1129
    Warning ("Current working directory contains spaces")
1130
        if ( $CWD =~ m/\s/ );
1131
}
1132
 
1133
 
227 dpurdie 1134
#-------------------------------------------------------------------------------
297 dpurdie 1135
# Function        : PathPrepend
1136
#
1137
# Description     : Prepend stuff to the PATH
1138
#
1139
# Inputs          : Items to prepend
1140
#
1141
# Returns         : Nothing
1142
#                   Modifies $PATH
1143
#
1144
sub PathPrepend
1145
{
299 dpurdie 1146
    foreach my $el ( @_ )
297 dpurdie 1147
    {
299 dpurdie 1148
        # Must NOT change the original argument, just a copy of it.
1149
        # Don't use $_ as this messes up too
1150
        my $item = $el;
297 dpurdie 1151
        $item =~ s~/~\\~g unless ( $GBE_UNIX );
1152
        $PATH = $item . $PSPLIT . $PATH;
1153
    }
1154
}
1155
 
1156
#-------------------------------------------------------------------------------
229 dpurdie 1157
# Function        : LocateJatsVersion
1158
#
245 dpurdie 1159
# Description     : Scan archives looking for a specified version of JATS
229 dpurdie 1160
#                   Complicated by the name change from core_devl to jats
245 dpurdie 1161
#                   that occurred circa version 2.71.7.
229 dpurdie 1162
#                   The required version may be in either of the packages
1163
#
4688 dpurdie 1164
#                   Ensure that package is complete
1165
#                   The caching process will write built.cache during the creation process
1166
#
229 dpurdie 1167
# Inputs          : $version            - Version to locate
1168
#
1169
# Returns         : undef               - if not found
1170
#                   Array of:
1171
#                       Repository
1172
#                       package/version
1173
#
1174
sub LocateJatsVersion
1175
{
1176
    my ($version) = @_;
1177
    my $package;
1178
    my $path;
1179
 
6276 dpurdie 1180
    foreach my $archive (qw ( GBE_DPKG_LOCAL GBE_DPKG_CACHE GBE_DPKG_ESCROW GBE_DPKG_REPLICA GBE_DPKG GBE_DPKG_STORE ))
229 dpurdie 1181
    {
1182
        no strict 'refs';
1183
        $path = ${$archive};
1184
        use strict 'refs';
1185
        next unless ( $path );
1186
 
369 dpurdie 1187
        foreach my $package (qw( jats core_devl ))
229 dpurdie 1188
        {
1189
            Verbose2( "ExamineDir: $path/$package/$version" );
1190
            if ( -d "$path/$package/$version" )
1191
            {
4688 dpurdie 1192
                unless (-f "$path/$package/$version/built.cache")
1193
                {
1194
                    return $path, "$package/$version", $archive;
1195
                }
229 dpurdie 1196
            }
1197
        }
1198
    }
283 dpurdie 1199
    return;
229 dpurdie 1200
}
1201
 
1202
 
1203
#-------------------------------------------------------------------------------
227 dpurdie 1204
# Function        : TestDirectoryConfig
1205
#
1206
# Description     : Sanity test a user configurable directory or file
1207
#                   Must not contain spaces
1208
#                   Must not be a network drive ie: //computer
1209
#
1210
# Inputs          :
1211
#
1212
# Returns         :
1213
#
1214
sub TestDirectoryConfig
1215
{
1216
    my ($dir) = @_;
1217
 
1218
    no strict 'refs';
1219
    my $val = ${$dir};
1220
 
1221
    if ( $val )
1222
    {
1223
        #
1224
        #   Cleanup the path
1225
        #
1226
        $val =~ tr~\\/~/~s;
1227
        $val =~ s~/+$~~;
255 dpurdie 1228
        $val = '' if ( $val eq '-' || $val eq 'none' );
227 dpurdie 1229
        ${$dir} = $val;
1230
 
1231
        ReportError("$dir path cannot contain spaces: $val") if ( $val =~ m/\s/ );
1232
        ReportError("$dir path cannot be a computer name: $val") if ( $val =~ m~^//~  );
1233
    }
1234
    use strict 'refs';
283 dpurdie 1235
    return;
227 dpurdie 1236
}
1237
 
1238
#-------------------------------------------------------------------------------
1239
# Function        : change_dir
1240
#
1241
# Description     : change directory to the specified directory
1242
#
1243
# Inputs          : $1      - Target directory
1244
#
1245
# Returns         :
1246
#
1247
sub change_dir
1248
{
1249
    my ($dir) = @_;
1250
 
363 dpurdie 1251
    if ( $dir && $dir ne '.' )
227 dpurdie 1252
    {
1253
        Verbose ("Changing to JATS build directory: $dir");
1254
        chdir $dir || Error ("Bad change directory: $dir");
363 dpurdie 1255
 
1256
        #
1257
        #   Reset the CWD
1258
        #   Note: Don't use `pwd`. This sucks for so many reasons including
1259
        #         the fact that it may not be available until this wrapper
1260
        #         script has done it job.
1261
        #
1262
        $CWD = getcwd();
367 dpurdie 1263
        Error ("Bad change directory: $dir","Cannot determine current directory - may be protected" )unless ( defined $CWD );
363 dpurdie 1264
        $CWD =~tr~\\/~/~s;
227 dpurdie 1265
    }
1266
}
1267
 
1268
#-------------------------------------------------------------------------------
277 dpurdie 1269
# Function        : scan_for_dir
1270
#
1271
# Description     : Scan from the current directory up to the root
1272
#                   of the current file system looking for a named
1273
#                   directory
1274
#
1275
# Inputs          : $target                 - Directory to locate
1276
#
1277
# Returns         : full_path               - Path of dir
1278
#                   full_dir                - Containng dir
1279
#
1280
 
1281
sub scan_for_dir
1282
{
1283
    my ($target) = @_;
1284
    Verbose2 ("Scan for $target");
1285
 
319 dpurdie 1286
    my $test_dir = $CWD || getcwd();
277 dpurdie 1287
    {
1288
        do
1289
        {
1290
            #
1291
            #   Stop at /home to prevent unix automounter spitting
1292
            #   lots of error messages
1293
            #
1294
            last if ( $test_dir =~ m~/home$~ );
1295
            Verbose2 ("Testing: $test_dir");
1296
 
1297
            my $test_path = $test_dir . '/' . $target;
1298
            if ( -d $test_path )
1299
            {
1300
                Verbose ("Found $target: $test_path");
1301
                return $test_path, $test_dir;
1302
            }
1303
            #
1304
            #   Remove one directory
1305
            #   Terminate the loop when no more can be removed
1306
            #
1307
        } while ( $test_dir =~ s~[/][^/]*$~~ );
1308
    }
1309
    return '','';
1310
}
1311
 
1312
#-------------------------------------------------------------------------------
227 dpurdie 1313
# Function        : get_java_home
1314
#
1315
# Description     : Convert user java option into a full path,or die
1316
#
1317
# Inputs          : User option
1318
#
1319
# Returns         : Full path
1320
#
1321
sub get_java_home
1322
{
1323
    my ($java) = @_;
1324
    my $jv = "JAVA_HOME_$java";
1325
    $jv =~ s~\.~_~g;
1326
 
1327
    unless ( exists($ENV{$jv}) )
1328
    {
1329
        Error ("Unknown JAVA version: $java",
1330
               "Looking for EnvVar: $jv",
1331
               "Example Usage: -java=1.5");
1332
    }
1333
    my $rv = $ENV{$jv};
1334
    unless ( -d $rv )
1335
    {
1336
        Error ("Java home path not found: $jv",
1337
               "Looking for: $rv" );
1338
    }
1339
    return $rv;
1340
}
1341
 
1342
#-------------------------------------------------------------------------------
1343
# Function        : get_version
1344
#
1345
# Description     : Return the version of JATS being run
1346
#                   JATS should be run from a "package"
1347
#                   The package should have a descpkg file
1348
#                   Use this file
1349
#
1350
# Inputs          :
1351
#
1352
# Returns         : A string
1353
#
1354
sub get_version
1355
{
229 dpurdie 1356
    #
1357
    #   The version number is embedded into this script by the release process
1358
    #   The text [V]ERSION_TAG will be replaced by the real version number
245 dpurdie 1359
    #   If this has not occurred then we know that the release is not official
229 dpurdie 1360
    #   Need to be a little bit careful about the tag name
1361
    #
1362
    return ("Unreleased Version. Version tag has not been set")
1363
        if ( $GBE_NOT_RELEASED );
1364
 
227 dpurdie 1365
    return "$GBE_VERSION [ Internal. Not an installed package ]"
1366
        if ( ! -f "$GBE_CORE/descpkg" );
1367
 
1368
    my $rec;
1369
    return $rec->{'VERSION_FULL'}
1370
        if ($rec = ReadDescpkg ( "$GBE_CORE/descpkg" ) );
1371
 
1372
    return "ERROR";
1373
}
1374
 
1375
#-------------------------------------------------------------------------------
1376
# Function        : print_version
1377
#
1378
# Description     :
1379
#
1380
# Inputs          :
1381
#
1382
# Returns         :
1383
#
1384
sub print_version
1385
{
1386
    #
1387
    #   Allow user to specify verboseness as an argument
1388
    #
1389
    foreach  ( @_ )
1390
    {
1391
        $GBE_VERBOSE++ if ( m/^-v/ );
1392
    }
1393
 
1394
    Message get_version();
1395
    Message "Internal: $GBE_VERSION" if ($GBE_VERBOSE);
1396
    $opr_done = 1;
283 dpurdie 1397
    return;
227 dpurdie 1398
}
1399
 
1400
 
1401
#-------------------------------------------------------------------------------
1402
#
1403
#   Give the user a clue
1404
#
1405
sub help
1406
{
1407
    my ($level) = @_;
1408
    $level = $opt_help unless ( $level );
1409
 
1410
    pod2usage(-verbose => 0, -message => "Version: ". get_version())  if ($level == 1 );
261 dpurdie 1411
    pod2usage(-verbose => $level - 1 );
227 dpurdie 1412
}
1413
 
1414
#-------------------------------------------------------------------------------
309 dpurdie 1415
# Function        : find_jats_dir
227 dpurdie 1416
#
309 dpurdie 1417
# Description     : Find a JATS build directory
1418
#                   Can be supressed with JATS '-here' command line option
227 dpurdie 1419
#
309 dpurdie 1420
# Inputs          : files               - Files to look for
1421
#                   options
1422
#                       --Ant           - Allow Ant files too
295 dpurdie 1423
#
309 dpurdie 1424
# Returns         : Will not return if not found
1425
#                   Will 'cd' to the build directory
1426
#
227 dpurdie 1427
sub find_jats_dir
1428
{
309 dpurdie 1429
    my $allow_ant;
1430
    my @FILES;
1431
    my $DIR;
1432
    my $check_file;
1433
 
227 dpurdie 1434
    #
1435
    #   Autodetect suppressed ?
1436
    #
1437
    return if ( $opt_here );
1438
 
309 dpurdie 1439
    #
1440
    #   Collect options
1441
    #   Collect the rest of the arguments
1442
    #
1443
    foreach ( @_ )
1444
    {
1445
        if ( m/^--Ant/ ) {
1446
            $allow_ant = 1;
1447
        }
1448
        else {
1449
            push @FILES, $_;
1450
        }
1451
    }
1452
 
227 dpurdie 1453
    push @FILES, @BUILD_FILE_ALT;
309 dpurdie 1454
    push @FILES, 'build.xml' if ( $allow_ant );
1455
 
1456
    #
1457
    #   Parent directories to search
1458
    #   Child dirs to search
1459
    #
227 dpurdie 1460
    my @SEARCH = qw( . .. ../.. ../../.. );
309 dpurdie 1461
    my @CHILD  = ('', '/jats', '/build', '/build/jats' );
227 dpurdie 1462
 
1463
    #
1464
    #   Locate the JATS build files
1465
    #   Allow the user to be in a number of parent directories
1466
    #
309 dpurdie 1467
    scan:
227 dpurdie 1468
    for my $ROOTDIR (@SEARCH)
1469
    {
309 dpurdie 1470
        for my $SUBDIR (@CHILD)
227 dpurdie 1471
        {
309 dpurdie 1472
            $DIR = $ROOTDIR . $SUBDIR;
227 dpurdie 1473
            next unless -d $DIR;
1474
 
283 dpurdie 1475
            for my $FILE ( @FILES)
227 dpurdie 1476
            {
309 dpurdie 1477
                $check_file = $DIR . '/' . $FILE;
227 dpurdie 1478
                Verbose2 ("Check for: $check_file");
309 dpurdie 1479
                last scan if ( -f $check_file );
1480
            }
1481
 
1482
            next unless ( $allow_ant );
1483
            foreach ( glob($DIR . '/*depends.xml' ) )
1484
            {
1485
                Verbose2 ("Check for: $_");
1486
                if ( m/(.+)depends.xml/ )
227 dpurdie 1487
                {
309 dpurdie 1488
                    $check_file = "$1.xml";
1489
                    last scan if ( -f $check_file );
227 dpurdie 1490
                }
1491
            }
1492
        }
309 dpurdie 1493
        $DIR = '';
227 dpurdie 1494
    }
309 dpurdie 1495
 
1496
    #
1497
    #   Change to the build directory if one has been found
1498
    #
1499
    if ( $DIR )
1500
    {
1501
        Verbose2 ("Found check file: $check_file");
1502
        change_dir ( $DIR );
1503
    }
1504
    else
1505
    {
1506
        Error ( 'JATS build directory not found.',
1507
                "Cannot locate: @FILES",
1508
                $allow_ant ? 'or Ant <Package>.xml <Package>depends.xml pair' : undef,
1509
                'Use -here option to supress this test'
1510
                );
1511
    }
227 dpurdie 1512
}
1513
 
1514
#-------------------------------------------------------------------------------
1515
#
295 dpurdie 1516
#   Determine the real build file to use
1517
#   Will select from a list of known build files.
227 dpurdie 1518
#
295 dpurdie 1519
sub getBuildFile
227 dpurdie 1520
{
1521
    my $build_file = $BUILD_FILE;
1522
    #
1523
    #   Use an alternative buildfile - if it exists
1524
    #   Do not use this file if the user has specified a buildfile
1525
    #
1526
    unless ( $BUILD_FILE_SET )
1527
    {
1528
        Verbose ("Search for alternate build file");
1529
        foreach my $test_file ( @BUILD_FILE_ALT )
1530
        {
1531
            Verbose2 ("Search for alternate build file: $test_file");
1532
            if ( -f $test_file )
1533
            {
1534
                $build_file = $test_file;
1535
                Message ("=== USING ALTERNATE BUILDFILE: $build_file ===");
1536
                last;
1537
            }
1538
        }
1539
    }
295 dpurdie 1540
   return $build_file;
1541
}
227 dpurdie 1542
 
295 dpurdie 1543
#-------------------------------------------------------------------------------
1544
#
1545
#   Kick off the build process
1546
#
1547
sub build
1548
{
4902 dpurdie 1549
    isaBuildMachine();
295 dpurdie 1550
    my $build_file = $BUILD_FILE;
1551
    (my $name = $CWD) =~ s~^.*/~~ ;
1552
    $opr_done = 1;
1553
 
1554
    find_jats_dir($build_file);
1555
    Message ("=== Building $name ===");
1556
    $build_file = getBuildFile();
1557
 
227 dpurdie 1558
    #
1559
    #   Jats/make does not handle file systems with spaces in the path names
1560
    #
1561
    Error('$CWD path cannot contain spaces') if ( $CWD =~ m/\s/ );
1562
 
333 dpurdie 1563
    $RESULT = System ($GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", @_ );
227 dpurdie 1564
 
283 dpurdie 1565
    Message ("=== Build $name NOT complete ===") if     ( $RESULT  );
1566
    Message ("=== Build $name complete ===")     unless ( $RESULT );
227 dpurdie 1567
    return $RESULT
1568
}
1569
 
1570
#-------------------------------------------------------------------------------
1571
# Function        : bmake_it
1572
#
1573
# Description     : Combo build and make operations
1574
#
1575
# Inputs          : ...     - COMMANDS or Make arguments.
1576
#                             Key commands are BUILD and INSTALL
1577
#
1578
# Returns         : RESULT code
1579
#
1580
sub bmake_it
1581
{
1582
    my @make_args = @_;
1583
    my $all = 1;
1584
    my $msg;
1585
    $opr_done = 1;
4902 dpurdie 1586
    isaBuildMachine();
227 dpurdie 1587
 
1588
    if ( $make_args[0] && $make_args[0] eq 'NOTALL' )
1589
    {
1590
        $all = 0;
1591
        shift @make_args;
1592
    }
1593
    elsif ( $make_args[0] && $make_args[0] eq 'BUILD' )
1594
    {
1595
        Verbose ("Makeit build") ;
1596
        $msg = "Component not built";
331 dpurdie 1597
        build('-noforce');
227 dpurdie 1598
        shift @make_args;
1599
    }
1600
 
1601
    unless ( $RESULT )
1602
    {
1603
        push @make_args, '-default=all' if ( $all );
1604
        Verbose ("Makeit make @make_args") ;
1605
 
309 dpurdie 1606
        find_jats_dir( 'makefile.pl', 'Makefile.gbe', $BUILD_FILE );
227 dpurdie 1607
        Error ("No Makefile.gbe file found") unless ( -f 'Makefile.gbe' );
1608
 
1609
        etool ( 'jmake.pl', @make_args );
1610
        $msg = "Component not made";
1611
        @make_args = ();
1612
    }
1613
 
1614
 
1615
    Verbose ("Makeit Result: $RESULT") ;
1616
    Error ( $msg ) if ( $RESULT );
1617
    return  if ( $RESULT );
1618
}
1619
 
1620
#-------------------------------------------------------------------------------
1621
# Function        : dev_expand
1622
#
1623
# Description     : Expand the users arguments to the "debug/prod" command
1624
#                   "debug/prod" builds and packages debug stuff
1625
#
1626
#                   Ignore make options.
1627
#
1628
# Inputs          : target
1629
#                   Argument list
1630
#
1631
# Returns         : expanded argument list
1632
#
1633
sub dev_expand
1634
{
1635
    my @resultd;
1636
    my @resultp;
1637
    my @args;
1638
    my @opts;
1639
 
1640
    #
1641
    #   Remove options from the argument list
1642
    #
1643
    foreach ( @_ )
1644
    {
1645
        if ( m~=~ || m~^-~ ) {
1646
            push @opts, $_;
1647
        } else {
1648
            push @args, $_;
1649
        }
1650
    }
1651
 
1652
    my $target = shift @args;
1653
    my @cmd = $target;
1654
    if ( $#args < 0 )
1655
    {
1656
        push @cmd, "package_$target";
1657
    }
1658
    else
1659
    {
1660
        foreach ( @args )
1661
        {
1662
            push @resultd, $_ . "_$target";
1663
            push @resultp, $_ . "_package_$target";
1664
            @cmd = ();
1665
        }
1666
    }
1667
 
1668
    return (@cmd, @resultd, @resultp, @opts);
1669
}
1670
 
1671
#-------------------------------------------------------------------------------
1672
# Function        : install_pkg
1673
#
1674
# Description     : Install the built package into local_dpkg_archive
1675
#                   This will make it available for use, without populating the
1676
#                   global archive
1677
#
1678
#                   This is done through an external utility to maintain
1679
#                   consistent interface
1680
#
1681
sub install_pkg
1682
{
1683
 
309 dpurdie 1684
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1685
    etool ( 'create_dpkg.pl', '-archive=local', '-quiet', '-override',  @_ );
1686
}
1687
 
1688
#-------------------------------------------------------------------------------
1689
# Function        : create_dpkg
1690
#
1691
# Description     : Install a package into the main dpkg_archive
1692
#                   This is done through an external utility to maintain
1693
#                   consistent interface
1694
#
1695
#                   This function is simply an easy way to access the utility
1696
 
1697
sub create_dpkg
1698
{
309 dpurdie 1699
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1700
    etool ( 'create_dpkg.pl',  @_ );
1701
}
1702
 
1703
#-------------------------------------------------------------------------------
1704
# Function        : etool
1705
#
1706
# Description     : Invoke an external tool program written in PERL
1707
#
1708
# Arguments       : $1  Name of the program to run
1709
#                       With optional .pl suffix
1710
#                   $2+ Program arguments
1711
#
1712
sub etool
1713
{
1714
    my $command = shift;
1715
    my $cmd;
1716
    my @etool_path = ( "$ENV{'GBE_TOOLS'}",
1717
                       "$ENV{'GBE_TOOLS'}/DEPLOY",
379 dpurdie 1718
                       "$ENV{'GBE_TOOLS'}/LOCAL",
1719
                        );
227 dpurdie 1720
    if ( $command )
1721
    {
1722
        #
1723
        #   Locate a potential tool
1724
        #   These will have the user name or a .pl extension
1725
        #
1726
        ETOOL_SEARCH:
1727
        foreach my $ext ( '', '.pl' )
1728
        {
1729
            foreach my $dir ( @etool_path )
1730
            {
297 dpurdie 1731
                $cmd = "$dir/jats_$command$ext";
1732
                last ETOOL_SEARCH if ( -f $cmd );
1733
 
227 dpurdie 1734
                $cmd = "$dir/$command$ext";
1735
                last ETOOL_SEARCH if ( -f $cmd );
1736
            }
1737
            $cmd='';
1738
        }
1739
 
1740
        Error ("Tool not found: $command", "Search path:", @etool_path) unless $cmd;
1741
        $RESULT = System ( $GBE_PERL, $cmd, @_ );
1742
    }
1743
    else
1744
    {
1745
        #
1746
        #   Display on the .pl commands
1747
        #
1748
        display_commands("Available Tools", \@etool_path, ['*.pl'] );
1749
    }
1750
 
1751
    $opr_done = 1;
1752
}
1753
 
1754
#-------------------------------------------------------------------------------
1755
# Function        : ebin
1756
#
1757
# Description     : Invoke an external JATS provided binary
1758
#                   within the JATS toolset
1759
#
1760
# Arguments       : $1  Name of the program to run
1761
#                   $2+ Program arguments
1762
#
1763
sub ebin
1764
{
1765
    my $command = shift;
1766
    my $cmd;
1767
    my @ebin_path = ( "$GBE_BIN" );
1768
 
1769
    if ( $command )
1770
    {
1771
        #
1772
        #   Locate a potential executable
1773
        #   This
1774
        #
1775
        ETOOL_SEARCH:
1776
        foreach my $ext ( '', '.exe', '.sh' )
1777
        {
1778
            foreach my $dir ( @ebin_path )
1779
            {
1780
                $cmd = "$dir/$command$ext";
1781
                last ETOOL_SEARCH if ( -f $cmd );
1782
            }
1783
            $cmd='';
1784
        }
1785
 
1786
        Error ("Program not found: $command", "Search path:", @ebin_path) unless $cmd;
1787
        $RESULT = System ( $cmd, @_ );
1788
    }
1789
    else
1790
    {
1791
        #
1792
        #   Display a list of programs
1793
        #
1794
        display_commands("Available Programs", \@ebin_path, ['*'] );
1795
    }
1796
 
1797
    $opr_done = 1;
1798
}
1799
 
1800
#-------------------------------------------------------------------------------
1801
# Function        : eprog
1802
#
1803
# Description     : Invoke an external program
1804
#                   Will detect local .pl files and execute them
1805
#                   Will detect local .jar files and execute them
229 dpurdie 1806
#                   Will detect local .bat files and execute them
227 dpurdie 1807
#
1808
# Arguments       : $1  Name of the program to run
1809
#                   $2+ Program arguments
1810
#
1811
sub eprog
1812
{
229 dpurdie 1813
    Verbose ("eprog: @_");
315 dpurdie 1814
    my $name = fix_command_name (shift @_);
227 dpurdie 1815
    Error ("eprog. No program specified") unless ( $name );
1816
 
229 dpurdie 1817
    $name .= ".pl"     if ( -f "${name}.pl" );
1818
    $name .= ".jar"    if ( -f "${name}.jar" );
1819
    $name .= ".bat"    if ( -f "${name}.bat" );
227 dpurdie 1820
 
229 dpurdie 1821
    #
245 dpurdie 1822
    #   On Windows programs in the CWD will be found
1823
    #   Mimic this behaviour on Unix
229 dpurdie 1824
    #
1825
    $name = "./$name" if ( $name !~ m~/~ && -f "./$name");
1826
 
227 dpurdie 1827
    if ( $name =~ m~\.pl$~ ) {
1828
        $RESULT = System ( $GBE_PERL, $name, @_ );
1829
 
1830
    } elsif ( $name =~  m~\.jar$~ ) {
1831
        $RESULT = System ( "$JAVA_HOME/bin/java", '-jar', $name, @_);
1832
 
1833
    } else {
229 dpurdie 1834
        #
1835
        #   Ensure .bat files are pathed with \, and not / characters
1836
        #   The windows command interpreter does not like /
1837
        #
1838
        $name =~ s~/~\\~g if ( $name =~ m~\.bat$~ );
1839
 
227 dpurdie 1840
        $RESULT = System ( $name, @_ );
1841
    }
1842
 
1843
    $opr_done = 1;
1844
}
1845
 
1846
#-------------------------------------------------------------------------------
1847
# Function        : display_commands
1848
#
1849
# Description     : Display a list of commands from a specified list of dirs
1850
#                   Internal helper function
1851
#
1852
# Inputs          : $title      - Display header
1853
#                   $ref_path   - Ref to an array that contains the search path
1854
#                   $ref_ext    - Ref to an array of valid patterns
1855
#
1856
# Returns         : Nothing
1857
#
1858
sub display_commands
1859
{
1860
    my ( $title, $ref_path, $ref_ext ) = @_;
1861
 
1862
    #
1863
    #   Display a list of commands
1864
    #
1865
    my %list;
1866
    foreach ( @$ref_path )
1867
    {
1868
        foreach my $ext ( @$ref_ext )
1869
        {
1870
            foreach my $file (  glob( "$_/$ext") )
1871
            {
1872
                $file =~ s~.*/~~ unless $GBE_VERBOSE;
1873
                $list{$file} = 1;
1874
            }
1875
        }
1876
    }
1877
 
1878
    my $count = 0;
1879
    my $limit = $GBE_VERBOSE ? 1 : 3;
1880
    print "$title:\n";
1881
    foreach ( sort keys %list )
1882
    {
1883
        printf "%-26s", $_;
1884
        print "\n" if ( !( ++$count % $limit) );
1885
    }
1886
}
1887
 
1888
#-------------------------------------------------------------------------------
315 dpurdie 1889
# Function        : fix_command_name
1890
#
1891
# Description     : Fix a command name parameter
1892
#                   Simplify use of cygwin for some users by allowing
1893
#                   that path of external tools to be a cygwin path
1894
#
1895
# Inputs          : cmd             - command
1896
#
1897
# Returns         : cleaned up version of cmd
1898
#
1899
sub fix_command_name
1900
{
1901
    my ($cmd) = @_;
1902
 
1903
    unless ( $GBE_UNIX )
1904
    {
1905
        #
1906
        #   Cygwin kludge
1907
        #       Replace /cygdrive/DriveLetter/ - with DriveLetter:/
1908
        #       Replace /DriveLetter/          - With DriveLetter:/
1909
        #
1910
        $cmd =~ s~^/cygdrive/([A-Z])/(.*)~$1:/$2~i;
1911
        $cmd =~ s~^/([A-Z])/(.*)~$1:/$2~i;
1912
    }
1913
    return $cmd;
1914
}
1915
 
1916
 
1917
#-------------------------------------------------------------------------------
227 dpurdie 1918
# Function        : run_ant
1919
#
1920
# Description     : Invoke ant
399 dpurdie 1921
#                   If the current directory looks like an VIX build system, then
227 dpurdie 1922
#                   create and maintain an auto.xml file. Otherwise simply invoke ant
1923
#
1924
# Inputs          : $1+ program arguments
1925
#
1926
sub run_ant
1927
{
4902 dpurdie 1928
    isaBuildMachine();
227 dpurdie 1929
    my $JAVA_HOME = $ENV{JAVA_HOME} || Error ("JAVA_HOME is not defined in the environment");
1930
    my $ANT_HOME  = $ENV{ANT_HOME}  || Error ("ANT_HOME is not defined in the environment" );
1931
 
1932
    #
399 dpurdie 1933
    #   Detect an VIX formatted build
227 dpurdie 1934
    #   This will have two files <projectname>.xml and <projectname>depends.xml
1935
    #   Create the 'auto.xml' file only if its not present
1936
    #
1937
    my @ant_arg;
1938
    my @flist;
1939
    my $basename = '';
235 dpurdie 1940
    my $scanner = '*depends.xml';
227 dpurdie 1941
 
1942
    #
1943
    #   Use specified build file to resolve multiple names
1944
    #   Strip any trailing depends.xml to make it user friendly
1945
    #
1946
    if ( $BUILD_FILE_SET )
1947
    {
1948
        $basename = $BUILD_FILE;
1949
        $basename =~ s~\.xml$~~;
1950
        $basename =~ s~depends$~~;
235 dpurdie 1951
        $scanner = "${basename}depends.xml";
227 dpurdie 1952
        Verbose ("Using buildfile: $basename");
1953
    }
1954
 
235 dpurdie 1955
    my @buildlist = glob($scanner);
227 dpurdie 1956
    foreach ( @buildlist )
1957
    {
1958
        if ( m/(.+)depends.xml/ )
1959
        {
1960
            my $pname = $1;
1961
            push @flist, $pname if ( -f "$pname.xml" );
1962
        }
1963
    }
1964
 
1965
    if ( $#flist >= 0 )
1966
    {
1967
        Error ("Multiple depends.xml files found:", @flist,
297 dpurdie 1968
               "Use 'jats -buildfile=name ant ...' to resolve") if ( $#flist > 0 );
227 dpurdie 1969
 
1970
        my $depend = "$flist[0]depends.xml";
1971
        @ant_arg = ('-f', "$flist[0].xml");
1972
 
1973
        Message ("Ant using projectfiles: $flist[0].xml");
1974
 
1975
        #
367 dpurdie 1976
        #   Create auto.xml if we have a depends.xml
227 dpurdie 1977
        #
367 dpurdie 1978
        if ( -f $depend )
227 dpurdie 1979
        {
367 dpurdie 1980
            #
1981
            #   Check for depends.xml newer than auto.xml.
1982
            #
1983
            my $auto_timestamp   = (stat('auto.xml'))[9] || 0;
1984
            my $depend_timestamp = (stat($depend))[9];
1985
            if ( $depend_timestamp > $auto_timestamp )
1986
            {
1987
                Message ("Creating: auto.xml");
1988
                copy( $depend, 'auto.xml' );
1989
                chmod 0777, 'auto.xml';
1990
            }
227 dpurdie 1991
        }
367 dpurdie 1992
        else
1993
        {
1994
            Warning ("Project file does not have a depends.xml file");
1995
        }
227 dpurdie 1996
    }
1997
    elsif ( $BUILD_FILE_SET  )
1998
    {
1999
        Error ("Specified build file pair not found:", $basename, $basename . "depends.xml");
2000
    }
2001
    #
2002
    #   The ant provided startup scripts don't return an exit code under
2003
    #   windows. Invoke ant directly
2004
    #
2005
    launch_ant ( $JAVA_HOME, $ANT_HOME, @ant_arg, @_ );
2006
    $opr_done = 1;
2007
}
2008
 
2009
#-------------------------------------------------------------------------------
2010
# Function        : run_abt
2011
#
2012
# Description     : Invoke auto build tool (older form)
2013
#                   Options for the ABT
2014
#                       --Java=x.x
2015
#                   Invoke ANT for the ABT using a specified version of Java
2016
#                   Do not play with the user environment.
297 dpurdie 2017
#                   Don't stick java path into environment
227 dpurdie 2018
#
2019
# Inputs          : $1+ program arguments
2020
#
2021
sub run_abt
2022
{
279 dpurdie 2023
    my $ABT_JAVA = 'JAVA_HOME_1_6';         # Default version for the ABT
227 dpurdie 2024
    my $JAVA_HOME = $ENV{$ABT_JAVA};
2025
    my $ANT_HOME  = $ENV{ANT_HOME};
2026
    my @abt_arg;
239 dpurdie 2027
    my $buildfile = 'build.xml';
227 dpurdie 2028
 
2029
    ErrorConfig( 'name'    => 'JATS ABT' );
4902 dpurdie 2030
    isaBuildMachine();
227 dpurdie 2031
 
2032
    #
239 dpurdie 2033
    #   Use the user specified buildfile
2034
    #
2035
    $buildfile = $BUILD_FILE
2036
        if ( $BUILD_FILE_SET );
2037
 
2038
    #
227 dpurdie 2039
    #   Extract known options
2040
    #
2041
    foreach  ( @_ )
2042
    {
2043
        if ( m/-java=(.*)/ ) {
2044
            $JAVA_HOME = get_java_home($1);
239 dpurdie 2045
 
2046
        } elsif ( m/^-buildfile=(.+)/ ) {
2047
            $buildfile = $1;
2048
 
227 dpurdie 2049
        } else {
2050
            push @abt_arg, $_;
2051
        }
2052
    }
2053
 
2054
    Error ("$ABT_JAVA is not defined in the environment") unless $JAVA_HOME;
2055
    Error ("ANT_HOME is not defined in the environment" ) unless $ANT_HOME;
239 dpurdie 2056
    Error ("Ant buildfile not found: $buildfile" ) unless (-f $buildfile);
227 dpurdie 2057
 
2058
    #
239 dpurdie 2059
    #   Insert correct build file arguments
2060
    #
279 dpurdie 2061
    push @abt_arg, '-buildfile', $buildfile;
2062
 
2063
    #
2064
    #   Add current directory as java library directory, but only if
2065
    #   it contains JAR files.
2066
    #
2067
    push @abt_arg, '-lib', $CWD
2068
        if ( glob ('*.jar') );
239 dpurdie 2069
 
2070
    #
227 dpurdie 2071
    #   Use the ant-launcher to invoke ant directly
2072
    #
2073
    launch_ant ( $JAVA_HOME, $ANT_HOME, @abt_arg );
2074
    $opr_done = 1;
2075
}
2076
 
2077
#-------------------------------------------------------------------------------
2078
# Function        : launch_ant
2079
#
2080
# Description     : Start ANT - with sanity checking
2081
#
2082
# Inputs          : JAVA_HOME
2083
#                   ANT_HOME
2084
#                   @user_args
2085
#
2086
# Returns         : Result Code
2087
#
2088
sub launch_ant
2089
{
2090
    my ($JAVA_HOME, $ANT_HOME, @user_args ) = @_;
2091
 
2092
    Error ("Directory not found: $JAVA_HOME") unless ( -d "$JAVA_HOME" );
2093
    Error ("Program not found: $JAVA_HOME/bin/java") unless ( -e "$JAVA_HOME/bin/java" || -e "$JAVA_HOME/bin/java.exe" );
2094
    Error ("Jar not found: $ANT_HOME/lib/ant-launcher.jar") unless ( -e "$ANT_HOME/lib/ant-launcher.jar" );
2095
    Error ("Directory not found: $ANT_HOME") unless ( -d "$ANT_HOME" );
2096
    Error ("Directory not found: $ANT_HOME/lib") unless ( -d "$ANT_HOME/lib" );
2097
 
2098
    #
4688 dpurdie 2099
    #   Documented KLUDGE
2100
    #   The 'ant-using' mechanism only understands GBE_DPKG
2101
    #   This is not good in a cloud build configuration where GBE_DPKG_REPLICA is the fastest repository
5568 dpurdie 2102
    #   Solution: In an GBE_ABT environment IFF GBE_DPKG_REPLIA exists then set GBE_DPKG and JATS_HOME
4688 dpurdie 2103
    #
2104
    if ($GBE_ABT && $GBE_DPKG_REPLICA)
2105
    {
2106
        $ENV{GBE_DPKG_ORIGINAL} = $ENV{GBE_DPKG};
2107
        $ENV{GBE_DPKG} = $ENV{GBE_DPKG_REPLICA};
5568 dpurdie 2108
        $ENV{JATS_HOME} = $ENV{GBE_DPKG_REPLICA};
4688 dpurdie 2109
        Message("Setting GBE_DPKG to GBE_DPKG_REPLICA");
2110
    }
2111
 
2112
    #
227 dpurdie 2113
    #   Use the ant-launcher to invoke ant directly
2114
    #
2115
    $RESULT = System ( "$JAVA_HOME/bin/java",
4688 dpurdie 2116
                       #"-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y",      # Enable Remote Debug
227 dpurdie 2117
                       "-classpath","$ANT_HOME/lib/ant-launcher.jar",
2118
                       "-Dant.home=$ANT_HOME",
2119
                       "org.apache.tools.ant.launch.Launcher",
2120
                       "-lib","$ANT_HOME/lib",
2121
                       @user_args
2122
                       );
2123
 
2124
   return $RESULT;
2125
}
2126
 
2127
 
2128
#-------------------------------------------------------------------------------
2129
#
2130
#   Cleanup the sandbox
2429 dpurdie 2131
#   Perform a "make clean" then a "build clobber"
227 dpurdie 2132
#
2133
sub clobber
2134
{
4902 dpurdie 2135
    isaBuildMachine();
227 dpurdie 2136
    Message ("=== Removing ======");
2137
    find_jats_dir( $BUILD_FILE );
295 dpurdie 2138
    my $build_file = getBuildFile();
2139
 
227 dpurdie 2140
 
2141
    #
2429 dpurdie 2142
    #   Run a "make clean" to clean out a lot of stuff
2143
    #   Run a "build clobber" to get rid of interface and local directories
227 dpurdie 2144
    #
2429 dpurdie 2145
    etool ( 'jmake.pl', 'clean' )
227 dpurdie 2146
        if ( -f "Makefile.gbe" );
2147
 
295 dpurdie 2148
    if ( -f $build_file )
227 dpurdie 2149
    {
333 dpurdie 2150
        System ( $GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", 'clobber' );
227 dpurdie 2151
    }
2152
    else
2153
    {
2154
        Error ("Cannot clobber. No buildfile found");
2155
    }
2156
 
2157
    Message ("=== Remove complete ===");
2158
    $opr_done = 1;
2159
}
2160
 
2161
#-------------------------------------------------------------------------------
2162
# Function        : do_exit
2163
#
2164
# Description     : Common exit point so that time information can be displayed
2165
#
2166
# Inputs          : Optional exit code
2167
#
2168
# Returns         :
2169
#
2170
sub do_exit
2171
{
2172
    my ($ecode) = @_;
2173
 
2174
    $RESULT = $ecode if ( $ecode );
2175
 
2176
    #..
2177
    #   Determine the runtime
363 dpurdie 2178
    #       $^T is the time that the program started
227 dpurdie 2179
    #
2180
    if ( $opt_time )
2181
    {
2182
        my ($TIMEU, $TIMES) = times;
363 dpurdie 2183
        my $TIMER = time - $^T;
2184
        my $m = int($TIMER / 60);
2185
        my $s = $TIMER - ($m * 60);
227 dpurdie 2186
 
2187
        Message ( "Times: Real: $m:$s, User: $TIMEU, System: $TIMES");
2188
    }
2189
    #.
2190
    #   Make sure that any important exit code is passed to the user
2191
    #
2192
    Verbose ("ExitCode: $RESULT");
2193
    exit $RESULT;
2194
}
2195
 
4902 dpurdie 2196
#-------------------------------------------------------------------------------
2197
# Function        : isaBuildMachine 
2198
#
2199
# Description     : Test that this machine is a build machine
2200
#                   One that supports compilation
2201
#                   Jats may be installed on machines where it may be used in 
2202
#                   a support mode but not to build software. ie: auperaunx01
2203
#
2204
# Inputs          : None
2205
#
2206
# Returns         : May not return 
2207
#
2208
sub isaBuildMachine
2209
{
2210
    if ($notaBuildMachine)
2211
    {
2212
        Error("This machine does not support JATS for building software.",
2213
              "This machine does support JATS for the purpose of running support utilities.");
2214
    }
2215
 
2216
 
2217
}
2218
 
2219
 
227 dpurdie 2220
########################################################################
2221
#
2222
#   Main body of the script
2223
#
2224
#   Process help and manual options
2225
#       Done after all the setup to ensure that the PATH is correct
2226
#       Done before bombout to give user a chance
2227
#
379 dpurdie 2228
 
2229
#
2230
#   Redirect all output to a log file
2231
#   Only perform redirection AFTER we have setup the users environment
2232
#       May change this.
2233
#
2234
if ( $opt_logfile )
2235
{
2236
    open STDOUT, '>', $opt_logfile  or die "Can't redirect STDOUT: $!";
2237
    open STDERR, ">&STDOUT"         or die "Can't dup STDOUT: $!";
2238
}
2239
 
227 dpurdie 2240
help() if $opt_help;
2241
ErrorDoExit();  # Exit if any error in setup
2242
ErrorConfig( 'on_exit'    => \&do_exit );
2243
 
2244
#
231 dpurdie 2245
#   Reset operational flags.
2246
#   May have been used by setup
2247
#
2248
$opr_done = 0;
2249
$RESULT = 0;
2250
 
2251
#
227 dpurdie 2252
#   Process user commands
2253
#
263 dpurdie 2254
my $cmd = shift @ARGV || help(1);
227 dpurdie 2255
 
2256
print_version(@ARGV)                    if ( $cmd =~ m/^ver/ );
2257
 
2258
clobber                                 if ( $cmd =~ m/^clobber$/ );
2259
build    (@ARGV)                        if ( $cmd =~ m/^build$/ );
2260
 
2261
bmake_it ('NOTALL', @ARGV)              if ( $cmd =~ m/^[x]*make$/ );
2262
bmake_it (@ARGV)                        if ( $cmd =~ m/^go$/ );
2263
bmake_it (dev_expand('debug', @ARGV) )  if ( $cmd =~ m/^debug$/ );
2264
bmake_it (dev_expand('prod', @ARGV) )   if ( $cmd =~ m/^prod$/ );
2265
bmake_it ("clean", @ARGV)               if ( $cmd =~ m/^clean$/ );
2266
bmake_it ("rebuild", @ARGV)             if ( $cmd =~ m/^rebuild$/ );
2267
bmake_it ('BUILD', @ARGV)               if ( $cmd =~ m/^all$/ );
2268
bmake_it ($cmd, @ARGV )                 if ( $cmd =~ m/^run_unit_tests/ );
2269
 
2270
install_pkg(@ARGV)                      if ( $cmd =~ m/^install$/ );
2271
create_dpkg(@ARGV)                      if ( $cmd =~ m/^create_dpkg$/ );
2272
 
2273
ebin  (@ARGV)                           if ( $cmd =~ m/^ebin/ );
2274
etool (@ARGV)                           if ( $cmd =~ m/^etool/ );
2275
eprog (@ARGV)                           if ( $cmd =~ m/^eprog$/ );
2276
run_ant (@ARGV)                         if ( $cmd =~ m/^ant$/ );
2277
run_abt (@ARGV)                         if ( $cmd =~ m/^abt$/ );
2278
 
299 dpurdie 2279
etool ('cache_dpkg', @ARGV)                         if ( $cmd =~ m/^dpkg/ );
2280
etool ('gen_msprojects', @ARGV)                     if ( $cmd =~ m/^gen_msproject/ );
361 dpurdie 2281
etool ("jats_${GBE_VCS}release.pl", @ARGV)                  if ( $cmd =~ m/^release/ );
2282
etool ("jats_${GBE_VCS}release.pl", '-extractfiles' ,@ARGV) if ( $cmd =~ m/^extractf/ );
2283
etool ("jats_${GBE_VCS}release.pl", '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^extract/ );
383 dpurdie 2284
 
2285
etool ("jats_svnrelease.pl", '-extractfiles' ,@ARGV) if ( $cmd =~ m/^svnextractf/ );
2286
etool ("jats_svnrelease.pl", '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^svnextract/ );
2287
 
361 dpurdie 2288
etool ("jats_${GBE_VCS}label", @ARGV)                       if ( $cmd =~ m/^label$/ );
299 dpurdie 2289
etool ('jats_sandbox', @ARGV)                       if ( $cmd =~ m/^sandbox$/ );
313 dpurdie 2290
etool ('jats_help', @ARGV)                          if ( $cmd =~ m/^help$/ );
325 dpurdie 2291
etool ('jats_help', '-man', @ARGV)                  if ( $cmd =~ m/^man$/ );
315 dpurdie 2292
etool ('jats_vars.pl', @ARGV)                       if ( $cmd =~ m/^var/ );
227 dpurdie 2293
 
2294
etool ($cmd, @ARGV)                     unless ($opr_done); # Pass to etool if not known
2295
 
2296
do_exit();
2297
#.
2298
 
2299
#-------------------------------------------------------------------------------
2300
#   Documentation
2301
#
2302
 
2303
=pod
2304
 
361 dpurdie 2305
=for htmltoc    CORE::AA::Jats
2306
 
227 dpurdie 2307
=head1 NAME
2308
 
2309
jats - JATS utility interface tool
2310
 
2311
=head1 SYNOPSIS
2312
 
277 dpurdie 2313
 Usage: jats [opts] command [cmd-options]
227 dpurdie 2314
 
2315
 Where opts:
261 dpurdie 2316
    -h, -h -h, -man=[n] - Help messages with increasing verbosity
227 dpurdie 2317
    -cd dir             - Change to specified directory
2318
    -b file             - Use alternate build file
261 dpurdie 2319
    -verbose[=n]        - Verbose operation
2320
    -debug[=n]          - Enable debug mode of JATS scripts
227 dpurdie 2321
    -here               - Disable JATS auto locate of build.pl
2322
    -locate             - Locate build.pl file and change to directory
245 dpurdie 2323
    -locatepkg=pkg      - Locate build.pl. Resolve multiple files via pkg
2764 dpurdie 2324
    -locatefile=file    - Locate specified build file and change to directory
321 dpurdie 2325
    -locatedir=name     - Locate specified directory by scanning to the root
227 dpurdie 2326
    -platform=[name]    - Set GBE_PLATFORM to name   (=+ to append)
2327
    -buildfilter=[xxx]  - Set GBE_BUILDFILTER to xxx (=+ to append)
2328
    -abt=[xxx]          - Set GBE_ABT to xxx (=+ to append)
349 dpurdie 2329
    -java=version       - Alters java version used (1.4, 1.5, 1.6)
227 dpurdie 2330
    -time               - Time build and compile times
2331
    -version=xxx        - Use specified version of JATS
277 dpurdie 2332
    -[no]exportvars     - Export sanitised JATS EnvVars (default)
379 dpurdie 2333
    -logfile=xxxx       - All output is redirected to the specified file
6177 dpurdie 2334
    -[no]script         - Suppress JATS messages.
227 dpurdie 2335
 
331 dpurdie 2336
 Common commands include:
227 dpurdie 2337
    build               - Rebuild the sandbox and makefiles
2338
    make                - Make one or more components
2339
    ant                 - Invoke an ant build
2340
    abt [-java=xxx]     - Invoke the auto build tool
2341
    install             - Install package into local_dpkg_archive
2342
    help                - Display help message
325 dpurdie 2343
    man                 - Display extended help message
227 dpurdie 2344
    vars                - Display JATS related environment variables
2345
 
2346
    create_dpkg         - Install a package into main dpkg_archive
2347
    label               - Labelling functions
6353 dpurdie 2348
    release             - Build a release from a VCS label/tag
2349
    extract             - Extract a release from a VCS label/tag
227 dpurdie 2350
    dpkg_cache          - Maintain a dpkg cache
2351
    gen_msproject       - Generate MSVC project files
361 dpurdie 2352
    sandbox             - Run Sandbox utility
299 dpurdie 2353
 
227 dpurdie 2354
    etool name          - Run internal tool
2355
    eprog name          - Run external tool
2356
    ebin name           - Run JATS binary tool
2357
 
2358
 Shortcut commands. Composites of basic commands
331 dpurdie 2359
    all [opt]           - Same as a "build -noforce" and "make all"
227 dpurdie 2360
    go  [opt]           - Same as a "make all"
2361
    debug [tgt]         - Same as "make debug package_debug"
2362
    prod  [tgt]         - Same as "make prod package_prod"
2363
    clean               - Same as "make clean"
2364
    clobber             - Same as "build clobber"
2365
    *                   - Unknown commands are treated as arguments to etool
2366
 
2367
 Where [cmd-options] are command specific.
325 dpurdie 2368
    Try "jats help command" for details
227 dpurdie 2369
 
2370
=head1 OPTIONS
2371
 
2372
=over 8
2373
 
2374
=item B<-help>
2375
 
2376
Print a brief help message and exits.
2377
 
2378
=item B<-help -help>
2379
 
2380
Print a detailed help message with an explanation for each option.
2381
 
261 dpurdie 2382
=item B<-man[=n]>
227 dpurdie 2383
 
2384
Prints the manual page and exits.
2385
 
261 dpurdie 2386
If a numeric manual level is provide then it will be used to control the
361 dpurdie 2387
verbosity of help provided. This should be in the range of 1 to 3.
261 dpurdie 2388
 
227 dpurdie 2389
=item B<-b file> B<-buildfile file>
2390
 
2391
This option modifies the operation of the "build" command. The command will
2392
use the specified file instead of the normal build.pl file.
2393
 
2394
=item B<-cd dir> B<-changedir dir>
2395
 
2396
This option will change to specified directory before the command is invoked.
2397
 
261 dpurdie 2398
=item B<--verbose[=n]>
227 dpurdie 2399
 
2400
This option will increase the level of verbosity of the JATS command and command
261 dpurdie 2401
invoked by the JATS shell.
227 dpurdie 2402
 
261 dpurdie 2403
If an argument is provided, then it will be used to set the level, otherwise the
2404
existing level will be incremented. This option may be specified multiple times.
227 dpurdie 2405
 
261 dpurdie 2406
=item B<-debug[=n]>
2407
 
227 dpurdie 2408
This option will increase the level of debug output of the JATS command and command
261 dpurdie 2409
invoked by the JATS shell.
227 dpurdie 2410
 
261 dpurdie 2411
If an argument is provided, then it will be used to set the level, otherwise the
2412
existing level will be incremented. This option may be specified multiple times.
2413
 
227 dpurdie 2414
=item B<-here>
2415
 
2416
This option will disable the "autolocate" mechanism of the JATS shell script.
2417
 
2418
By default JATS will "hunt" for a suitable "build.pl" or "makefile.pl" before
2419
executing a build or a make command. JATS will look in the following directories
2420
for a  suitable file. Under some conditions this mechanism is not useful.
2421
 
2422
By default JATS will hunt in the following directories: "." "jats" "build/
2423
jats" ".." "../.." and "../../..".
2424
 
2425
=item B<-locate>
2426
 
2427
This option will cause the JATS wrapper script to locate the build.pl file and
2428
then change to that directory. This allows users to locate the build root of
2429
a project and then issue other JATS commands.
2430
 
2431
If the B<-c> option is also specified then searching will start in the specified
2432
directory.
2433
 
2434
If an alternate build file is specified with the B<-b> option then that filename
2435
will be used in the location process.
2436
 
2437
This option implies a B<-here>. No further scanning will be done.
2438
 
2439
Exactly one build file must be located. If more than buildfile is located then
2440
the locations of the build files is displayed and JATS will terminate.
2441
 
245 dpurdie 2442
 
2443
=item B<-locatepkg=packagename>
2444
 
2445
This option is similar to the B<-locate> option, but it allows the required
2446
build files to be located by ensuring that the required buildfile builds the
2447
specified package.
2448
 
2449
There are two forms in which the B<packagename> can be specified. It can be
361 dpurdie 2450
specified as a full package name and version, or as a package name and the
245 dpurdie 2451
project suffix. ie: jats-api.1.0.0000.cr or jats-api.cr
2452
 
227 dpurdie 2453
=item B<-locatefile=file>
2454
 
2455
This option is similar to the B<-locate> option, but it allows the name of the
2764 dpurdie 2456
build file to be located to be specified.
227 dpurdie 2457
 
2764 dpurdie 2458
If the named file has an '.xml' suffix then the process will look for a pair of
2459
ANT build files of the form xxx.xml and xxxdepends.xml.
2460
 
319 dpurdie 2461
=item B<-locatedir=name>
2462
 
2463
Locate the named directory by scanning from the current directory to the root
321 dpurdie 2464
of the filesystem. This operation is performed before any other location
319 dpurdie 2465
operations and before the B<-cd=path> operation.
2466
 
2467
It may be used to position the jats operation at the root of a view - provided
2468
the view root is known.
2469
 
227 dpurdie 2470
=item B<-platform=[name]>
2471
 
2472
This option will set the JATS specific environment variable GBE_PLATFORM to
2473
the specified name. The existing value of GBE_PLATFORM may be extended by
2474
using "=+".
2475
 
2476
In practice the GBE_PLATFORM variable is of little use. The same effect can be
2477
achieved directly with make targets or with GBE_BUILDFILTER.
2478
 
2479
=item B<-buildfilter=[xxx]>
2480
 
2481
This option will set the JATS specific environment variable GBE_BUILDFILTER to
2482
the specified name. The existing value of GBE_BUILDFILTER may be extended by
2483
using "=+".
2484
 
2485
This option may be used to limit the initial build, and subsequent "make" to a
2486
limited set of platforms.
2487
 
2488
=item B<-abt=[xxx]>
2489
 
2490
This option will set the JATS specific environment variable GBE_ABT to
2491
the specified name The existing value of GBE_ABT may be extended by
2492
using "=+"..
2493
 
2494
This option is used to pass arguments directly to some tools within the
2495
(ABT) Auto Build Tool framework, or to indicate that the build is being
2496
performed within the ABT framework.
2497
 
2498
=item B<-java=version>
2499
 
2500
This option will override the default java version used by the ant builds and
2501
passed to the underlying programs. The path to the Java SDK is determined from
2502
the environment using the version string replacing the '.' with '_'
2503
 
2504
eg: -java=1.5, will examine the environment for JAVA_HOME_1_5 and will set
2505
JAVA_HOME to that value. It will not setup the users PATH or classpath.
2506
 
2507
=item B<-time>
2508
 
2509
When this option is enabled the JATS script will report the runtime of the
2510
underlying, invoked, command.
2511
 
2512
=item B<-version=xxx>
2513
 
2514
When this option is invoked JATS will attempt to use the specified version to
2515
perform all processing. JATS will search the GBE_DPKG_LOCAL, GBE_DPKG_CACHE,
4688 dpurdie 2516
GBE_DPKG_REPLICA, GBE_DPKG, GBE_DPKG_STORE in order to locate the specified 
2517
version of the package.
227 dpurdie 2518
 
2519
The entire command line will be passed to the JATS wrapper script within that
2520
version. This bypasses the jats.bat or jats.sh startup scripts.
2521
 
277 dpurdie 2522
JATS will attempt to transfer the target version to the local cache in an
2523
attempt to improve performance.
227 dpurdie 2524
 
277 dpurdie 2525
=item B<-[no]exportvars>
227 dpurdie 2526
 
361 dpurdie 2527
The default operation is to export sanitized and calculated values to the
277 dpurdie 2528
programs running under JATS. The use of NoExportVars will prevent JATS from
2529
exporting modified EnvVars into the environment. This may be required by
2530
processes, such as the build daemons that need to pick up the current version of
2531
JATS on the fly and not have it fixed when the daemon is started.
227 dpurdie 2532
 
379 dpurdie 2533
=item B<-logfile=xxxx>
2534
 
2535
This option will cause all output to be redirected to the named logroll. Both
2536
STDOUT and STDERR will be redirected.
2537
 
2538
The redirection occurs after the sanity testing that JATS performs and before the
2539
user command is invoked. The redirection occurs after any directory change option
2540
is executed.
2541
 
2542
Output redirection continues until the program terminates. If JATS invokes other
2543
programs or scripts, there default output will also be redirected.
2544
 
6177 dpurdie 2545
=item B<-[no]script>
2546
 
2547
This option will suppress some internal warning messages, generated by the JATS wrapper
2548
script. It is intended to allow JATS to be used with a shell script without the output 
2549
being polluted with internal warnings.
2550
 
2551
The default operation is to show internal warnings. 
2552
 
227 dpurdie 2553
=back
2554
 
2555
=head1 ARGUMENTS
2556
 
2557
=head2 Basic Commands
2558
 
2559
The following commands are invoked directly by the JATS script to wrap the build
2560
tools in a controlled manner.
2561
 
2562
=over 8
2563
 
361 dpurdie 2564
=item L<build|TOOLS::buildlib>
227 dpurdie 2565
 
2566
Build or rebuild the sandbox and makefiles.
2567
 
2568
This command must be used before the component can be "made" and when the
2569
contents of the "buildpl" file change. It is a common mistake to use the "build"
2570
command to much.
2571
 
2572
The script will hunt for a suitable build.pl file before running the build and
2573
make subcommands.
2574
 
361 dpurdie 2575
The build process has a large number of options.
2576
Use L<"JATS build help"|TOOLS::buildlib/"item_help"> to display the complete list.
227 dpurdie 2577
 
361 dpurdie 2578
=item L<make|TOOLS::jmake>
227 dpurdie 2579
 
2580
Make one or more components
2581
 
2582
This command will invoke a suitable "make" program on the makefile found in
2583
the current directory. This makefile should have been generated by JATS.
2584
 
361 dpurdie 2585
The make process has a large number of options. Use
2586
L<"JATS make help"|TOOLS::jmake/"item_help">" to display the complete list.
227 dpurdie 2587
 
2588
=item B<ant>
2589
 
2590
This command will use ANT to build a component. JATS will determine the
2591
build.xml file to use with the following algorithm.
2592
 
2593
    If the files called <Project>depends.xml and <Project>.xml exist then JATS
2594
    will create an 'auto.xml' from the depends file, if one does not already
2595
    exist or is older than the depends.xml file and then use the <Project>.xml
2596
    file as the ant build file.
2597
 
2598
    Otherwise ant is invoked and it will expect a build.xml file.
2599
 
2600
If multiple <Project>depends.xml and <Project>.xml file pairs are found the
2601
command will fail. This can be resolved through the use of the -buildfile=name
2602
option.
2603
 
2604
Ant is invoked with the version of Java specified with the -Java=x.x option.
2605
 
2606
=item B<abt>
2607
 
2608
This command is used to invoke the Auto Build Tool. It will invoke ANT on the
2609
build.xml file in the current directory in such  manner as to not affect the
239 dpurdie 2610
environment of the programs running under ANT.
227 dpurdie 2611
 
361 dpurdie 2612
The remainder of the command line is passed to the ABT, with the exception of
239 dpurdie 2613
the options:
2614
 
2615
=over 8
2616
 
361 dpurdie 2617
=item *
2618
 
2619
-java=x.x. This is used to control the version of Java used by the
349 dpurdie 2620
ABT. The default is 1.6.
227 dpurdie 2621
 
361 dpurdie 2622
=item *
2623
 
2624
-buildfile=name. This is used to provide a different build file to ant.
239 dpurdie 2625
The default build file is 'build.xml'.
2626
 
2627
=back
2628
 
361 dpurdie 2629
=item L<help|TOOLS::jats_help>
227 dpurdie 2630
 
2631
Display the basic help message.
2632
 
361 dpurdie 2633
=item L<vars [-v]|TOOLS::jats_vars>
227 dpurdie 2634
 
2635
This command will display all the JATS related environment variables in a
2636
readable form.
2637
 
2638
Additional information will be displayed if an argument of "-v" is provided.
2639
 
2640
=back
2641
 
2642
=head2 Extended Commands
2643
 
2644
The following commands support the build environment. They are supplemental to
2645
the build environment. They are implemented as extensions to the basic JATS
2646
command scripts.
2647
 
2648
=over 8
2649
 
361 dpurdie 2650
=item L<create_dpkg|TOOLS::create_dpkg>
227 dpurdie 2651
 
2652
This command will install a generated package into main dpkg_archive. This
2653
command should not be used directly by a user as it does not ensure that package
2654
has been created in a repeatable manner - use "jats release".
2655
 
361 dpurdie 2656
=item label
227 dpurdie 2657
 
2658
This command provides a number of useful labelling mechanisms to assist in the
2659
labeling of source code.
2660
 
361 dpurdie 2661
The command will determine the default Version Control System and invoke the VCS
2662
specific utility. This will be one of:
227 dpurdie 2663
 
361 dpurdie 2664
=over 4
227 dpurdie 2665
 
361 dpurdie 2666
=item   *
2667
 
2668
ClearCase: L<cclabel|TOOLS::jats_cclabel>
2669
 
2670
=item   *
2671
 
2672
Subversion: L<svnlabel|TOOLS::jats_svnlabel>
2673
 
2674
=back
2675
 
2676
=item release
2677
 
2678
This command allows a package to be built and released, given a label.
2679
This is the desired release mechanism for manually releasing a package.
2680
 
227 dpurdie 2681
The command has two main uses:
2682
 
361 dpurdie 2683
=over 4
227 dpurdie 2684
 
2685
=item 1
2686
 
2687
Build a package for release. The process will ensure that the build is
2688
controlled and repeatable.
2689
 
2690
=item 2
2691
 
2692
Rebuild a package for test or debugging purposes.
2693
 
2694
=back
2695
 
361 dpurdie 2696
The command will determine the default Version Control System and invoke the VCS
2697
specific utility. This will be one of:
227 dpurdie 2698
 
361 dpurdie 2699
=over 4
2700
 
2701
=item   *
2702
 
2703
ClearCase: L<ccrelease|TOOLS::jats_ccrelease>
2704
 
2705
=item   *
2706
 
2707
Subversion: L<svnrelease|TOOLS::jats_svnrelease>
2708
 
2709
=back
2710
 
2711
=item L<extract|/"release">
2712
 
227 dpurdie 2713
This is the same as "release -extract"
2714
 
2715
 
361 dpurdie 2716
=item L<dpkg_cache|TOOLS::cache_dpkg>
227 dpurdie 2717
 
2718
This utility provides a number of commands to maintain the local cache of
245 dpurdie 2719
dpkg_archive.
227 dpurdie 2720
 
361 dpurdie 2721
=item L<gen_msproject|TOOLS::gen_msprojects>
227 dpurdie 2722
 
2723
This utility will generate a set of Microsoft Studio (Version 6) project and
361 dpurdie 2724
workspace files to encapsulate the JATS build. The resultant project allows
2725
Visual Studio to be used as an editor, source browser, debugger and build tool.
2726
JATS is still used to perform the build.
227 dpurdie 2727
 
361 dpurdie 2728
=item B<install>
2729
 
2730
This command will install a generated "package" into the local_dpkg_archive
2731
directory. This allows a group of packages to be tested before being published
2732
into the global dpkg_archive.
2733
 
2734
=for htmlclass Note
2735
 
2736
Note. This command is no longer needed. The "build" process will place a
2737
shortcut in the local_dpkg_archive to a components "pkg" directory. Other
2738
components will utilize this shortcut directly and pickup the package without
2739
the user needing to "install" the package - a step that can be forgotten.
2740
 
227 dpurdie 2741
=item B<etool name>
2742
 
2743
This command allows any JATS extension program to be run. The programs will by
2744
found in the JATS TOOLS directory.
2745
 
2746
=item B<eprog name>
2747
 
2748
This command allows any JATS extension program to be run.
2749
If the program end in .pl, then it will be run within a perl interpreter.
2750
If the program end in .jar, then it will be run under a java interpreter.
2751
 
2752
=item B<ebin name>
2753
 
2754
This command allows any JATS support program to be run. The programs will by
2755
found in the JATS BIN directory for the current platform. This command allows
2756
a user script to access many of the machine independent utilities in a simple
2757
manner.
2758
 
2759
Example: "JATS ebin ls" - will provide a "real" ls on all platforms.
2760
 
2761
Example: "JATS ebin sh" - will start up the shell used by make.
2762
 
2763
=back
2764
 
2765
=head2 Command Shortcuts
2766
 
2767
The following commands are user shortcuts to the basic commands. The are basic
2768
commands run in sequence.
2769
 
2770
=over 8
2771
 
2772
=item B<all [make_opts]>
2773
 
2774
This command is the same as running the command "build" and "make all".
2775
It will build a component with a single command.
2776
 
2777
If "make_opts" is not present then "make all" is used.
2778
 
2779
If "make_opts" is present then they are passed to the "make" command. In this
2780
manner is it possible to build a WIN32 component of package with a single
2781
command.
2782
 
2783
=item B<go [make_opts]>
2784
 
2785
This command is similar to the "all" shortcut, but it does not "build" the
2786
sandbox. It may be used where the sandbox has already been prepared.
2787
 
2788
=item B<debug [target]>
2789
 
2790
This command is the same as running "make debug package_debug". It will make and
2791
package all the debug components of a sandbox.
2792
 
2793
If any additional arguments are provided to the B<dev> command then they will be
2794
treated as make targets and the commands will be expanded to make and package
2795
the specified debug versions of the names platforms. Make options cannot be
2796
passed in this manner.
2797
 
2798
Example: "JATS dev GAK" will create and package the debug parts for the
2799
GAK_MOS68K and GAK_MOSCF.
2800
 
2801
=item B<prod [target]>
2802
 
2803
This command is the same as running "make prod package_prod". It will make and
2804
package all the debug components of a sandbox.
2805
 
2806
If any additional arguments are provided to the B<prod> command then they will be
2807
treated as make targets and the commands will be expanded to make and package
2808
the specified debug versions of the names platforms. Make options cannot be
2809
passed in this manner.
2810
 
2811
Example: "JATS prod GAK" will create and package the production parts for the
2812
GAK_MOS68K and GAK_MOSCF.
2813
 
2814
=item B<clean>
2815
 
2816
This is the same as "make clean".
2817
 
2818
=item B<clobber>
2819
 
2820
This is the same as "build clobber"
2821
 
2822
=item B<else>
2823
 
2824
Commands that are not known to the JATS wrapper script are passed to etool.
2825
 
2826
ie: "JATS xxxx" is is the same as "JATS etool xxxx".
2827
 
2828
=back
2829
 
2830
=head1 DESCRIPTION
2831
 
2832
JATS is a wrapper script. It provides:
2833
 
361 dpurdie 2834
=over 4
227 dpurdie 2835
 
2836
=item *
2837
 
361 dpurdie 2838
A controlled and sanitized environment to all the build tools.
227 dpurdie 2839
 
2840
=item *
2841
 
2842
The same command interface on all supported machines: Windows, Solaris and
2843
Linux.
2844
 
2845
=item *
2846
 
2847
Provides a framework for extending the build environment toolset.
2848
 
2849
=back
2850
 
315 dpurdie 2851
=head1 RELATED DOCUMENTATION
227 dpurdie 2852
 
361 dpurdie 2853
=over 4
227 dpurdie 2854
 
361 dpurdie 2855
=item   * L<Installation Notes|POD::InstallationNotes>
227 dpurdie 2856
 
361 dpurdie 2857
=item   * L<OverView|POD::OverView>
227 dpurdie 2858
 
361 dpurdie 2859
=item   * L<EnvVars|POD::EnvVars>
255 dpurdie 2860
 
361 dpurdie 2861
=item   * L<PkgArchives|POD::PkgArchives>
227 dpurdie 2862
 
2863
=back
2864
 
361 dpurdie 2865
Use L<jats help|TOOLS::jats_help> to see the available internal documentation.
227 dpurdie 2866
 
315 dpurdie 2867
=head1 EXAMPLES
227 dpurdie 2868
 
315 dpurdie 2869
=over 8
227 dpurdie 2870
 
361 dpurdie 2871
=item   L<JATS help|TOOLS::jats_help>
227 dpurdie 2872
 
315 dpurdie 2873
This will display the available internal documentation.
227 dpurdie 2874
 
361 dpurdie 2875
=item   L<JATS build|TOOLS::buildlib>
227 dpurdie 2876
 
315 dpurdie 2877
This will prime the current package being built ready for "make". The command
2878
will locate the build.pl file and process it. This will locate all the external
2879
packages and generate the required makefiles.
227 dpurdie 2880
 
361 dpurdie 2881
=item   L<JATS make|TOOLS::jmake>
227 dpurdie 2882
 
2883
This will run the GNU make program over the makefiles generated by the "build"
2884
command. This may be executed in a subdirectory in order to limit the targets
2885
that are "made".
2886
 
361 dpurdie 2887
=for htmlclass Note
2888
 
227 dpurdie 2889
B<NOTE:> Do not run "make" without using the JATS wrapper. It will not perform
2890
as expected as the environment will not have been set up correctly.
2891
 
2892
=back
2893
 
2894
=cut
2895