Subversion Repositories DevTools

Rev

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