Subversion Repositories DevTools

Rev

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

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