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