Subversion Repositories DevTools

Rev

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

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