Subversion Repositories DevTools

Rev

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