Subversion Repositories DevTools

Rev

Rev 3527 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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