Subversion Repositories DevTools

Rev

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