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