Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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