Subversion Repositories DevTools

Rev

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

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