Subversion Repositories DevTools

Rev

Rev 7547 | Details | Compare with Previous | Last modification | View Log | RSS feed

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