Subversion Repositories DevTools

Rev

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