Subversion Repositories DevTools

Rev

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

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