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
################################################################################
773
#   Sanitize the PATH variable
774
#   Some of the Win32 binary tools used by JATS cannot handle lower case Path
775
#   Force an upper case PATH
776
#
777
my $PATH = '';
778
$PATH .= delete( $ENV{ 'Path' } ) if (exists $ENV{ 'Path' });
779
$PATH .= delete( $ENV{ 'path' } ) if (exists $ENV{ 'path' });
780
$PATH .= delete( $ENV{ 'PATH' } ) if (exists $ENV{ 'PATH' });
277 dpurdie 781
$ENV{'PATH'} = $PATH;
227 dpurdie 782
 
783
#
784
#   Windows now defines ComSpec. This is only a problem when programs are
785
#   started up without the use of cmd.exe - like the JATS internal sh.exe
786
#   Correct by deleting the environment variable and forcing it to be uppercase
787
#
788
my $COMSPEC = '';
789
$COMSPEC = delete( $ENV{'COMSPEC'} ) if ( exists $ENV{'COMSPEC'} );
790
 
791
################################################################################
792
#   There is some really ugly interaction between Cygwin, ActiveState Perl 5.8.2
793
#   and xmake. Even if none of the cygwin bits are used within JATS the fact that
794
#   Cygwin is in the path causes problems.
795
#
796
#   Problems seen:
797
#       1) "jats build"     xmake fails with a segment fault. Possibly when
798
#                           displaying an error message
799
#       2) Warnings and messages generated from within Perl don't always appear
800
#          In particular. The output from a Message() within a PLATFORM/xxx file
801
#          does not get displayed.
802
#
803
#   Solution:
804
#       Remove cygwin from the PATH
805
#
806
$PATH =~ s~c:\\cygwin[^;]*;~~ig;
807
 
808
################################################################################
297 dpurdie 809
#   Setup the default JAVA_HOME
810
#   User should specify 1.4, 1.5,1.6 ....
811
#
812
$JAVA_HOME = get_java_home ($opt_java)
813
    if ( $opt_java );
814
PathPrepend ("$JAVA_HOME/bin")
815
    if ( -d $JAVA_HOME );
816
 
343 dpurdie 817
################################################################################
818
#   Setup GBE_VIEWBASE
819
#   Ideally this should be configured externally
820
#
821
unless ( $GBE_VIEWBASE )
822
{
823
    if ( $GBE_UNIX ){
824
        my $HOME = $ENV{'HOME'};
825
        Error ("Unix HOME EnvVar not defined" ) unless ( $HOME );
826
        Error ("Unix HOME directory not found: $HOME" ) unless (-d $HOME );
827
        $GBE_VIEWBASE= "$HOME/jats_cbuilder";
828
    } else {
829
        $GBE_VIEWBASE= 'c:/clearcase';
830
    }
831
}
297 dpurdie 832
 
833
################################################################################
227 dpurdie 834
#   Ensure that the PATH contains the PERL executable
835
#   Need to true path to the PERL executable so that the user has access to some
836
#   of the perl utility programs such as pod2html
837
#
299 dpurdie 838
PathPrepend ($Config{'binexp'});
227 dpurdie 839
 
840
################################################################################
841
#   There is more ugliness if GBE_BIN is not in the users path
842
#   I suspect that it something within xmake (under win32) and that it needs
843
#   to be able to find sh within the path - even though its fully pathed
844
#
845
#   Add GBE_BIN to the start of the path to assist in searching
846
#   Also ensure that we pickup our version of utilities instead of random
847
#   versions.
848
#
297 dpurdie 849
PathPrepend ($GBE_BIN);
227 dpurdie 850
 
851
################################################################################
852
#   Clean PATH
853
#       Remove duplicates
854
#       Remove empty elements
855
#       Clean path endings
245 dpurdie 856
#       Place non-existent paths at the end. They will be seen, but not scanned
227 dpurdie 857
#
858
{
859
    my @new_path;
860
    my @non_exist;
861
    my %seen;
862
    foreach ( split $PSPLIT, $PATH )
863
    {
864
        s~[/\\]+$~~;                                # Remove trailing / or \
865
        my $name = ( $GBE_UNIX ) ? $_ : lc ($_);    # Windows is case insensitive
866
        next unless ( $_ );                         # Remove empty elements
867
        next if ( /^\.+$/ );                        # Remove . and ..
868
        next if ( exists $seen{$name} );            # Remove duplicates
869
        if ( -d $_ ) {
870
            push @new_path, $_;                     # Exists
871
        } else {
245 dpurdie 872
            push @non_exist, $_;                    # Place non existent paths at the end
227 dpurdie 873
        }
874
        $seen{$name} = 1;
875
    }
876
    $PATH = join( $PSPLIT, @new_path, @non_exist );
877
}
878
 
879
################################################################################
880
#   Windows: Ensure that cmd.exe is in the users PATH
881
#            If cmd.exe cannot be found then the 'system' command will not work
882
#
317 dpurdie 883
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 884
{
885
    my $cmd_found;
886
    foreach ( split $PSPLIT, $PATH )
887
    {
888
        my $file = $_ . "/cmd.exe";
889
        Verbose2 ("Look for: $file");
890
        if ( -x $file  )
891
        {
892
            $cmd_found = 1;
893
            Verbose ("Found: $file");
894
            last;
895
        }
896
    }
897
 
898
    Warning( "Users PATH does not contain \"cmd.exe\"",
899
             "System commands may not work" ) unless $cmd_found;
900
}
901
 
902
################################################################################
903
#   Sanitize the Microsoft Visual Studio environment variables LIB and INCLUDE.
904
#   If these have a trailing \ then the generated makefiles
905
#   will fail. This is impossible to detect and fix within make so do it here
906
#
907
#   Note: JATS no longer allows these environment variables through to the
908
#         makefiles.
909
#
317 dpurdie 910
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 911
{
912
    for my $var qw ( LIB INCLUDE )
913
    {
914
        my $evar = $ENV{$var};
915
        if ( $evar )
916
        {
917
            $evar =~ s~\\;~;~g;         # Remove trailing \ from components \; -> ;
918
            $evar =~ s~\\$~~;           # Remove trailing \
919
            $evar =~ s~;$~~;            # Remove trailing ;
920
            $evar =~ s~;;~;~g;          # Remove empty items ;;
921
            $ENV{$var} = $evar;
922
        }
923
    }
924
}
925
 
926
################################################################################
297 dpurdie 927
#   Update the environment variables used by JATS, unless requested otherwise.
227 dpurdie 928
#
277 dpurdie 929
#   If JATS is being used to startup build daemons, then we don't want to
930
#   export many of the calculated values into the environment. In particular
931
#   GBE_CORE, GBE_BIN, GBE_CONFIG and GBE_TOOLS must not be exported as it will
932
#   prevent the daemon from picking up the 'current' version of JATS
933
#
934
#
287 dpurdie 935
 
277 dpurdie 936
if ( $opt_export_vars )
937
{
938
    $ENV{'PATH'}              = $PATH;
939
    $ENV{'GBE_VERSION'}       = $GBE_VERSION;
940
    $ENV{'GBE_CORE'}          = $GBE_CORE;
941
    $ENV{'GBE_BIN'}           = $GBE_BIN;
942
    $ENV{'GBE_CONFIG'}        = $GBE_CONFIG;
943
    $ENV{'GBE_DPLY'}          = $GBE_DPLY;
944
    $ENV{'GBE_DPKG'}          = $GBE_DPKG;
945
    $ENV{'JATS_HOME'}         = $GBE_DPKG;
946
    $ENV{'GBE_DPKG_CACHE'}    = $GBE_DPKG_CACHE;
947
    $ENV{'GBE_DPKG_STORE'}    = $GBE_DPKG_STORE;
948
    $ENV{'GBE_DPKG_LOCAL'}    = $GBE_DPKG_LOCAL;
949
    $ENV{'GBE_SANDBOX'}       = $GBE_SANDBOX;
950
    $ENV{'GBE_DPKG_SBOX'}     = $GBE_DPKG_SBOX;
951
    $ENV{'GBE_PERL'}          = $GBE_PERL;
952
    $ENV{'GBE_TOOLS'}         = $GBE_TOOLS;
953
    $ENV{'GBE_MACHTYPE'}      = $GBE_MACHTYPE;
954
    $ENV{'GBE_HOSTMACH'}      = $GBE_HOSTMACH;
955
    $ENV{'GBE_PLATFORM'}      = $GBE_PLATFORM;
956
    $ENV{'GBE_DRV'}           = $GBE_DRV;
957
    $ENV{'PERL5LIB'}          = $PERL5LIB;
958
    $ENV{'JAVA_HOME'}         = $JAVA_HOME if ($JAVA_HOME);
959
    $ENV{'GBE_JATS_SANE'}     = 1;
960
}
287 dpurdie 961
else
962
{
963
    #
964
    #   Delete, from the environment, values that are related to selecting
965
    #   the version of JATS being used
966
    #
967
    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 ) )
968
    {
969
        delete $ENV{$_};
970
    }
971
}
277 dpurdie 972
 
973
#
974
#   The following don't affect the operation of the build daemons selecting
975
#   the current version of JATS. Some need to be passed through anyway
976
#
227 dpurdie 977
$ENV{'GBE_BUILDFILTER'}   = $GBE_BUILDFILTER;
277 dpurdie 978
$ENV{'GBE_ABT'}           = $GBE_ABT if ($GBE_ABT);
227 dpurdie 979
$ENV{'GBE_DEBUG'}         = $GBE_DEBUG;
980
$ENV{'GBE_VERBOSE'}       = $GBE_VERBOSE;
981
$ENV{'GBE_UNIX'}          = $GBE_UNIX;
982
$ENV{'USER'}              = $USER;
277 dpurdie 983
$ENV{'COMSPEC'}           = $COMSPEC;
279 dpurdie 984
$ENV{'GBE_HOSTNAME'}      = $GBE_HOSTNAME;
343 dpurdie 985
$ENV{'GBE_VIEWBASE'}      = $GBE_VIEWBASE;
361 dpurdie 986
$ENV{'GBE_VCS'}           = $GBE_VCS;
227 dpurdie 987
 
363 dpurdie 988
#
989
#   Warn users of potential problem
990
#   Only do once. May change dirtory while getting here
991
unless ( $GBE_JATS_SANE)
992
{
993
    Warning ("Current working directory contains spaces")
994
        if ( $CWD =~ m/\s/ );
995
}
996
 
997
 
227 dpurdie 998
#-------------------------------------------------------------------------------
297 dpurdie 999
# Function        : PathPrepend
1000
#
1001
# Description     : Prepend stuff to the PATH
1002
#
1003
# Inputs          : Items to prepend
1004
#
1005
# Returns         : Nothing
1006
#                   Modifies $PATH
1007
#
1008
sub PathPrepend
1009
{
299 dpurdie 1010
    foreach my $el ( @_ )
297 dpurdie 1011
    {
299 dpurdie 1012
        # Must NOT change the original argument, just a copy of it.
1013
        # Don't use $_ as this messes up too
1014
        my $item = $el;
297 dpurdie 1015
        $item =~ s~/~\\~g unless ( $GBE_UNIX );
1016
        $PATH = $item . $PSPLIT . $PATH;
1017
    }
1018
}
1019
 
1020
#-------------------------------------------------------------------------------
229 dpurdie 1021
# Function        : LocateJatsVersion
1022
#
245 dpurdie 1023
# Description     : Scan archives looking for a specified version of JATS
229 dpurdie 1024
#                   Complicated by the name change from core_devl to jats
245 dpurdie 1025
#                   that occurred circa version 2.71.7.
229 dpurdie 1026
#                   The required version may be in either of the packages
1027
#
1028
# Inputs          : $version            - Version to locate
1029
#
1030
# Returns         : undef               - if not found
1031
#                   Array of:
1032
#                       Repository
1033
#                       package/version
1034
#
1035
sub LocateJatsVersion
1036
{
1037
    my ($version) = @_;
1038
    my $package;
1039
    my $path;
1040
 
1041
    foreach my $archive qw ( GBE_DPKG_LOCAL GBE_DPKG_CACHE GBE_DPKG GBE_DPKG_STORE )
1042
    {
1043
        no strict 'refs';
1044
        $path = ${$archive};
1045
        use strict 'refs';
1046
        next unless ( $path );
1047
 
1048
        foreach my $package qw( jats core_devl )
1049
        {
1050
            Verbose2( "ExamineDir: $path/$package/$version" );
1051
            if ( -d "$path/$package/$version" )
1052
            {
283 dpurdie 1053
                return $path, "$package/$version";
229 dpurdie 1054
            }
1055
        }
1056
    }
283 dpurdie 1057
    return;
229 dpurdie 1058
}
1059
 
1060
 
1061
#-------------------------------------------------------------------------------
227 dpurdie 1062
# Function        : TestDirectoryConfig
1063
#
1064
# Description     : Sanity test a user configurable directory or file
1065
#                   Must not contain spaces
1066
#                   Must not be a network drive ie: //computer
1067
#
1068
# Inputs          :
1069
#
1070
# Returns         :
1071
#
1072
sub TestDirectoryConfig
1073
{
1074
    my ($dir) = @_;
1075
 
1076
    no strict 'refs';
1077
    my $val = ${$dir};
1078
 
1079
    if ( $val )
1080
    {
1081
        #
1082
        #   Cleanup the path
1083
        #
1084
        $val =~ tr~\\/~/~s;
1085
        $val =~ s~/+$~~;
255 dpurdie 1086
        $val = '' if ( $val eq '-' || $val eq 'none' );
227 dpurdie 1087
        ${$dir} = $val;
1088
 
1089
        ReportError("$dir path cannot contain spaces: $val") if ( $val =~ m/\s/ );
1090
        ReportError("$dir path cannot be a computer name: $val") if ( $val =~ m~^//~  );
1091
    }
1092
    use strict 'refs';
283 dpurdie 1093
    return;
227 dpurdie 1094
}
1095
 
1096
#-------------------------------------------------------------------------------
1097
# Function        : change_dir
1098
#
1099
# Description     : change directory to the specified directory
1100
#
1101
# Inputs          : $1      - Target directory
1102
#
1103
# Returns         :
1104
#
1105
sub change_dir
1106
{
1107
    my ($dir) = @_;
1108
 
363 dpurdie 1109
    if ( $dir && $dir ne '.' )
227 dpurdie 1110
    {
1111
        Verbose ("Changing to JATS build directory: $dir");
1112
        chdir $dir || Error ("Bad change directory: $dir");
363 dpurdie 1113
 
1114
        #
1115
        #   Reset the CWD
1116
        #   Note: Don't use `pwd`. This sucks for so many reasons including
1117
        #         the fact that it may not be available until this wrapper
1118
        #         script has done it job.
1119
        #
1120
        $CWD = getcwd();
367 dpurdie 1121
        Error ("Bad change directory: $dir","Cannot determine current directory - may be protected" )unless ( defined $CWD );
363 dpurdie 1122
        $CWD =~tr~\\/~/~s;
227 dpurdie 1123
    }
1124
}
1125
 
1126
#-------------------------------------------------------------------------------
277 dpurdie 1127
# Function        : scan_for_dir
1128
#
1129
# Description     : Scan from the current directory up to the root
1130
#                   of the current file system looking for a named
1131
#                   directory
1132
#
1133
# Inputs          : $target                 - Directory to locate
1134
#
1135
# Returns         : full_path               - Path of dir
1136
#                   full_dir                - Containng dir
1137
#
1138
 
1139
sub scan_for_dir
1140
{
1141
    my ($target) = @_;
1142
    Verbose2 ("Scan for $target");
1143
 
319 dpurdie 1144
    my $test_dir = $CWD || getcwd();
277 dpurdie 1145
    {
1146
        do
1147
        {
1148
            #
1149
            #   Stop at /home to prevent unix automounter spitting
1150
            #   lots of error messages
1151
            #
1152
            last if ( $test_dir =~ m~/home$~ );
1153
            Verbose2 ("Testing: $test_dir");
1154
 
1155
            my $test_path = $test_dir . '/' . $target;
1156
            if ( -d $test_path )
1157
            {
1158
                Verbose ("Found $target: $test_path");
1159
                return $test_path, $test_dir;
1160
            }
1161
            #
1162
            #   Remove one directory
1163
            #   Terminate the loop when no more can be removed
1164
            #
1165
        } while ( $test_dir =~ s~[/][^/]*$~~ );
1166
    }
1167
    return '','';
1168
}
1169
 
1170
#-------------------------------------------------------------------------------
227 dpurdie 1171
# Function        : get_java_home
1172
#
1173
# Description     : Convert user java option into a full path,or die
1174
#
1175
# Inputs          : User option
1176
#
1177
# Returns         : Full path
1178
#
1179
sub get_java_home
1180
{
1181
    my ($java) = @_;
1182
    my $jv = "JAVA_HOME_$java";
1183
    $jv =~ s~\.~_~g;
1184
 
1185
    unless ( exists($ENV{$jv}) )
1186
    {
1187
        Error ("Unknown JAVA version: $java",
1188
               "Looking for EnvVar: $jv",
1189
               "Example Usage: -java=1.5");
1190
    }
1191
    my $rv = $ENV{$jv};
1192
    unless ( -d $rv )
1193
    {
1194
        Error ("Java home path not found: $jv",
1195
               "Looking for: $rv" );
1196
    }
1197
    return $rv;
1198
}
1199
 
1200
#-------------------------------------------------------------------------------
1201
# Function        : get_version
1202
#
1203
# Description     : Return the version of JATS being run
1204
#                   JATS should be run from a "package"
1205
#                   The package should have a descpkg file
1206
#                   Use this file
1207
#
1208
# Inputs          :
1209
#
1210
# Returns         : A string
1211
#
1212
sub get_version
1213
{
229 dpurdie 1214
    #
1215
    #   The version number is embedded into this script by the release process
1216
    #   The text [V]ERSION_TAG will be replaced by the real version number
245 dpurdie 1217
    #   If this has not occurred then we know that the release is not official
229 dpurdie 1218
    #   Need to be a little bit careful about the tag name
1219
    #
1220
    return ("Unreleased Version. Version tag has not been set")
1221
        if ( $GBE_NOT_RELEASED );
1222
 
227 dpurdie 1223
    return "$GBE_VERSION [ Internal. Not an installed package ]"
1224
        if ( ! -f "$GBE_CORE/descpkg" );
1225
 
1226
    my $rec;
1227
    return $rec->{'VERSION_FULL'}
1228
        if ($rec = ReadDescpkg ( "$GBE_CORE/descpkg" ) );
1229
 
1230
    return "ERROR";
1231
}
1232
 
1233
#-------------------------------------------------------------------------------
1234
# Function        : print_version
1235
#
1236
# Description     :
1237
#
1238
# Inputs          :
1239
#
1240
# Returns         :
1241
#
1242
sub print_version
1243
{
1244
    #
1245
    #   Allow user to specify verboseness as an argument
1246
    #
1247
    foreach  ( @_ )
1248
    {
1249
        $GBE_VERBOSE++ if ( m/^-v/ );
1250
    }
1251
 
1252
    Message get_version();
1253
    Message "Internal: $GBE_VERSION" if ($GBE_VERBOSE);
1254
    $opr_done = 1;
283 dpurdie 1255
    return;
227 dpurdie 1256
}
1257
 
1258
 
1259
#-------------------------------------------------------------------------------
1260
#
1261
#   Give the user a clue
1262
#
1263
sub help
1264
{
1265
    my ($level) = @_;
1266
    $level = $opt_help unless ( $level );
1267
 
1268
    pod2usage(-verbose => 0, -message => "Version: ". get_version())  if ($level == 1 );
261 dpurdie 1269
    pod2usage(-verbose => $level - 1 );
227 dpurdie 1270
}
1271
 
1272
#-------------------------------------------------------------------------------
309 dpurdie 1273
# Function        : find_jats_dir
227 dpurdie 1274
#
309 dpurdie 1275
# Description     : Find a JATS build directory
1276
#                   Can be supressed with JATS '-here' command line option
227 dpurdie 1277
#
309 dpurdie 1278
# Inputs          : files               - Files to look for
1279
#                   options
1280
#                       --Ant           - Allow Ant files too
295 dpurdie 1281
#
309 dpurdie 1282
# Returns         : Will not return if not found
1283
#                   Will 'cd' to the build directory
1284
#
227 dpurdie 1285
sub find_jats_dir
1286
{
309 dpurdie 1287
    my $allow_ant;
1288
    my @FILES;
1289
    my $DIR;
1290
    my $check_file;
1291
 
227 dpurdie 1292
    #
1293
    #   Autodetect suppressed ?
1294
    #
1295
    return if ( $opt_here );
1296
 
309 dpurdie 1297
    #
1298
    #   Collect options
1299
    #   Collect the rest of the arguments
1300
    #
1301
    foreach ( @_ )
1302
    {
1303
        if ( m/^--Ant/ ) {
1304
            $allow_ant = 1;
1305
        }
1306
        else {
1307
            push @FILES, $_;
1308
        }
1309
    }
1310
 
227 dpurdie 1311
    push @FILES, @BUILD_FILE_ALT;
309 dpurdie 1312
    push @FILES, 'build.xml' if ( $allow_ant );
1313
 
1314
    #
1315
    #   Parent directories to search
1316
    #   Child dirs to search
1317
    #
227 dpurdie 1318
    my @SEARCH = qw( . .. ../.. ../../.. );
309 dpurdie 1319
    my @CHILD  = ('', '/jats', '/build', '/build/jats' );
227 dpurdie 1320
 
1321
    #
1322
    #   Locate the JATS build files
1323
    #   Allow the user to be in a number of parent directories
1324
    #
309 dpurdie 1325
    scan:
227 dpurdie 1326
    for my $ROOTDIR (@SEARCH)
1327
    {
309 dpurdie 1328
        for my $SUBDIR (@CHILD)
227 dpurdie 1329
        {
309 dpurdie 1330
            $DIR = $ROOTDIR . $SUBDIR;
227 dpurdie 1331
            next unless -d $DIR;
1332
 
283 dpurdie 1333
            for my $FILE ( @FILES)
227 dpurdie 1334
            {
309 dpurdie 1335
                $check_file = $DIR . '/' . $FILE;
227 dpurdie 1336
                Verbose2 ("Check for: $check_file");
309 dpurdie 1337
                last scan if ( -f $check_file );
1338
            }
1339
 
1340
            next unless ( $allow_ant );
1341
            foreach ( glob($DIR . '/*depends.xml' ) )
1342
            {
1343
                Verbose2 ("Check for: $_");
1344
                if ( m/(.+)depends.xml/ )
227 dpurdie 1345
                {
309 dpurdie 1346
                    $check_file = "$1.xml";
1347
                    last scan if ( -f $check_file );
227 dpurdie 1348
                }
1349
            }
1350
        }
309 dpurdie 1351
        $DIR = '';
227 dpurdie 1352
    }
309 dpurdie 1353
 
1354
    #
1355
    #   Change to the build directory if one has been found
1356
    #
1357
    if ( $DIR )
1358
    {
1359
        Verbose2 ("Found check file: $check_file");
1360
        change_dir ( $DIR );
1361
    }
1362
    else
1363
    {
1364
        Error ( 'JATS build directory not found.',
1365
                "Cannot locate: @FILES",
1366
                $allow_ant ? 'or Ant <Package>.xml <Package>depends.xml pair' : undef,
1367
                'Use -here option to supress this test'
1368
                );
1369
    }
227 dpurdie 1370
}
1371
 
1372
#-------------------------------------------------------------------------------
1373
#
295 dpurdie 1374
#   Determine the real build file to use
1375
#   Will select from a list of known build files.
227 dpurdie 1376
#
295 dpurdie 1377
sub getBuildFile
227 dpurdie 1378
{
1379
    my $build_file = $BUILD_FILE;
1380
    #
1381
    #   Use an alternative buildfile - if it exists
1382
    #   Do not use this file if the user has specified a buildfile
1383
    #
1384
    unless ( $BUILD_FILE_SET )
1385
    {
1386
        Verbose ("Search for alternate build file");
1387
        foreach my $test_file ( @BUILD_FILE_ALT )
1388
        {
1389
            Verbose2 ("Search for alternate build file: $test_file");
1390
            if ( -f $test_file )
1391
            {
1392
                $build_file = $test_file;
1393
                Message ("=== USING ALTERNATE BUILDFILE: $build_file ===");
1394
                last;
1395
            }
1396
        }
1397
    }
295 dpurdie 1398
   return $build_file;
1399
}
227 dpurdie 1400
 
295 dpurdie 1401
#-------------------------------------------------------------------------------
1402
#
1403
#   Kick off the build process
1404
#
1405
sub build
1406
{
1407
    my $build_file = $BUILD_FILE;
1408
    (my $name = $CWD) =~ s~^.*/~~ ;
1409
    $opr_done = 1;
1410
 
1411
    find_jats_dir($build_file);
1412
    Message ("=== Building $name ===");
1413
    $build_file = getBuildFile();
1414
 
227 dpurdie 1415
    #
1416
    #   Jats/make does not handle file systems with spaces in the path names
1417
    #
1418
    Error('$CWD path cannot contain spaces') if ( $CWD =~ m/\s/ );
1419
 
333 dpurdie 1420
    $RESULT = System ($GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", @_ );
227 dpurdie 1421
 
283 dpurdie 1422
    Message ("=== Build $name NOT complete ===") if     ( $RESULT  );
1423
    Message ("=== Build $name complete ===")     unless ( $RESULT );
227 dpurdie 1424
    return $RESULT
1425
}
1426
 
1427
#-------------------------------------------------------------------------------
1428
# Function        : bmake_it
1429
#
1430
# Description     : Combo build and make operations
1431
#
1432
# Inputs          : ...     - COMMANDS or Make arguments.
1433
#                             Key commands are BUILD and INSTALL
1434
#
1435
# Returns         : RESULT code
1436
#
1437
sub bmake_it
1438
{
1439
    my @make_args = @_;
1440
    my $all = 1;
1441
    my $msg;
1442
    $opr_done = 1;
1443
 
1444
    if ( $make_args[0] && $make_args[0] eq 'NOTALL' )
1445
    {
1446
        $all = 0;
1447
        shift @make_args;
1448
    }
1449
    elsif ( $make_args[0] && $make_args[0] eq 'BUILD' )
1450
    {
1451
        Verbose ("Makeit build") ;
1452
        $msg = "Component not built";
331 dpurdie 1453
        build('-noforce');
227 dpurdie 1454
        shift @make_args;
1455
    }
1456
 
1457
    unless ( $RESULT )
1458
    {
1459
        push @make_args, '-default=all' if ( $all );
1460
        Verbose ("Makeit make @make_args") ;
1461
 
309 dpurdie 1462
        find_jats_dir( 'makefile.pl', 'Makefile.gbe', $BUILD_FILE );
227 dpurdie 1463
        Error ("No Makefile.gbe file found") unless ( -f 'Makefile.gbe' );
1464
 
1465
        etool ( 'jmake.pl', @make_args );
1466
        $msg = "Component not made";
1467
        @make_args = ();
1468
    }
1469
 
1470
 
1471
    Verbose ("Makeit Result: $RESULT") ;
1472
    Error ( $msg ) if ( $RESULT );
1473
    return  if ( $RESULT );
1474
}
1475
 
1476
#-------------------------------------------------------------------------------
1477
# Function        : dev_expand
1478
#
1479
# Description     : Expand the users arguments to the "debug/prod" command
1480
#                   "debug/prod" builds and packages debug stuff
1481
#
1482
#                   Ignore make options.
1483
#
1484
# Inputs          : target
1485
#                   Argument list
1486
#
1487
# Returns         : expanded argument list
1488
#
1489
sub dev_expand
1490
{
1491
    my @resultd;
1492
    my @resultp;
1493
    my @args;
1494
    my @opts;
1495
 
1496
    #
1497
    #   Remove options from the argument list
1498
    #
1499
    foreach ( @_ )
1500
    {
1501
        if ( m~=~ || m~^-~ ) {
1502
            push @opts, $_;
1503
        } else {
1504
            push @args, $_;
1505
        }
1506
    }
1507
 
1508
    my $target = shift @args;
1509
    my @cmd = $target;
1510
    if ( $#args < 0 )
1511
    {
1512
        push @cmd, "package_$target";
1513
    }
1514
    else
1515
    {
1516
        foreach ( @args )
1517
        {
1518
            push @resultd, $_ . "_$target";
1519
            push @resultp, $_ . "_package_$target";
1520
            @cmd = ();
1521
        }
1522
    }
1523
 
1524
    return (@cmd, @resultd, @resultp, @opts);
1525
}
1526
 
1527
#-------------------------------------------------------------------------------
1528
# Function        : install_pkg
1529
#
1530
# Description     : Install the built package into local_dpkg_archive
1531
#                   This will make it available for use, without populating the
1532
#                   global archive
1533
#
1534
#                   This is done through an external utility to maintain
1535
#                   consistent interface
1536
#
1537
sub install_pkg
1538
{
1539
 
309 dpurdie 1540
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1541
    etool ( 'create_dpkg.pl', '-archive=local', '-quiet', '-override',  @_ );
1542
}
1543
 
1544
#-------------------------------------------------------------------------------
1545
# Function        : create_dpkg
1546
#
1547
# Description     : Install a package into the main dpkg_archive
1548
#                   This is done through an external utility to maintain
1549
#                   consistent interface
1550
#
1551
#                   This function is simply an easy way to access the utility
1552
 
1553
sub create_dpkg
1554
{
309 dpurdie 1555
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1556
    etool ( 'create_dpkg.pl',  @_ );
1557
}
1558
 
1559
#-------------------------------------------------------------------------------
1560
# Function        : etool
1561
#
1562
# Description     : Invoke an external tool program written in PERL
1563
#
1564
# Arguments       : $1  Name of the program to run
1565
#                       With optional .pl suffix
1566
#                   $2+ Program arguments
1567
#
1568
sub etool
1569
{
1570
    my $command = shift;
1571
    my $cmd;
1572
    my @etool_path = ( "$ENV{'GBE_TOOLS'}",
1573
                       "$ENV{'GBE_TOOLS'}/DEPLOY",
1574
                       "$ENV{'GBE_TOOLS'}/LOCAL" );
1575
    if ( $command )
1576
    {
1577
        #
1578
        #   Locate a potential tool
1579
        #   These will have the user name or a .pl extension
1580
        #
1581
        ETOOL_SEARCH:
1582
        foreach my $ext ( '', '.pl' )
1583
        {
1584
            foreach my $dir ( @etool_path )
1585
            {
297 dpurdie 1586
                $cmd = "$dir/jats_$command$ext";
1587
                last ETOOL_SEARCH if ( -f $cmd );
1588
 
227 dpurdie 1589
                $cmd = "$dir/$command$ext";
1590
                last ETOOL_SEARCH if ( -f $cmd );
1591
            }
1592
            $cmd='';
1593
        }
1594
 
1595
        Error ("Tool not found: $command", "Search path:", @etool_path) unless $cmd;
1596
        $RESULT = System ( $GBE_PERL, $cmd, @_ );
1597
    }
1598
    else
1599
    {
1600
        #
1601
        #   Display on the .pl commands
1602
        #
1603
        display_commands("Available Tools", \@etool_path, ['*.pl'] );
1604
    }
1605
 
1606
    $opr_done = 1;
1607
}
1608
 
1609
#-------------------------------------------------------------------------------
1610
# Function        : ebin
1611
#
1612
# Description     : Invoke an external JATS provided binary
1613
#                   within the JATS toolset
1614
#
1615
# Arguments       : $1  Name of the program to run
1616
#                   $2+ Program arguments
1617
#
1618
sub ebin
1619
{
1620
    my $command = shift;
1621
    my $cmd;
1622
    my @ebin_path = ( "$GBE_BIN" );
1623
 
1624
    if ( $command )
1625
    {
1626
        #
1627
        #   Locate a potential executable
1628
        #   This
1629
        #
1630
        ETOOL_SEARCH:
1631
        foreach my $ext ( '', '.exe', '.sh' )
1632
        {
1633
            foreach my $dir ( @ebin_path )
1634
            {
1635
                $cmd = "$dir/$command$ext";
1636
                last ETOOL_SEARCH if ( -f $cmd );
1637
            }
1638
            $cmd='';
1639
        }
1640
 
1641
        Error ("Program not found: $command", "Search path:", @ebin_path) unless $cmd;
1642
        $RESULT = System ( $cmd, @_ );
1643
    }
1644
    else
1645
    {
1646
        #
1647
        #   Display a list of programs
1648
        #
1649
        display_commands("Available Programs", \@ebin_path, ['*'] );
1650
    }
1651
 
1652
    $opr_done = 1;
1653
}
1654
 
1655
#-------------------------------------------------------------------------------
1656
# Function        : eprog
1657
#
1658
# Description     : Invoke an external program
1659
#                   Will detect local .pl files and execute them
1660
#                   Will detect local .jar files and execute them
229 dpurdie 1661
#                   Will detect local .bat files and execute them
227 dpurdie 1662
#
1663
# Arguments       : $1  Name of the program to run
1664
#                   $2+ Program arguments
1665
#
1666
sub eprog
1667
{
229 dpurdie 1668
    Verbose ("eprog: @_");
315 dpurdie 1669
    my $name = fix_command_name (shift @_);
227 dpurdie 1670
    Error ("eprog. No program specified") unless ( $name );
1671
 
229 dpurdie 1672
    $name .= ".pl"     if ( -f "${name}.pl" );
1673
    $name .= ".jar"    if ( -f "${name}.jar" );
1674
    $name .= ".bat"    if ( -f "${name}.bat" );
227 dpurdie 1675
 
229 dpurdie 1676
    #
245 dpurdie 1677
    #   On Windows programs in the CWD will be found
1678
    #   Mimic this behaviour on Unix
229 dpurdie 1679
    #
1680
    $name = "./$name" if ( $name !~ m~/~ && -f "./$name");
1681
 
227 dpurdie 1682
    if ( $name =~ m~\.pl$~ ) {
1683
        $RESULT = System ( $GBE_PERL, $name, @_ );
1684
 
1685
    } elsif ( $name =~  m~\.jar$~ ) {
1686
        $RESULT = System ( "$JAVA_HOME/bin/java", '-jar', $name, @_);
1687
 
1688
    } else {
229 dpurdie 1689
        #
1690
        #   Ensure .bat files are pathed with \, and not / characters
1691
        #   The windows command interpreter does not like /
1692
        #
1693
        $name =~ s~/~\\~g if ( $name =~ m~\.bat$~ );
1694
 
227 dpurdie 1695
        $RESULT = System ( $name, @_ );
1696
    }
1697
 
1698
    $opr_done = 1;
1699
}
1700
 
1701
#-------------------------------------------------------------------------------
1702
# Function        : display_commands
1703
#
1704
# Description     : Display a list of commands from a specified list of dirs
1705
#                   Internal helper function
1706
#
1707
# Inputs          : $title      - Display header
1708
#                   $ref_path   - Ref to an array that contains the search path
1709
#                   $ref_ext    - Ref to an array of valid patterns
1710
#
1711
# Returns         : Nothing
1712
#
1713
sub display_commands
1714
{
1715
    my ( $title, $ref_path, $ref_ext ) = @_;
1716
 
1717
    #
1718
    #   Display a list of commands
1719
    #
1720
    my %list;
1721
    foreach ( @$ref_path )
1722
    {
1723
        foreach my $ext ( @$ref_ext )
1724
        {
1725
            foreach my $file (  glob( "$_/$ext") )
1726
            {
1727
                $file =~ s~.*/~~ unless $GBE_VERBOSE;
1728
                $list{$file} = 1;
1729
            }
1730
        }
1731
    }
1732
 
1733
    my $count = 0;
1734
    my $limit = $GBE_VERBOSE ? 1 : 3;
1735
    print "$title:\n";
1736
    foreach ( sort keys %list )
1737
    {
1738
        printf "%-26s", $_;
1739
        print "\n" if ( !( ++$count % $limit) );
1740
    }
1741
}
1742
 
1743
#-------------------------------------------------------------------------------
315 dpurdie 1744
# Function        : fix_command_name
1745
#
1746
# Description     : Fix a command name parameter
1747
#                   Simplify use of cygwin for some users by allowing
1748
#                   that path of external tools to be a cygwin path
1749
#
1750
# Inputs          : cmd             - command
1751
#
1752
# Returns         : cleaned up version of cmd
1753
#
1754
sub fix_command_name
1755
{
1756
    my ($cmd) = @_;
1757
 
1758
    unless ( $GBE_UNIX )
1759
    {
1760
        #
1761
        #   Cygwin kludge
1762
        #       Replace /cygdrive/DriveLetter/ - with DriveLetter:/
1763
        #       Replace /DriveLetter/          - With DriveLetter:/
1764
        #
1765
        $cmd =~ s~^/cygdrive/([A-Z])/(.*)~$1:/$2~i;
1766
        $cmd =~ s~^/([A-Z])/(.*)~$1:/$2~i;
1767
    }
1768
    return $cmd;
1769
}
1770
 
1771
 
1772
#-------------------------------------------------------------------------------
227 dpurdie 1773
# Function        : run_ant
1774
#
1775
# Description     : Invoke ant
1776
#                   If the current directory looks like an ERG build system, then
1777
#                   create and maintain an auto.xml file. Otherwise simply invoke ant
1778
#
1779
# Inputs          : $1+ program arguments
1780
#
1781
sub run_ant
1782
{
1783
    my $JAVA_HOME = $ENV{JAVA_HOME} || Error ("JAVA_HOME is not defined in the environment");
1784
    my $ANT_HOME  = $ENV{ANT_HOME}  || Error ("ANT_HOME is not defined in the environment" );
1785
 
1786
    #
1787
    #   Detect an ERG formatted build
1788
    #   This will have two files <projectname>.xml and <projectname>depends.xml
1789
    #   Create the 'auto.xml' file only if its not present
1790
    #
1791
    my @ant_arg;
1792
    my @flist;
1793
    my $basename = '';
235 dpurdie 1794
    my $scanner = '*depends.xml';
227 dpurdie 1795
 
1796
    #
1797
    #   Use specified build file to resolve multiple names
1798
    #   Strip any trailing depends.xml to make it user friendly
1799
    #
1800
    if ( $BUILD_FILE_SET )
1801
    {
1802
        $basename = $BUILD_FILE;
1803
        $basename =~ s~\.xml$~~;
1804
        $basename =~ s~depends$~~;
235 dpurdie 1805
        $scanner = "${basename}depends.xml";
227 dpurdie 1806
        Verbose ("Using buildfile: $basename");
1807
    }
1808
 
235 dpurdie 1809
    my @buildlist = glob($scanner);
227 dpurdie 1810
    foreach ( @buildlist )
1811
    {
1812
        if ( m/(.+)depends.xml/ )
1813
        {
1814
            my $pname = $1;
1815
            push @flist, $pname if ( -f "$pname.xml" );
1816
        }
1817
    }
1818
 
1819
    if ( $#flist >= 0 )
1820
    {
1821
        Error ("Multiple depends.xml files found:", @flist,
297 dpurdie 1822
               "Use 'jats -buildfile=name ant ...' to resolve") if ( $#flist > 0 );
227 dpurdie 1823
 
1824
        my $depend = "$flist[0]depends.xml";
1825
        @ant_arg = ('-f', "$flist[0].xml");
1826
 
1827
        Message ("Ant using projectfiles: $flist[0].xml");
1828
 
1829
        #
367 dpurdie 1830
        #   Create auto.xml if we have a depends.xml
227 dpurdie 1831
        #
367 dpurdie 1832
        if ( -f $depend )
227 dpurdie 1833
        {
367 dpurdie 1834
            #
1835
            #   Check for depends.xml newer than auto.xml.
1836
            #
1837
            my $auto_timestamp   = (stat('auto.xml'))[9] || 0;
1838
            my $depend_timestamp = (stat($depend))[9];
1839
            if ( $depend_timestamp > $auto_timestamp )
1840
            {
1841
                Message ("Creating: auto.xml");
1842
                copy( $depend, 'auto.xml' );
1843
                chmod 0777, 'auto.xml';
1844
            }
227 dpurdie 1845
        }
367 dpurdie 1846
        else
1847
        {
1848
            Warning ("Project file does not have a depends.xml file");
1849
        }
227 dpurdie 1850
    }
1851
    elsif ( $BUILD_FILE_SET  )
1852
    {
1853
        Error ("Specified build file pair not found:", $basename, $basename . "depends.xml");
1854
    }
1855
    #
1856
    #   The ant provided startup scripts don't return an exit code under
1857
    #   windows. Invoke ant directly
1858
    #
1859
    launch_ant ( $JAVA_HOME, $ANT_HOME, @ant_arg, @_ );
1860
    $opr_done = 1;
1861
}
1862
 
1863
#-------------------------------------------------------------------------------
1864
# Function        : run_abt
1865
#
1866
# Description     : Invoke auto build tool (older form)
1867
#                   Options for the ABT
1868
#                       --Java=x.x
1869
#                   Invoke ANT for the ABT using a specified version of Java
1870
#                   Do not play with the user environment.
297 dpurdie 1871
#                   Don't stick java path into environment
227 dpurdie 1872
#
1873
# Inputs          : $1+ program arguments
1874
#
1875
sub run_abt
1876
{
279 dpurdie 1877
    my $ABT_JAVA = 'JAVA_HOME_1_6';         # Default version for the ABT
227 dpurdie 1878
    my $JAVA_HOME = $ENV{$ABT_JAVA};
1879
    my $ANT_HOME  = $ENV{ANT_HOME};
1880
    my @abt_arg;
239 dpurdie 1881
    my $buildfile = 'build.xml';
227 dpurdie 1882
 
1883
    ErrorConfig( 'name'    => 'JATS ABT' );
1884
 
1885
    #
239 dpurdie 1886
    #   Use the user specified buildfile
1887
    #
1888
    $buildfile = $BUILD_FILE
1889
        if ( $BUILD_FILE_SET );
1890
 
1891
    #
227 dpurdie 1892
    #   Extract known options
1893
    #
1894
    foreach  ( @_ )
1895
    {
1896
        if ( m/-java=(.*)/ ) {
1897
            $JAVA_HOME = get_java_home($1);
239 dpurdie 1898
 
1899
        } elsif ( m/^-buildfile=(.+)/ ) {
1900
            $buildfile = $1;
1901
 
227 dpurdie 1902
        } else {
1903
            push @abt_arg, $_;
1904
        }
1905
    }
1906
 
1907
    Error ("$ABT_JAVA is not defined in the environment") unless $JAVA_HOME;
1908
    Error ("ANT_HOME is not defined in the environment" ) unless $ANT_HOME;
239 dpurdie 1909
    Error ("Ant buildfile not found: $buildfile" ) unless (-f $buildfile);
227 dpurdie 1910
 
1911
    #
239 dpurdie 1912
    #   Insert correct build file arguments
1913
    #
279 dpurdie 1914
    push @abt_arg, '-buildfile', $buildfile;
1915
 
1916
    #
1917
    #   Add current directory as java library directory, but only if
1918
    #   it contains JAR files.
1919
    #
1920
    push @abt_arg, '-lib', $CWD
1921
        if ( glob ('*.jar') );
239 dpurdie 1922
 
1923
    #
227 dpurdie 1924
    #   Use the ant-launcher to invoke ant directly
1925
    #
1926
    launch_ant ( $JAVA_HOME, $ANT_HOME, @abt_arg );
1927
    $opr_done = 1;
1928
}
1929
 
1930
#-------------------------------------------------------------------------------
1931
# Function        : launch_ant
1932
#
1933
# Description     : Start ANT - with sanity checking
1934
#
1935
# Inputs          : JAVA_HOME
1936
#                   ANT_HOME
1937
#                   @user_args
1938
#
1939
# Returns         : Result Code
1940
#
1941
sub launch_ant
1942
{
1943
    my ($JAVA_HOME, $ANT_HOME, @user_args ) = @_;
1944
 
1945
    Error ("Directory not found: $JAVA_HOME") unless ( -d "$JAVA_HOME" );
1946
    Error ("Program not found: $JAVA_HOME/bin/java") unless ( -e "$JAVA_HOME/bin/java" || -e "$JAVA_HOME/bin/java.exe" );
1947
    Error ("Jar not found: $ANT_HOME/lib/ant-launcher.jar") unless ( -e "$ANT_HOME/lib/ant-launcher.jar" );
1948
    Error ("Directory not found: $ANT_HOME") unless ( -d "$ANT_HOME" );
1949
    Error ("Directory not found: $ANT_HOME/lib") unless ( -d "$ANT_HOME/lib" );
1950
 
1951
    #
1952
    #   Use the ant-launcher to invoke ant directly
1953
    #
1954
    $RESULT = System ( "$JAVA_HOME/bin/java",
1955
                       "-classpath","$ANT_HOME/lib/ant-launcher.jar",
1956
                       "-Dant.home=$ANT_HOME",
1957
                       "org.apache.tools.ant.launch.Launcher",
1958
                       "-lib","$ANT_HOME/lib",
1959
                       @user_args
1960
                       );
1961
 
1962
   return $RESULT;
1963
}
1964
 
1965
 
1966
#-------------------------------------------------------------------------------
1967
#
1968
#   Cleanup the sandbox
1969
#   Perform a "make clobber" then a "build clobber"
1970
#
1971
sub clobber
1972
{
1973
    Message ("=== Removing ======");
1974
    find_jats_dir( $BUILD_FILE );
295 dpurdie 1975
    my $build_file = getBuildFile();
1976
 
227 dpurdie 1977
 
1978
    #
1979
    #   Run a "make clobber" to clean out "everything"
1980
    #
1981
    etool ( 'jmake.pl', 'clobber' )
1982
        if ( -f "Makefile.gbe" );
1983
 
295 dpurdie 1984
    if ( -f $build_file )
227 dpurdie 1985
    {
333 dpurdie 1986
        System ( $GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", 'clobber' );
227 dpurdie 1987
    }
1988
    else
1989
    {
1990
        Error ("Cannot clobber. No buildfile found");
1991
    }
1992
 
1993
    Message ("=== Remove complete ===");
1994
    $opr_done = 1;
1995
}
1996
 
1997
#-------------------------------------------------------------------------------
1998
# Function        : do_exit
1999
#
2000
# Description     : Common exit point so that time information can be displayed
2001
#
2002
# Inputs          : Optional exit code
2003
#
2004
# Returns         :
2005
#
2006
sub do_exit
2007
{
2008
    my ($ecode) = @_;
2009
 
2010
    $RESULT = $ecode if ( $ecode );
2011
 
2012
    #..
2013
    #   Determine the runtime
363 dpurdie 2014
    #       $^T is the time that the program started
227 dpurdie 2015
    #
2016
    if ( $opt_time )
2017
    {
2018
        my ($TIMEU, $TIMES) = times;
363 dpurdie 2019
        my $TIMER = time - $^T;
2020
        my $m = int($TIMER / 60);
2021
        my $s = $TIMER - ($m * 60);
227 dpurdie 2022
 
2023
        Message ( "Times: Real: $m:$s, User: $TIMEU, System: $TIMES");
2024
    }
2025
    #.
2026
    #   Make sure that any important exit code is passed to the user
2027
    #
2028
    Verbose ("ExitCode: $RESULT");
2029
    exit $RESULT;
2030
}
2031
 
2032
########################################################################
2033
#
2034
#   Main body of the script
2035
#
2036
#   Process help and manual options
2037
#       Done after all the setup to ensure that the PATH is correct
2038
#       Done before bombout to give user a chance
2039
#
2040
help() if $opt_help;
2041
ErrorDoExit();  # Exit if any error in setup
2042
ErrorConfig( 'on_exit'    => \&do_exit );
2043
 
2044
#
231 dpurdie 2045
#   Reset operational flags.
2046
#   May have been used by setup
2047
#
2048
$opr_done = 0;
2049
$RESULT = 0;
2050
 
2051
#
227 dpurdie 2052
#   Process user commands
2053
#
263 dpurdie 2054
my $cmd = shift @ARGV || help(1);
227 dpurdie 2055
 
2056
print_version(@ARGV)                    if ( $cmd =~ m/^ver/ );
2057
 
2058
clobber                                 if ( $cmd =~ m/^clobber$/ );
2059
build    (@ARGV)                        if ( $cmd =~ m/^build$/ );
2060
 
2061
bmake_it ('NOTALL', @ARGV)              if ( $cmd =~ m/^[x]*make$/ );
2062
bmake_it (@ARGV)                        if ( $cmd =~ m/^go$/ );
2063
bmake_it (dev_expand('debug', @ARGV) )  if ( $cmd =~ m/^debug$/ );
2064
bmake_it (dev_expand('prod', @ARGV) )   if ( $cmd =~ m/^prod$/ );
2065
bmake_it ("clean", @ARGV)               if ( $cmd =~ m/^clean$/ );
2066
bmake_it ("rebuild", @ARGV)             if ( $cmd =~ m/^rebuild$/ );
2067
bmake_it ('BUILD', @ARGV)               if ( $cmd =~ m/^all$/ );
2068
bmake_it ($cmd, @ARGV )                 if ( $cmd =~ m/^run_unit_tests/ );
2069
 
2070
install_pkg(@ARGV)                      if ( $cmd =~ m/^install$/ );
2071
create_dpkg(@ARGV)                      if ( $cmd =~ m/^create_dpkg$/ );
2072
 
2073
ebin  (@ARGV)                           if ( $cmd =~ m/^ebin/ );
2074
etool (@ARGV)                           if ( $cmd =~ m/^etool/ );
2075
eprog (@ARGV)                           if ( $cmd =~ m/^eprog$/ );
2076
run_ant (@ARGV)                         if ( $cmd =~ m/^ant$/ );
2077
run_abt (@ARGV)                         if ( $cmd =~ m/^abt$/ );
2078
 
299 dpurdie 2079
etool ('cache_dpkg', @ARGV)                         if ( $cmd =~ m/^dpkg/ );
2080
etool ('gen_msprojects', @ARGV)                     if ( $cmd =~ m/^gen_msproject/ );
361 dpurdie 2081
etool ("jats_${GBE_VCS}release.pl", @ARGV)                  if ( $cmd =~ m/^release/ );
2082
etool ("jats_${GBE_VCS}release.pl", '-extractfiles' ,@ARGV) if ( $cmd =~ m/^extractf/ );
2083
etool ("jats_${GBE_VCS}release.pl", '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^extract/ );
2084
etool ("jats_${GBE_VCS}label", @ARGV)                       if ( $cmd =~ m/^label$/ );
299 dpurdie 2085
etool ('jats_sandbox', @ARGV)                       if ( $cmd =~ m/^sandbox$/ );
313 dpurdie 2086
etool ('jats_help', @ARGV)                          if ( $cmd =~ m/^help$/ );
325 dpurdie 2087
etool ('jats_help', '-man', @ARGV)                  if ( $cmd =~ m/^man$/ );
315 dpurdie 2088
etool ('jats_vars.pl', @ARGV)                       if ( $cmd =~ m/^var/ );
227 dpurdie 2089
 
2090
etool ($cmd, @ARGV)                     unless ($opr_done); # Pass to etool if not known
2091
 
2092
do_exit();
2093
#.
2094
 
2095
#-------------------------------------------------------------------------------
2096
#   Documentation
2097
#
2098
 
2099
=pod
2100
 
361 dpurdie 2101
=for htmltoc    CORE::AA::Jats
2102
 
227 dpurdie 2103
=head1 NAME
2104
 
2105
jats - JATS utility interface tool
2106
 
2107
=head1 SYNOPSIS
2108
 
277 dpurdie 2109
 Usage: jats [opts] command [cmd-options]
227 dpurdie 2110
 
2111
 Where opts:
261 dpurdie 2112
    -h, -h -h, -man=[n] - Help messages with increasing verbosity
227 dpurdie 2113
    -cd dir             - Change to specified directory
2114
    -b file             - Use alternate build file
261 dpurdie 2115
    -verbose[=n]        - Verbose operation
2116
    -debug[=n]          - Enable debug mode of JATS scripts
227 dpurdie 2117
    -here               - Disable JATS auto locate of build.pl
2118
    -locate             - Locate build.pl file and change to directory
245 dpurdie 2119
    -locatepkg=pkg      - Locate build.pl. Resolve multiple files via pkg
227 dpurdie 2120
    -locatefile=file    - Locate specified file and change to directory
321 dpurdie 2121
    -locatedir=name     - Locate specified directory by scanning to the root
227 dpurdie 2122
    -platform=[name]    - Set GBE_PLATFORM to name   (=+ to append)
2123
    -buildfilter=[xxx]  - Set GBE_BUILDFILTER to xxx (=+ to append)
2124
    -abt=[xxx]          - Set GBE_ABT to xxx (=+ to append)
349 dpurdie 2125
    -java=version       - Alters java version used (1.4, 1.5, 1.6)
227 dpurdie 2126
    -time               - Time build and compile times
2127
    -version=xxx        - Use specified version of JATS
277 dpurdie 2128
    -[no]exportvars     - Export sanitised JATS EnvVars (default)
227 dpurdie 2129
 
331 dpurdie 2130
 Common commands include:
227 dpurdie 2131
    build               - Rebuild the sandbox and makefiles
2132
    make                - Make one or more components
2133
    ant                 - Invoke an ant build
2134
    abt [-java=xxx]     - Invoke the auto build tool
2135
    install             - Install package into local_dpkg_archive
2136
    help                - Display help message
325 dpurdie 2137
    man                 - Display extended help message
227 dpurdie 2138
    vars                - Display JATS related environment variables
2139
 
2140
    create_dpkg         - Install a package into main dpkg_archive
2141
    label               - Labelling functions
2142
    release             - Build a release from a clearcase label
2143
    extract             - Extract a release from a clearcase label
2144
    dpkg_cache          - Maintain a dpkg cache
2145
    gen_msproject       - Generate MSVC project files
361 dpurdie 2146
    sandbox             - Run Sandbox utility
299 dpurdie 2147
 
227 dpurdie 2148
    etool name          - Run internal tool
2149
    eprog name          - Run external tool
2150
    ebin name           - Run JATS binary tool
2151
 
2152
 Shortcut commands. Composites of basic commands
331 dpurdie 2153
    all [opt]           - Same as a "build -noforce" and "make all"
227 dpurdie 2154
    go  [opt]           - Same as a "make all"
2155
    debug [tgt]         - Same as "make debug package_debug"
2156
    prod  [tgt]         - Same as "make prod package_prod"
2157
    clean               - Same as "make clean"
2158
    clobber             - Same as "build clobber"
2159
    *                   - Unknown commands are treated as arguments to etool
2160
 
2161
 Where [cmd-options] are command specific.
325 dpurdie 2162
    Try "jats help command" for details
227 dpurdie 2163
 
2164
=head1 OPTIONS
2165
 
2166
=over 8
2167
 
2168
=item B<-help>
2169
 
2170
Print a brief help message and exits.
2171
 
2172
=item B<-help -help>
2173
 
2174
Print a detailed help message with an explanation for each option.
2175
 
261 dpurdie 2176
=item B<-man[=n]>
227 dpurdie 2177
 
2178
Prints the manual page and exits.
2179
 
261 dpurdie 2180
If a numeric manual level is provide then it will be used to control the
361 dpurdie 2181
verbosity of help provided. This should be in the range of 1 to 3.
261 dpurdie 2182
 
227 dpurdie 2183
=item B<-b file> B<-buildfile file>
2184
 
2185
This option modifies the operation of the "build" command. The command will
2186
use the specified file instead of the normal build.pl file.
2187
 
2188
=item B<-cd dir> B<-changedir dir>
2189
 
2190
This option will change to specified directory before the command is invoked.
2191
 
261 dpurdie 2192
=item B<--verbose[=n]>
227 dpurdie 2193
 
2194
This option will increase the level of verbosity of the JATS command and command
261 dpurdie 2195
invoked by the JATS shell.
227 dpurdie 2196
 
261 dpurdie 2197
If an argument is provided, then it will be used to set the level, otherwise the
2198
existing level will be incremented. This option may be specified multiple times.
227 dpurdie 2199
 
261 dpurdie 2200
=item B<-debug[=n]>
2201
 
227 dpurdie 2202
This option will increase the level of debug output of the JATS command and command
261 dpurdie 2203
invoked by the JATS shell.
227 dpurdie 2204
 
261 dpurdie 2205
If an argument is provided, then it will be used to set the level, otherwise the
2206
existing level will be incremented. This option may be specified multiple times.
2207
 
227 dpurdie 2208
=item B<-here>
2209
 
2210
This option will disable the "autolocate" mechanism of the JATS shell script.
2211
 
2212
By default JATS will "hunt" for a suitable "build.pl" or "makefile.pl" before
2213
executing a build or a make command. JATS will look in the following directories
2214
for a  suitable file. Under some conditions this mechanism is not useful.
2215
 
2216
By default JATS will hunt in the following directories: "." "jats" "build/
2217
jats" ".." "../.." and "../../..".
2218
 
2219
=item B<-locate>
2220
 
2221
This option will cause the JATS wrapper script to locate the build.pl file and
2222
then change to that directory. This allows users to locate the build root of
2223
a project and then issue other JATS commands.
2224
 
2225
If the B<-c> option is also specified then searching will start in the specified
2226
directory.
2227
 
2228
If an alternate build file is specified with the B<-b> option then that filename
2229
will be used in the location process.
2230
 
2231
This option implies a B<-here>. No further scanning will be done.
2232
 
2233
Exactly one build file must be located. If more than buildfile is located then
2234
the locations of the build files is displayed and JATS will terminate.
2235
 
245 dpurdie 2236
 
2237
=item B<-locatepkg=packagename>
2238
 
2239
This option is similar to the B<-locate> option, but it allows the required
2240
build files to be located by ensuring that the required buildfile builds the
2241
specified package.
2242
 
2243
There are two forms in which the B<packagename> can be specified. It can be
361 dpurdie 2244
specified as a full package name and version, or as a package name and the
245 dpurdie 2245
project suffix. ie: jats-api.1.0.0000.cr or jats-api.cr
2246
 
227 dpurdie 2247
=item B<-locatefile=file>
2248
 
2249
This option is similar to the B<-locate> option, but it allows the name of the
2250
file to be located to be specified.
2251
 
319 dpurdie 2252
=item B<-locatedir=name>
2253
 
2254
Locate the named directory by scanning from the current directory to the root
321 dpurdie 2255
of the filesystem. This operation is performed before any other location
319 dpurdie 2256
operations and before the B<-cd=path> operation.
2257
 
2258
It may be used to position the jats operation at the root of a view - provided
2259
the view root is known.
2260
 
227 dpurdie 2261
=item B<-platform=[name]>
2262
 
2263
This option will set the JATS specific environment variable GBE_PLATFORM to
2264
the specified name. The existing value of GBE_PLATFORM may be extended by
2265
using "=+".
2266
 
2267
In practice the GBE_PLATFORM variable is of little use. The same effect can be
2268
achieved directly with make targets or with GBE_BUILDFILTER.
2269
 
2270
=item B<-buildfilter=[xxx]>
2271
 
2272
This option will set the JATS specific environment variable GBE_BUILDFILTER to
2273
the specified name. The existing value of GBE_BUILDFILTER may be extended by
2274
using "=+".
2275
 
2276
This option may be used to limit the initial build, and subsequent "make" to a
2277
limited set of platforms.
2278
 
2279
=item B<-abt=[xxx]>
2280
 
2281
This option will set the JATS specific environment variable GBE_ABT to
2282
the specified name The existing value of GBE_ABT may be extended by
2283
using "=+"..
2284
 
2285
This option is used to pass arguments directly to some tools within the
2286
(ABT) Auto Build Tool framework, or to indicate that the build is being
2287
performed within the ABT framework.
2288
 
2289
=item B<-java=version>
2290
 
2291
This option will override the default java version used by the ant builds and
2292
passed to the underlying programs. The path to the Java SDK is determined from
2293
the environment using the version string replacing the '.' with '_'
2294
 
2295
eg: -java=1.5, will examine the environment for JAVA_HOME_1_5 and will set
2296
JAVA_HOME to that value. It will not setup the users PATH or classpath.
2297
 
2298
=item B<-time>
2299
 
2300
When this option is enabled the JATS script will report the runtime of the
2301
underlying, invoked, command.
2302
 
2303
=item B<-version=xxx>
2304
 
2305
When this option is invoked JATS will attempt to use the specified version to
2306
perform all processing. JATS will search the GBE_DPKG_LOCAL, GBE_DPKG_CACHE,
2307
GBE_DPKG, GBE_DPKG_STORE in order to locate the specified version of the package.
2308
 
2309
The entire command line will be passed to the JATS wrapper script within that
2310
version. This bypasses the jats.bat or jats.sh startup scripts.
2311
 
277 dpurdie 2312
JATS will attempt to transfer the target version to the local cache in an
2313
attempt to improve performance.
227 dpurdie 2314
 
277 dpurdie 2315
=item B<-[no]exportvars>
227 dpurdie 2316
 
361 dpurdie 2317
The default operation is to export sanitized and calculated values to the
277 dpurdie 2318
programs running under JATS. The use of NoExportVars will prevent JATS from
2319
exporting modified EnvVars into the environment. This may be required by
2320
processes, such as the build daemons that need to pick up the current version of
2321
JATS on the fly and not have it fixed when the daemon is started.
227 dpurdie 2322
 
2323
=back
2324
 
2325
=head1 ARGUMENTS
2326
 
2327
=head2 Basic Commands
2328
 
2329
The following commands are invoked directly by the JATS script to wrap the build
2330
tools in a controlled manner.
2331
 
2332
=over 8
2333
 
361 dpurdie 2334
=item L<build|TOOLS::buildlib>
227 dpurdie 2335
 
2336
Build or rebuild the sandbox and makefiles.
2337
 
2338
This command must be used before the component can be "made" and when the
2339
contents of the "buildpl" file change. It is a common mistake to use the "build"
2340
command to much.
2341
 
2342
The script will hunt for a suitable build.pl file before running the build and
2343
make subcommands.
2344
 
361 dpurdie 2345
The build process has a large number of options.
2346
Use L<"JATS build help"|TOOLS::buildlib/"item_help"> to display the complete list.
227 dpurdie 2347
 
361 dpurdie 2348
=item L<make|TOOLS::jmake>
227 dpurdie 2349
 
2350
Make one or more components
2351
 
2352
This command will invoke a suitable "make" program on the makefile found in
2353
the current directory. This makefile should have been generated by JATS.
2354
 
361 dpurdie 2355
The make process has a large number of options. Use
2356
L<"JATS make help"|TOOLS::jmake/"item_help">" to display the complete list.
227 dpurdie 2357
 
2358
=item B<ant>
2359
 
2360
This command will use ANT to build a component. JATS will determine the
2361
build.xml file to use with the following algorithm.
2362
 
2363
    If the files called <Project>depends.xml and <Project>.xml exist then JATS
2364
    will create an 'auto.xml' from the depends file, if one does not already
2365
    exist or is older than the depends.xml file and then use the <Project>.xml
2366
    file as the ant build file.
2367
 
2368
    Otherwise ant is invoked and it will expect a build.xml file.
2369
 
2370
If multiple <Project>depends.xml and <Project>.xml file pairs are found the
2371
command will fail. This can be resolved through the use of the -buildfile=name
2372
option.
2373
 
2374
Ant is invoked with the version of Java specified with the -Java=x.x option.
2375
 
2376
=item B<abt>
2377
 
2378
This command is used to invoke the Auto Build Tool. It will invoke ANT on the
2379
build.xml file in the current directory in such  manner as to not affect the
239 dpurdie 2380
environment of the programs running under ANT.
227 dpurdie 2381
 
361 dpurdie 2382
The remainder of the command line is passed to the ABT, with the exception of
239 dpurdie 2383
the options:
2384
 
2385
=over 8
2386
 
361 dpurdie 2387
=item *
2388
 
2389
-java=x.x. This is used to control the version of Java used by the
349 dpurdie 2390
ABT. The default is 1.6.
227 dpurdie 2391
 
361 dpurdie 2392
=item *
2393
 
2394
-buildfile=name. This is used to provide a different build file to ant.
239 dpurdie 2395
The default build file is 'build.xml'.
2396
 
2397
=back
2398
 
361 dpurdie 2399
=item L<help|TOOLS::jats_help>
227 dpurdie 2400
 
2401
Display the basic help message.
2402
 
361 dpurdie 2403
=item L<vars [-v]|TOOLS::jats_vars>
227 dpurdie 2404
 
2405
This command will display all the JATS related environment variables in a
2406
readable form.
2407
 
2408
Additional information will be displayed if an argument of "-v" is provided.
2409
 
2410
=back
2411
 
2412
=head2 Extended Commands
2413
 
2414
The following commands support the build environment. They are supplemental to
2415
the build environment. They are implemented as extensions to the basic JATS
2416
command scripts.
2417
 
2418
=over 8
2419
 
361 dpurdie 2420
=item L<create_dpkg|TOOLS::create_dpkg>
227 dpurdie 2421
 
2422
This command will install a generated package into main dpkg_archive. This
2423
command should not be used directly by a user as it does not ensure that package
2424
has been created in a repeatable manner - use "jats release".
2425
 
361 dpurdie 2426
=item label
227 dpurdie 2427
 
2428
This command provides a number of useful labelling mechanisms to assist in the
2429
labeling of source code.
2430
 
361 dpurdie 2431
The command will determine the default Version Control System and invoke the VCS
2432
specific utility. This will be one of:
227 dpurdie 2433
 
361 dpurdie 2434
=over 4
227 dpurdie 2435
 
361 dpurdie 2436
=item   *
2437
 
2438
ClearCase: L<cclabel|TOOLS::jats_cclabel>
2439
 
2440
=item   *
2441
 
2442
Subversion: L<svnlabel|TOOLS::jats_svnlabel>
2443
 
2444
=back
2445
 
2446
=item release
2447
 
2448
This command allows a package to be built and released, given a label.
2449
This is the desired release mechanism for manually releasing a package.
2450
 
227 dpurdie 2451
The command has two main uses:
2452
 
361 dpurdie 2453
=over 4
227 dpurdie 2454
 
2455
=item 1
2456
 
2457
Build a package for release. The process will ensure that the build is
2458
controlled and repeatable.
2459
 
2460
=item 2
2461
 
2462
Rebuild a package for test or debugging purposes.
2463
 
2464
=back
2465
 
361 dpurdie 2466
The command will determine the default Version Control System and invoke the VCS
2467
specific utility. This will be one of:
227 dpurdie 2468
 
361 dpurdie 2469
=over 4
2470
 
2471
=item   *
2472
 
2473
ClearCase: L<ccrelease|TOOLS::jats_ccrelease>
2474
 
2475
=item   *
2476
 
2477
Subversion: L<svnrelease|TOOLS::jats_svnrelease>
2478
 
2479
=back
2480
 
2481
=item L<extract|/"release">
2482
 
227 dpurdie 2483
This is the same as "release -extract"
2484
 
2485
 
361 dpurdie 2486
=item L<dpkg_cache|TOOLS::cache_dpkg>
227 dpurdie 2487
 
2488
This utility provides a number of commands to maintain the local cache of
245 dpurdie 2489
dpkg_archive.
227 dpurdie 2490
 
361 dpurdie 2491
=item L<gen_msproject|TOOLS::gen_msprojects>
227 dpurdie 2492
 
2493
This utility will generate a set of Microsoft Studio (Version 6) project and
361 dpurdie 2494
workspace files to encapsulate the JATS build. The resultant project allows
2495
Visual Studio to be used as an editor, source browser, debugger and build tool.
2496
JATS is still used to perform the build.
227 dpurdie 2497
 
361 dpurdie 2498
=item B<install>
2499
 
2500
This command will install a generated "package" into the local_dpkg_archive
2501
directory. This allows a group of packages to be tested before being published
2502
into the global dpkg_archive.
2503
 
2504
=for htmlclass Note
2505
 
2506
Note. This command is no longer needed. The "build" process will place a
2507
shortcut in the local_dpkg_archive to a components "pkg" directory. Other
2508
components will utilize this shortcut directly and pickup the package without
2509
the user needing to "install" the package - a step that can be forgotten.
2510
 
227 dpurdie 2511
=item B<etool name>
2512
 
2513
This command allows any JATS extension program to be run. The programs will by
2514
found in the JATS TOOLS directory.
2515
 
2516
=item B<eprog name>
2517
 
2518
This command allows any JATS extension program to be run.
2519
If the program end in .pl, then it will be run within a perl interpreter.
2520
If the program end in .jar, then it will be run under a java interpreter.
2521
 
2522
=item B<ebin name>
2523
 
2524
This command allows any JATS support program to be run. The programs will by
2525
found in the JATS BIN directory for the current platform. This command allows
2526
a user script to access many of the machine independent utilities in a simple
2527
manner.
2528
 
2529
Example: "JATS ebin ls" - will provide a "real" ls on all platforms.
2530
 
2531
Example: "JATS ebin sh" - will start up the shell used by make.
2532
 
2533
=back
2534
 
2535
=head2 Command Shortcuts
2536
 
2537
The following commands are user shortcuts to the basic commands. The are basic
2538
commands run in sequence.
2539
 
2540
=over 8
2541
 
2542
=item B<all [make_opts]>
2543
 
2544
This command is the same as running the command "build" and "make all".
2545
It will build a component with a single command.
2546
 
2547
If "make_opts" is not present then "make all" is used.
2548
 
2549
If "make_opts" is present then they are passed to the "make" command. In this
2550
manner is it possible to build a WIN32 component of package with a single
2551
command.
2552
 
2553
=item B<go [make_opts]>
2554
 
2555
This command is similar to the "all" shortcut, but it does not "build" the
2556
sandbox. It may be used where the sandbox has already been prepared.
2557
 
2558
=item B<debug [target]>
2559
 
2560
This command is the same as running "make debug package_debug". It will make and
2561
package all the debug components of a sandbox.
2562
 
2563
If any additional arguments are provided to the B<dev> command then they will be
2564
treated as make targets and the commands will be expanded to make and package
2565
the specified debug versions of the names platforms. Make options cannot be
2566
passed in this manner.
2567
 
2568
Example: "JATS dev GAK" will create and package the debug parts for the
2569
GAK_MOS68K and GAK_MOSCF.
2570
 
2571
=item B<prod [target]>
2572
 
2573
This command is the same as running "make prod package_prod". It will make and
2574
package all the debug components of a sandbox.
2575
 
2576
If any additional arguments are provided to the B<prod> command then they will be
2577
treated as make targets and the commands will be expanded to make and package
2578
the specified debug versions of the names platforms. Make options cannot be
2579
passed in this manner.
2580
 
2581
Example: "JATS prod GAK" will create and package the production parts for the
2582
GAK_MOS68K and GAK_MOSCF.
2583
 
2584
=item B<clean>
2585
 
2586
This is the same as "make clean".
2587
 
2588
=item B<clobber>
2589
 
2590
This is the same as "build clobber"
2591
 
2592
=item B<else>
2593
 
2594
Commands that are not known to the JATS wrapper script are passed to etool.
2595
 
2596
ie: "JATS xxxx" is is the same as "JATS etool xxxx".
2597
 
2598
=back
2599
 
2600
=head1 DESCRIPTION
2601
 
2602
JATS is a wrapper script. It provides:
2603
 
361 dpurdie 2604
=over 4
227 dpurdie 2605
 
2606
=item *
2607
 
361 dpurdie 2608
A controlled and sanitized environment to all the build tools.
227 dpurdie 2609
 
2610
=item *
2611
 
2612
The same command interface on all supported machines: Windows, Solaris and
2613
Linux.
2614
 
2615
=item *
2616
 
2617
Provides a framework for extending the build environment toolset.
2618
 
2619
=back
2620
 
315 dpurdie 2621
=head1 RELATED DOCUMENTATION
227 dpurdie 2622
 
361 dpurdie 2623
=over 4
227 dpurdie 2624
 
361 dpurdie 2625
=item   * L<Installation Notes|POD::InstallationNotes>
227 dpurdie 2626
 
361 dpurdie 2627
=item   * L<OverView|POD::OverView>
227 dpurdie 2628
 
361 dpurdie 2629
=item   * L<EnvVars|POD::EnvVars>
255 dpurdie 2630
 
361 dpurdie 2631
=item   * L<PkgArchives|POD::PkgArchives>
227 dpurdie 2632
 
2633
=back
2634
 
361 dpurdie 2635
Use L<jats help|TOOLS::jats_help> to see the available internal documentation.
227 dpurdie 2636
 
315 dpurdie 2637
=head1 EXAMPLES
227 dpurdie 2638
 
315 dpurdie 2639
=over 8
227 dpurdie 2640
 
361 dpurdie 2641
=item   L<JATS help|TOOLS::jats_help>
227 dpurdie 2642
 
315 dpurdie 2643
This will display the available internal documentation.
227 dpurdie 2644
 
361 dpurdie 2645
=item   L<JATS build|TOOLS::buildlib>
227 dpurdie 2646
 
315 dpurdie 2647
This will prime the current package being built ready for "make". The command
2648
will locate the build.pl file and process it. This will locate all the external
2649
packages and generate the required makefiles.
227 dpurdie 2650
 
361 dpurdie 2651
=item   L<JATS make|TOOLS::jmake>
227 dpurdie 2652
 
2653
This will run the GNU make program over the makefiles generated by the "build"
2654
command. This may be executed in a subdirectory in order to limit the targets
2655
that are "made".
2656
 
361 dpurdie 2657
=for htmlclass Note
2658
 
227 dpurdie 2659
B<NOTE:> Do not run "make" without using the JATS wrapper. It will not perform
2660
as expected as the environment will not have been set up correctly.
2661
 
2662
=back
2663
 
2664
=cut
2665