Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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