Subversion Repositories DevTools

Rev

Rev 3965 | 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
 
4018 dpurdie 1833
    if ( defined $cmd )
315 dpurdie 1834
    {
4018 dpurdie 1835
        unless ( $GBE_UNIX )
1836
        {
1837
            #
1838
            #   Cygwin kludge
1839
            #       Replace /cygdrive/DriveLetter/ - with DriveLetter:/
1840
            #       Replace /DriveLetter/          - With DriveLetter:/
1841
            #
1842
            $cmd =~ s~^/cygdrive/([A-Z])/(.*)~$1:/$2~i;
1843
            $cmd =~ s~^/([A-Z])/(.*)~$1:/$2~i;
1844
        }
315 dpurdie 1845
    }
1846
    return $cmd;
1847
}
1848
 
1849
 
1850
#-------------------------------------------------------------------------------
227 dpurdie 1851
# Function        : run_ant
1852
#
1853
# Description     : Invoke ant
396 dpurdie 1854
#                   If the current directory looks like an VIX build system, then
227 dpurdie 1855
#                   create and maintain an auto.xml file. Otherwise simply invoke ant
1856
#
1857
# Inputs          : $1+ program arguments
1858
#
1859
sub run_ant
1860
{
1861
    my $JAVA_HOME = $ENV{JAVA_HOME} || Error ("JAVA_HOME is not defined in the environment");
1862
    my $ANT_HOME  = $ENV{ANT_HOME}  || Error ("ANT_HOME is not defined in the environment" );
1863
 
1864
    #
396 dpurdie 1865
    #   Detect an VIX formatted build
227 dpurdie 1866
    #   This will have two files <projectname>.xml and <projectname>depends.xml
1867
    #   Create the 'auto.xml' file only if its not present
1868
    #
1869
    my @ant_arg;
1870
    my @flist;
1871
    my $basename = '';
235 dpurdie 1872
    my $scanner = '*depends.xml';
227 dpurdie 1873
 
1874
    #
1875
    #   Use specified build file to resolve multiple names
1876
    #   Strip any trailing depends.xml to make it user friendly
1877
    #
1878
    if ( $BUILD_FILE_SET )
1879
    {
1880
        $basename = $BUILD_FILE;
1881
        $basename =~ s~\.xml$~~;
1882
        $basename =~ s~depends$~~;
235 dpurdie 1883
        $scanner = "${basename}depends.xml";
227 dpurdie 1884
        Verbose ("Using buildfile: $basename");
1885
    }
1886
 
235 dpurdie 1887
    my @buildlist = glob($scanner);
227 dpurdie 1888
    foreach ( @buildlist )
1889
    {
1890
        if ( m/(.+)depends.xml/ )
1891
        {
1892
            my $pname = $1;
1893
            push @flist, $pname if ( -f "$pname.xml" );
1894
        }
1895
    }
1896
 
1897
    if ( $#flist >= 0 )
1898
    {
1899
        Error ("Multiple depends.xml files found:", @flist,
297 dpurdie 1900
               "Use 'jats -buildfile=name ant ...' to resolve") if ( $#flist > 0 );
227 dpurdie 1901
 
1902
        my $depend = "$flist[0]depends.xml";
1903
        @ant_arg = ('-f', "$flist[0].xml");
1904
 
1905
        Message ("Ant using projectfiles: $flist[0].xml");
1906
 
1907
        #
367 dpurdie 1908
        #   Create auto.xml if we have a depends.xml
227 dpurdie 1909
        #
367 dpurdie 1910
        if ( -f $depend )
227 dpurdie 1911
        {
367 dpurdie 1912
            #
1913
            #   Check for depends.xml newer than auto.xml.
1914
            #
1915
            my $auto_timestamp   = (stat('auto.xml'))[9] || 0;
1916
            my $depend_timestamp = (stat($depend))[9];
1917
            if ( $depend_timestamp > $auto_timestamp )
1918
            {
1919
                Message ("Creating: auto.xml");
1920
                copy( $depend, 'auto.xml' );
1921
                chmod 0777, 'auto.xml';
1922
            }
227 dpurdie 1923
        }
367 dpurdie 1924
        else
1925
        {
1926
            Warning ("Project file does not have a depends.xml file");
1927
        }
227 dpurdie 1928
    }
1929
    elsif ( $BUILD_FILE_SET  )
1930
    {
1931
        Error ("Specified build file pair not found:", $basename, $basename . "depends.xml");
1932
    }
1933
    #
1934
    #   The ant provided startup scripts don't return an exit code under
1935
    #   windows. Invoke ant directly
1936
    #
1937
    launch_ant ( $JAVA_HOME, $ANT_HOME, @ant_arg, @_ );
1938
    $opr_done = 1;
1939
}
1940
 
1941
#-------------------------------------------------------------------------------
1942
# Function        : run_abt
1943
#
1944
# Description     : Invoke auto build tool (older form)
1945
#                   Options for the ABT
1946
#                       --Java=x.x
1947
#                   Invoke ANT for the ABT using a specified version of Java
1948
#                   Do not play with the user environment.
297 dpurdie 1949
#                   Don't stick java path into environment
227 dpurdie 1950
#
1951
# Inputs          : $1+ program arguments
1952
#
1953
sub run_abt
1954
{
279 dpurdie 1955
    my $ABT_JAVA = 'JAVA_HOME_1_6';         # Default version for the ABT
227 dpurdie 1956
    my $JAVA_HOME = $ENV{$ABT_JAVA};
1957
    my $ANT_HOME  = $ENV{ANT_HOME};
1958
    my @abt_arg;
239 dpurdie 1959
    my $buildfile = 'build.xml';
227 dpurdie 1960
 
1961
    ErrorConfig( 'name'    => 'JATS ABT' );
1962
 
1963
    #
239 dpurdie 1964
    #   Use the user specified buildfile
1965
    #
1966
    $buildfile = $BUILD_FILE
1967
        if ( $BUILD_FILE_SET );
1968
 
1969
    #
227 dpurdie 1970
    #   Extract known options
1971
    #
1972
    foreach  ( @_ )
1973
    {
1974
        if ( m/-java=(.*)/ ) {
1975
            $JAVA_HOME = get_java_home($1);
239 dpurdie 1976
 
1977
        } elsif ( m/^-buildfile=(.+)/ ) {
1978
            $buildfile = $1;
1979
 
227 dpurdie 1980
        } else {
1981
            push @abt_arg, $_;
1982
        }
1983
    }
1984
 
1985
    Error ("$ABT_JAVA is not defined in the environment") unless $JAVA_HOME;
1986
    Error ("ANT_HOME is not defined in the environment" ) unless $ANT_HOME;
239 dpurdie 1987
    Error ("Ant buildfile not found: $buildfile" ) unless (-f $buildfile);
227 dpurdie 1988
 
1989
    #
239 dpurdie 1990
    #   Insert correct build file arguments
1991
    #
279 dpurdie 1992
    push @abt_arg, '-buildfile', $buildfile;
1993
 
1994
    #
1995
    #   Add current directory as java library directory, but only if
1996
    #   it contains JAR files.
1997
    #
1998
    push @abt_arg, '-lib', $CWD
1999
        if ( glob ('*.jar') );
239 dpurdie 2000
 
2001
    #
227 dpurdie 2002
    #   Use the ant-launcher to invoke ant directly
2003
    #
2004
    launch_ant ( $JAVA_HOME, $ANT_HOME, @abt_arg );
2005
    $opr_done = 1;
2006
}
2007
 
2008
#-------------------------------------------------------------------------------
2009
# Function        : launch_ant
2010
#
2011
# Description     : Start ANT - with sanity checking
2012
#
2013
# Inputs          : JAVA_HOME
2014
#                   ANT_HOME
2015
#                   @user_args
2016
#
2017
# Returns         : Result Code
2018
#
2019
sub launch_ant
2020
{
2021
    my ($JAVA_HOME, $ANT_HOME, @user_args ) = @_;
2022
 
2023
    Error ("Directory not found: $JAVA_HOME") unless ( -d "$JAVA_HOME" );
2024
    Error ("Program not found: $JAVA_HOME/bin/java") unless ( -e "$JAVA_HOME/bin/java" || -e "$JAVA_HOME/bin/java.exe" );
2025
    Error ("Jar not found: $ANT_HOME/lib/ant-launcher.jar") unless ( -e "$ANT_HOME/lib/ant-launcher.jar" );
2026
    Error ("Directory not found: $ANT_HOME") unless ( -d "$ANT_HOME" );
2027
    Error ("Directory not found: $ANT_HOME/lib") unless ( -d "$ANT_HOME/lib" );
2028
 
2029
    #
2030
    #   Use the ant-launcher to invoke ant directly
2031
    #
2032
    $RESULT = System ( "$JAVA_HOME/bin/java",
2033
                       "-classpath","$ANT_HOME/lib/ant-launcher.jar",
2034
                       "-Dant.home=$ANT_HOME",
2035
                       "org.apache.tools.ant.launch.Launcher",
2036
                       "-lib","$ANT_HOME/lib",
2037
                       @user_args
2038
                       );
2039
 
2040
   return $RESULT;
2041
}
2042
 
2043
 
2044
#-------------------------------------------------------------------------------
2045
#
2046
#   Cleanup the sandbox
2426 dpurdie 2047
#   Perform a "make clean" then a "build clobber"
227 dpurdie 2048
#
2049
sub clobber
2050
{
2051
    Message ("=== Removing ======");
2052
    find_jats_dir( $BUILD_FILE );
295 dpurdie 2053
    my $build_file = getBuildFile();
2054
 
227 dpurdie 2055
 
2056
    #
2426 dpurdie 2057
    #   Run a "make clean" to clean out a lot of stuff
2058
    #   Run a "build clobber" to get rid of interface and local directories
227 dpurdie 2059
    #
2426 dpurdie 2060
    etool ( 'jmake.pl', 'clean' )
227 dpurdie 2061
        if ( -f "Makefile.gbe" );
2062
 
295 dpurdie 2063
    if ( -f $build_file )
227 dpurdie 2064
    {
333 dpurdie 2065
        System ( $GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", 'clobber' );
227 dpurdie 2066
    }
2067
    else
2068
    {
2069
        Error ("Cannot clobber. No buildfile found");
2070
    }
2071
 
2072
    Message ("=== Remove complete ===");
2073
    $opr_done = 1;
2074
}
2075
 
2076
#-------------------------------------------------------------------------------
2077
# Function        : do_exit
2078
#
2079
# Description     : Common exit point so that time information can be displayed
2080
#
2081
# Inputs          : Optional exit code
2082
#
2083
# Returns         :
2084
#
2085
sub do_exit
2086
{
2087
    my ($ecode) = @_;
2088
 
2089
    $RESULT = $ecode if ( $ecode );
2090
 
2091
    #..
2092
    #   Determine the runtime
363 dpurdie 2093
    #       $^T is the time that the program started
227 dpurdie 2094
    #
2095
    if ( $opt_time )
2096
    {
2097
        my ($TIMEU, $TIMES) = times;
363 dpurdie 2098
        my $TIMER = time - $^T;
2099
        my $m = int($TIMER / 60);
2100
        my $s = $TIMER - ($m * 60);
227 dpurdie 2101
 
2102
        Message ( "Times: Real: $m:$s, User: $TIMEU, System: $TIMES");
2103
    }
2104
    #.
2105
    #   Make sure that any important exit code is passed to the user
2106
    #
2107
    Verbose ("ExitCode: $RESULT");
2108
    exit $RESULT;
2109
}
2110
 
2111
########################################################################
2112
#
2113
#   Main body of the script
2114
#
2115
#   Process help and manual options
2116
#       Done after all the setup to ensure that the PATH is correct
2117
#       Done before bombout to give user a chance
2118
#
379 dpurdie 2119
 
2120
#
2121
#   Redirect all output to a log file
2122
#   Only perform redirection AFTER we have setup the users environment
2123
#       May change this.
2124
#
2125
if ( $opt_logfile )
2126
{
2127
    open STDOUT, '>', $opt_logfile  or die "Can't redirect STDOUT: $!";
2128
    open STDERR, ">&STDOUT"         or die "Can't dup STDOUT: $!";
2129
}
2130
 
227 dpurdie 2131
help() if $opt_help;
2132
ErrorDoExit();  # Exit if any error in setup
2133
ErrorConfig( 'on_exit'    => \&do_exit );
2134
 
2135
#
231 dpurdie 2136
#   Reset operational flags.
2137
#   May have been used by setup
2138
#
2139
$opr_done = 0;
2140
$RESULT = 0;
2141
 
2142
#
227 dpurdie 2143
#   Process user commands
2144
#
263 dpurdie 2145
my $cmd = shift @ARGV || help(1);
227 dpurdie 2146
 
2147
print_version(@ARGV)                    if ( $cmd =~ m/^ver/ );
2148
 
2149
clobber                                 if ( $cmd =~ m/^clobber$/ );
2150
build    (@ARGV)                        if ( $cmd =~ m/^build$/ );
2151
 
2152
bmake_it ('NOTALL', @ARGV)              if ( $cmd =~ m/^[x]*make$/ );
2153
bmake_it (@ARGV)                        if ( $cmd =~ m/^go$/ );
2154
bmake_it (dev_expand('debug', @ARGV) )  if ( $cmd =~ m/^debug$/ );
2155
bmake_it (dev_expand('prod', @ARGV) )   if ( $cmd =~ m/^prod$/ );
2156
bmake_it ("clean", @ARGV)               if ( $cmd =~ m/^clean$/ );
2157
bmake_it ("rebuild", @ARGV)             if ( $cmd =~ m/^rebuild$/ );
2158
bmake_it ('BUILD', @ARGV)               if ( $cmd =~ m/^all$/ );
2159
bmake_it ($cmd, @ARGV )                 if ( $cmd =~ m/^run_unit_tests/ );
2160
 
2161
install_pkg(@ARGV)                      if ( $cmd =~ m/^install$/ );
2162
create_dpkg(@ARGV)                      if ( $cmd =~ m/^create_dpkg$/ );
2163
 
2164
ebin  (@ARGV)                           if ( $cmd =~ m/^ebin/ );
2165
etool (@ARGV)                           if ( $cmd =~ m/^etool/ );
2166
eprog (@ARGV)                           if ( $cmd =~ m/^eprog$/ );
2167
run_ant (@ARGV)                         if ( $cmd =~ m/^ant$/ );
2168
run_abt (@ARGV)                         if ( $cmd =~ m/^abt$/ );
2169
 
299 dpurdie 2170
etool ('cache_dpkg', @ARGV)                         if ( $cmd =~ m/^dpkg/ );
2171
etool ('gen_msprojects', @ARGV)                     if ( $cmd =~ m/^gen_msproject/ );
361 dpurdie 2172
etool ("jats_${GBE_VCS}release.pl", @ARGV)                  if ( $cmd =~ m/^release/ );
2173
etool ("jats_${GBE_VCS}release.pl", '-extractfiles' ,@ARGV) if ( $cmd =~ m/^extractf/ );
2174
etool ("jats_${GBE_VCS}release.pl", '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^extract/ );
383 dpurdie 2175
 
2176
etool ("jats_svnrelease.pl", '-extractfiles' ,@ARGV) if ( $cmd =~ m/^svnextractf/ );
2177
etool ("jats_svnrelease.pl", '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^svnextract/ );
2178
 
361 dpurdie 2179
etool ("jats_${GBE_VCS}label", @ARGV)                       if ( $cmd =~ m/^label$/ );
299 dpurdie 2180
etool ('jats_sandbox', @ARGV)                       if ( $cmd =~ m/^sandbox$/ );
313 dpurdie 2181
etool ('jats_help', @ARGV)                          if ( $cmd =~ m/^help$/ );
325 dpurdie 2182
etool ('jats_help', '-man', @ARGV)                  if ( $cmd =~ m/^man$/ );
315 dpurdie 2183
etool ('jats_vars.pl', @ARGV)                       if ( $cmd =~ m/^var/ );
227 dpurdie 2184
 
2185
etool ($cmd, @ARGV)                     unless ($opr_done); # Pass to etool if not known
2186
 
2187
do_exit();
2188
#.
2189
 
2190
#-------------------------------------------------------------------------------
2191
#   Documentation
2192
#
2193
 
2194
=pod
2195
 
361 dpurdie 2196
=for htmltoc    CORE::AA::Jats
2197
 
227 dpurdie 2198
=head1 NAME
2199
 
2200
jats - JATS utility interface tool
2201
 
2202
=head1 SYNOPSIS
2203
 
277 dpurdie 2204
 Usage: jats [opts] command [cmd-options]
227 dpurdie 2205
 
2206
 Where opts:
261 dpurdie 2207
    -h, -h -h, -man=[n] - Help messages with increasing verbosity
227 dpurdie 2208
    -cd dir             - Change to specified directory
2209
    -b file             - Use alternate build file
261 dpurdie 2210
    -verbose[=n]        - Verbose operation
2211
    -debug[=n]          - Enable debug mode of JATS scripts
227 dpurdie 2212
    -here               - Disable JATS auto locate of build.pl
2213
    -locate             - Locate build.pl file and change to directory
245 dpurdie 2214
    -locatepkg=pkg      - Locate build.pl. Resolve multiple files via pkg
2651 dpurdie 2215
    -locatefile=file    - Locate specified build file and change to directory
321 dpurdie 2216
    -locatedir=name     - Locate specified directory by scanning to the root
227 dpurdie 2217
    -platform=[name]    - Set GBE_PLATFORM to name   (=+ to append)
2218
    -buildfilter=[xxx]  - Set GBE_BUILDFILTER to xxx (=+ to append)
2219
    -abt=[xxx]          - Set GBE_ABT to xxx (=+ to append)
349 dpurdie 2220
    -java=version       - Alters java version used (1.4, 1.5, 1.6)
227 dpurdie 2221
    -time               - Time build and compile times
2222
    -version=xxx        - Use specified version of JATS
277 dpurdie 2223
    -[no]exportvars     - Export sanitised JATS EnvVars (default)
379 dpurdie 2224
    -logfile=xxxx       - All output is redirected to the specified file
227 dpurdie 2225
 
331 dpurdie 2226
 Common commands include:
227 dpurdie 2227
    build               - Rebuild the sandbox and makefiles
2228
    make                - Make one or more components
2229
    ant                 - Invoke an ant build
2230
    abt [-java=xxx]     - Invoke the auto build tool
2231
    install             - Install package into local_dpkg_archive
2232
    help                - Display help message
325 dpurdie 2233
    man                 - Display extended help message
227 dpurdie 2234
    vars                - Display JATS related environment variables
2235
 
2236
    create_dpkg         - Install a package into main dpkg_archive
2237
    label               - Labelling functions
2238
    release             - Build a release from a clearcase label
2239
    extract             - Extract a release from a clearcase label
2240
    dpkg_cache          - Maintain a dpkg cache
2241
    gen_msproject       - Generate MSVC project files
361 dpurdie 2242
    sandbox             - Run Sandbox utility
299 dpurdie 2243
 
227 dpurdie 2244
    etool name          - Run internal tool
2245
    eprog name          - Run external tool
2246
    ebin name           - Run JATS binary tool
2247
 
2248
 Shortcut commands. Composites of basic commands
331 dpurdie 2249
    all [opt]           - Same as a "build -noforce" and "make all"
227 dpurdie 2250
    go  [opt]           - Same as a "make all"
2251
    debug [tgt]         - Same as "make debug package_debug"
2252
    prod  [tgt]         - Same as "make prod package_prod"
2253
    clean               - Same as "make clean"
2254
    clobber             - Same as "build clobber"
2255
    *                   - Unknown commands are treated as arguments to etool
2256
 
2257
 Where [cmd-options] are command specific.
325 dpurdie 2258
    Try "jats help command" for details
227 dpurdie 2259
 
2260
=head1 OPTIONS
2261
 
2262
=over 8
2263
 
2264
=item B<-help>
2265
 
2266
Print a brief help message and exits.
2267
 
2268
=item B<-help -help>
2269
 
2270
Print a detailed help message with an explanation for each option.
2271
 
261 dpurdie 2272
=item B<-man[=n]>
227 dpurdie 2273
 
2274
Prints the manual page and exits.
2275
 
261 dpurdie 2276
If a numeric manual level is provide then it will be used to control the
361 dpurdie 2277
verbosity of help provided. This should be in the range of 1 to 3.
261 dpurdie 2278
 
227 dpurdie 2279
=item B<-b file> B<-buildfile file>
2280
 
2281
This option modifies the operation of the "build" command. The command will
2282
use the specified file instead of the normal build.pl file.
2283
 
2284
=item B<-cd dir> B<-changedir dir>
2285
 
2286
This option will change to specified directory before the command is invoked.
2287
 
261 dpurdie 2288
=item B<--verbose[=n]>
227 dpurdie 2289
 
2290
This option will increase the level of verbosity of the JATS command and command
261 dpurdie 2291
invoked by the JATS shell.
227 dpurdie 2292
 
261 dpurdie 2293
If an argument is provided, then it will be used to set the level, otherwise the
2294
existing level will be incremented. This option may be specified multiple times.
227 dpurdie 2295
 
261 dpurdie 2296
=item B<-debug[=n]>
2297
 
227 dpurdie 2298
This option will increase the level of debug output of the JATS command and command
261 dpurdie 2299
invoked by the JATS shell.
227 dpurdie 2300
 
261 dpurdie 2301
If an argument is provided, then it will be used to set the level, otherwise the
2302
existing level will be incremented. This option may be specified multiple times.
2303
 
227 dpurdie 2304
=item B<-here>
2305
 
2306
This option will disable the "autolocate" mechanism of the JATS shell script.
2307
 
2308
By default JATS will "hunt" for a suitable "build.pl" or "makefile.pl" before
2309
executing a build or a make command. JATS will look in the following directories
2310
for a  suitable file. Under some conditions this mechanism is not useful.
2311
 
2312
By default JATS will hunt in the following directories: "." "jats" "build/
2313
jats" ".." "../.." and "../../..".
2314
 
2315
=item B<-locate>
2316
 
2317
This option will cause the JATS wrapper script to locate the build.pl file and
2318
then change to that directory. This allows users to locate the build root of
2319
a project and then issue other JATS commands.
2320
 
2321
If the B<-c> option is also specified then searching will start in the specified
2322
directory.
2323
 
2324
If an alternate build file is specified with the B<-b> option then that filename
2325
will be used in the location process.
2326
 
2327
This option implies a B<-here>. No further scanning will be done.
2328
 
2329
Exactly one build file must be located. If more than buildfile is located then
2330
the locations of the build files is displayed and JATS will terminate.
2331
 
245 dpurdie 2332
 
2333
=item B<-locatepkg=packagename>
2334
 
2335
This option is similar to the B<-locate> option, but it allows the required
2336
build files to be located by ensuring that the required buildfile builds the
2337
specified package.
2338
 
2339
There are two forms in which the B<packagename> can be specified. It can be
361 dpurdie 2340
specified as a full package name and version, or as a package name and the
245 dpurdie 2341
project suffix. ie: jats-api.1.0.0000.cr or jats-api.cr
2342
 
227 dpurdie 2343
=item B<-locatefile=file>
2344
 
2345
This option is similar to the B<-locate> option, but it allows the name of the
2651 dpurdie 2346
build file to be located to be specified.
227 dpurdie 2347
 
2651 dpurdie 2348
If the named file has an '.xml' suffix then the process will look for a pair of
2349
ANT build files of the form xxx.xml and xxxdepends.xml.
2350
 
319 dpurdie 2351
=item B<-locatedir=name>
2352
 
2353
Locate the named directory by scanning from the current directory to the root
321 dpurdie 2354
of the filesystem. This operation is performed before any other location
319 dpurdie 2355
operations and before the B<-cd=path> operation.
2356
 
2357
It may be used to position the jats operation at the root of a view - provided
2358
the view root is known.
2359
 
227 dpurdie 2360
=item B<-platform=[name]>
2361
 
2362
This option will set the JATS specific environment variable GBE_PLATFORM to
2363
the specified name. The existing value of GBE_PLATFORM may be extended by
2364
using "=+".
2365
 
2366
In practice the GBE_PLATFORM variable is of little use. The same effect can be
2367
achieved directly with make targets or with GBE_BUILDFILTER.
2368
 
2369
=item B<-buildfilter=[xxx]>
2370
 
2371
This option will set the JATS specific environment variable GBE_BUILDFILTER to
2372
the specified name. The existing value of GBE_BUILDFILTER may be extended by
2373
using "=+".
2374
 
2375
This option may be used to limit the initial build, and subsequent "make" to a
2376
limited set of platforms.
2377
 
2378
=item B<-abt=[xxx]>
2379
 
2380
This option will set the JATS specific environment variable GBE_ABT to
2381
the specified name The existing value of GBE_ABT may be extended by
2382
using "=+"..
2383
 
2384
This option is used to pass arguments directly to some tools within the
2385
(ABT) Auto Build Tool framework, or to indicate that the build is being
2386
performed within the ABT framework.
2387
 
2388
=item B<-java=version>
2389
 
2390
This option will override the default java version used by the ant builds and
2391
passed to the underlying programs. The path to the Java SDK is determined from
2392
the environment using the version string replacing the '.' with '_'
2393
 
2394
eg: -java=1.5, will examine the environment for JAVA_HOME_1_5 and will set
2395
JAVA_HOME to that value. It will not setup the users PATH or classpath.
2396
 
2397
=item B<-time>
2398
 
2399
When this option is enabled the JATS script will report the runtime of the
2400
underlying, invoked, command.
2401
 
2402
=item B<-version=xxx>
2403
 
2404
When this option is invoked JATS will attempt to use the specified version to
2405
perform all processing. JATS will search the GBE_DPKG_LOCAL, GBE_DPKG_CACHE,
2406
GBE_DPKG, GBE_DPKG_STORE in order to locate the specified version of the package.
2407
 
2408
The entire command line will be passed to the JATS wrapper script within that
2409
version. This bypasses the jats.bat or jats.sh startup scripts.
2410
 
277 dpurdie 2411
JATS will attempt to transfer the target version to the local cache in an
2412
attempt to improve performance.
227 dpurdie 2413
 
277 dpurdie 2414
=item B<-[no]exportvars>
227 dpurdie 2415
 
361 dpurdie 2416
The default operation is to export sanitized and calculated values to the
277 dpurdie 2417
programs running under JATS. The use of NoExportVars will prevent JATS from
2418
exporting modified EnvVars into the environment. This may be required by
2419
processes, such as the build daemons that need to pick up the current version of
2420
JATS on the fly and not have it fixed when the daemon is started.
227 dpurdie 2421
 
379 dpurdie 2422
=item B<-logfile=xxxx>
2423
 
2424
This option will cause all output to be redirected to the named logroll. Both
2425
STDOUT and STDERR will be redirected.
2426
 
2427
The redirection occurs after the sanity testing that JATS performs and before the
2428
user command is invoked. The redirection occurs after any directory change option
2429
is executed.
2430
 
2431
Output redirection continues until the program terminates. If JATS invokes other
2432
programs or scripts, there default output will also be redirected.
2433
 
227 dpurdie 2434
=back
2435
 
2436
=head1 ARGUMENTS
2437
 
2438
=head2 Basic Commands
2439
 
2440
The following commands are invoked directly by the JATS script to wrap the build
2441
tools in a controlled manner.
2442
 
2443
=over 8
2444
 
361 dpurdie 2445
=item L<build|TOOLS::buildlib>
227 dpurdie 2446
 
2447
Build or rebuild the sandbox and makefiles.
2448
 
2449
This command must be used before the component can be "made" and when the
2450
contents of the "buildpl" file change. It is a common mistake to use the "build"
2451
command to much.
2452
 
2453
The script will hunt for a suitable build.pl file before running the build and
2454
make subcommands.
2455
 
361 dpurdie 2456
The build process has a large number of options.
2457
Use L<"JATS build help"|TOOLS::buildlib/"item_help"> to display the complete list.
227 dpurdie 2458
 
361 dpurdie 2459
=item L<make|TOOLS::jmake>
227 dpurdie 2460
 
2461
Make one or more components
2462
 
2463
This command will invoke a suitable "make" program on the makefile found in
2464
the current directory. This makefile should have been generated by JATS.
2465
 
361 dpurdie 2466
The make process has a large number of options. Use
2467
L<"JATS make help"|TOOLS::jmake/"item_help">" to display the complete list.
227 dpurdie 2468
 
2469
=item B<ant>
2470
 
2471
This command will use ANT to build a component. JATS will determine the
2472
build.xml file to use with the following algorithm.
2473
 
2474
    If the files called <Project>depends.xml and <Project>.xml exist then JATS
2475
    will create an 'auto.xml' from the depends file, if one does not already
2476
    exist or is older than the depends.xml file and then use the <Project>.xml
2477
    file as the ant build file.
2478
 
2479
    Otherwise ant is invoked and it will expect a build.xml file.
2480
 
2481
If multiple <Project>depends.xml and <Project>.xml file pairs are found the
2482
command will fail. This can be resolved through the use of the -buildfile=name
2483
option.
2484
 
2485
Ant is invoked with the version of Java specified with the -Java=x.x option.
2486
 
2487
=item B<abt>
2488
 
2489
This command is used to invoke the Auto Build Tool. It will invoke ANT on the
2490
build.xml file in the current directory in such  manner as to not affect the
239 dpurdie 2491
environment of the programs running under ANT.
227 dpurdie 2492
 
361 dpurdie 2493
The remainder of the command line is passed to the ABT, with the exception of
239 dpurdie 2494
the options:
2495
 
2496
=over 8
2497
 
361 dpurdie 2498
=item *
2499
 
2500
-java=x.x. This is used to control the version of Java used by the
349 dpurdie 2501
ABT. The default is 1.6.
227 dpurdie 2502
 
361 dpurdie 2503
=item *
2504
 
2505
-buildfile=name. This is used to provide a different build file to ant.
239 dpurdie 2506
The default build file is 'build.xml'.
2507
 
2508
=back
2509
 
361 dpurdie 2510
=item L<help|TOOLS::jats_help>
227 dpurdie 2511
 
2512
Display the basic help message.
2513
 
361 dpurdie 2514
=item L<vars [-v]|TOOLS::jats_vars>
227 dpurdie 2515
 
2516
This command will display all the JATS related environment variables in a
2517
readable form.
2518
 
2519
Additional information will be displayed if an argument of "-v" is provided.
2520
 
2521
=back
2522
 
2523
=head2 Extended Commands
2524
 
2525
The following commands support the build environment. They are supplemental to
2526
the build environment. They are implemented as extensions to the basic JATS
2527
command scripts.
2528
 
2529
=over 8
2530
 
361 dpurdie 2531
=item L<create_dpkg|TOOLS::create_dpkg>
227 dpurdie 2532
 
2533
This command will install a generated package into main dpkg_archive. This
2534
command should not be used directly by a user as it does not ensure that package
2535
has been created in a repeatable manner - use "jats release".
2536
 
361 dpurdie 2537
=item label
227 dpurdie 2538
 
2539
This command provides a number of useful labelling mechanisms to assist in the
2540
labeling of source code.
2541
 
361 dpurdie 2542
The command will determine the default Version Control System and invoke the VCS
2543
specific utility. This will be one of:
227 dpurdie 2544
 
361 dpurdie 2545
=over 4
227 dpurdie 2546
 
361 dpurdie 2547
=item   *
2548
 
2549
ClearCase: L<cclabel|TOOLS::jats_cclabel>
2550
 
2551
=item   *
2552
 
2553
Subversion: L<svnlabel|TOOLS::jats_svnlabel>
2554
 
2555
=back
2556
 
2557
=item release
2558
 
2559
This command allows a package to be built and released, given a label.
2560
This is the desired release mechanism for manually releasing a package.
2561
 
227 dpurdie 2562
The command has two main uses:
2563
 
361 dpurdie 2564
=over 4
227 dpurdie 2565
 
2566
=item 1
2567
 
2568
Build a package for release. The process will ensure that the build is
2569
controlled and repeatable.
2570
 
2571
=item 2
2572
 
2573
Rebuild a package for test or debugging purposes.
2574
 
2575
=back
2576
 
361 dpurdie 2577
The command will determine the default Version Control System and invoke the VCS
2578
specific utility. This will be one of:
227 dpurdie 2579
 
361 dpurdie 2580
=over 4
2581
 
2582
=item   *
2583
 
2584
ClearCase: L<ccrelease|TOOLS::jats_ccrelease>
2585
 
2586
=item   *
2587
 
2588
Subversion: L<svnrelease|TOOLS::jats_svnrelease>
2589
 
2590
=back
2591
 
2592
=item L<extract|/"release">
2593
 
227 dpurdie 2594
This is the same as "release -extract"
2595
 
2596
 
361 dpurdie 2597
=item L<dpkg_cache|TOOLS::cache_dpkg>
227 dpurdie 2598
 
2599
This utility provides a number of commands to maintain the local cache of
245 dpurdie 2600
dpkg_archive.
227 dpurdie 2601
 
361 dpurdie 2602
=item L<gen_msproject|TOOLS::gen_msprojects>
227 dpurdie 2603
 
2604
This utility will generate a set of Microsoft Studio (Version 6) project and
361 dpurdie 2605
workspace files to encapsulate the JATS build. The resultant project allows
2606
Visual Studio to be used as an editor, source browser, debugger and build tool.
2607
JATS is still used to perform the build.
227 dpurdie 2608
 
361 dpurdie 2609
=item B<install>
2610
 
2611
This command will install a generated "package" into the local_dpkg_archive
2612
directory. This allows a group of packages to be tested before being published
2613
into the global dpkg_archive.
2614
 
2615
=for htmlclass Note
2616
 
2617
Note. This command is no longer needed. The "build" process will place a
2618
shortcut in the local_dpkg_archive to a components "pkg" directory. Other
2619
components will utilize this shortcut directly and pickup the package without
2620
the user needing to "install" the package - a step that can be forgotten.
2621
 
227 dpurdie 2622
=item B<etool name>
2623
 
2624
This command allows any JATS extension program to be run. The programs will by
2625
found in the JATS TOOLS directory.
2626
 
2627
=item B<eprog name>
2628
 
2629
This command allows any JATS extension program to be run.
2630
If the program end in .pl, then it will be run within a perl interpreter.
2631
If the program end in .jar, then it will be run under a java interpreter.
2632
 
2633
=item B<ebin name>
2634
 
2635
This command allows any JATS support program to be run. The programs will by
2636
found in the JATS BIN directory for the current platform. This command allows
2637
a user script to access many of the machine independent utilities in a simple
2638
manner.
2639
 
2640
Example: "JATS ebin ls" - will provide a "real" ls on all platforms.
2641
 
2642
Example: "JATS ebin sh" - will start up the shell used by make.
2643
 
2644
=back
2645
 
2646
=head2 Command Shortcuts
2647
 
2648
The following commands are user shortcuts to the basic commands. The are basic
2649
commands run in sequence.
2650
 
2651
=over 8
2652
 
2653
=item B<all [make_opts]>
2654
 
2655
This command is the same as running the command "build" and "make all".
2656
It will build a component with a single command.
2657
 
2658
If "make_opts" is not present then "make all" is used.
2659
 
2660
If "make_opts" is present then they are passed to the "make" command. In this
2661
manner is it possible to build a WIN32 component of package with a single
2662
command.
2663
 
2664
=item B<go [make_opts]>
2665
 
2666
This command is similar to the "all" shortcut, but it does not "build" the
2667
sandbox. It may be used where the sandbox has already been prepared.
2668
 
2669
=item B<debug [target]>
2670
 
2671
This command is the same as running "make debug package_debug". It will make and
2672
package all the debug components of a sandbox.
2673
 
2674
If any additional arguments are provided to the B<dev> command then they will be
2675
treated as make targets and the commands will be expanded to make and package
2676
the specified debug versions of the names platforms. Make options cannot be
2677
passed in this manner.
2678
 
2679
Example: "JATS dev GAK" will create and package the debug parts for the
2680
GAK_MOS68K and GAK_MOSCF.
2681
 
2682
=item B<prod [target]>
2683
 
2684
This command is the same as running "make prod package_prod". It will make and
2685
package all the debug components of a sandbox.
2686
 
2687
If any additional arguments are provided to the B<prod> command then they will be
2688
treated as make targets and the commands will be expanded to make and package
2689
the specified debug versions of the names platforms. Make options cannot be
2690
passed in this manner.
2691
 
2692
Example: "JATS prod GAK" will create and package the production parts for the
2693
GAK_MOS68K and GAK_MOSCF.
2694
 
2695
=item B<clean>
2696
 
2697
This is the same as "make clean".
2698
 
2699
=item B<clobber>
2700
 
2701
This is the same as "build clobber"
2702
 
2703
=item B<else>
2704
 
2705
Commands that are not known to the JATS wrapper script are passed to etool.
2706
 
2707
ie: "JATS xxxx" is is the same as "JATS etool xxxx".
2708
 
2709
=back
2710
 
2711
=head1 DESCRIPTION
2712
 
2713
JATS is a wrapper script. It provides:
2714
 
361 dpurdie 2715
=over 4
227 dpurdie 2716
 
2717
=item *
2718
 
361 dpurdie 2719
A controlled and sanitized environment to all the build tools.
227 dpurdie 2720
 
2721
=item *
2722
 
2723
The same command interface on all supported machines: Windows, Solaris and
2724
Linux.
2725
 
2726
=item *
2727
 
2728
Provides a framework for extending the build environment toolset.
2729
 
2730
=back
2731
 
315 dpurdie 2732
=head1 RELATED DOCUMENTATION
227 dpurdie 2733
 
361 dpurdie 2734
=over 4
227 dpurdie 2735
 
361 dpurdie 2736
=item   * L<Installation Notes|POD::InstallationNotes>
227 dpurdie 2737
 
361 dpurdie 2738
=item   * L<OverView|POD::OverView>
227 dpurdie 2739
 
361 dpurdie 2740
=item   * L<EnvVars|POD::EnvVars>
255 dpurdie 2741
 
361 dpurdie 2742
=item   * L<PkgArchives|POD::PkgArchives>
227 dpurdie 2743
 
2744
=back
2745
 
361 dpurdie 2746
Use L<jats help|TOOLS::jats_help> to see the available internal documentation.
227 dpurdie 2747
 
315 dpurdie 2748
=head1 EXAMPLES
227 dpurdie 2749
 
315 dpurdie 2750
=over 8
227 dpurdie 2751
 
361 dpurdie 2752
=item   L<JATS help|TOOLS::jats_help>
227 dpurdie 2753
 
315 dpurdie 2754
This will display the available internal documentation.
227 dpurdie 2755
 
361 dpurdie 2756
=item   L<JATS build|TOOLS::buildlib>
227 dpurdie 2757
 
315 dpurdie 2758
This will prime the current package being built ready for "make". The command
2759
will locate the build.pl file and process it. This will locate all the external
2760
packages and generate the required makefiles.
227 dpurdie 2761
 
361 dpurdie 2762
=item   L<JATS make|TOOLS::jmake>
227 dpurdie 2763
 
2764
This will run the GNU make program over the makefiles generated by the "build"
2765
command. This may be executed in a subdirectory in order to limit the targets
2766
that are "made".
2767
 
361 dpurdie 2768
=for htmlclass Note
2769
 
227 dpurdie 2770
B<NOTE:> Do not run "make" without using the JATS wrapper. It will not perform
2771
as expected as the environment will not have been set up correctly.
2772
 
2773
=back
2774
 
2775
=cut
2776