Subversion Repositories DevTools

Rev

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