Subversion Repositories DevTools

Rev

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

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