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