Subversion Repositories DevTools

Rev

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

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