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