Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
4937 dpurdie 1
########################################################################
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : androidBuilder.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : This program is invoked by the JATS Makefile System
10
#                 to 'build' an Android project from an AndroidStudio based
11
#                 Android project. It does this by:
12
#                   Creating a build.xml file from the Eclispe files
13
#                   Injecting properties into the build
14
#                       Create gradle.properties (Must not be version controlled)
15
#                       Create local.properties (Must not be version controlled)
16
#                   Insert external dependencies
17
#                       Jar files
18
#                       Aar files
19
#                       JNI Libraries
20
#                   Invoking 'gradle' to perform the build 
21
#
22
#                 This process requires external tool - delivered in packages
23
#                 These are:
24
#                   gradle      - Provides the core of gradle
25
#                   androidSdk  - From package rather than installed
26
#                                 This provides flexability when a new Sdk
27
#                                 is required
28
#
29
# Usage:        The utility is invoked in a controlled manner from a Jats
30
#               makefile. The call is generated by the Android Toolset
31
#               Arguments:
32
#                -verbose                   - Increase debugging
33
#                -verbose=n                 - Increase debugging
34
#                -f=manifestFile.xml        - project Manifest file
35
#                -i=path                    - Path to the interface directory
36
#                -t=[P|D]"                  - Build Type. Production or Debug
37
#                -pn=PackageName            - Package Name
38
#                -pv=PackageVersion         - Package Version
39
#                -clean                     - Will clean the build
40
#                -populate                  - Test Env and Populate 'libs'
41
#               Aguments that can be provided by the user
42
#                -Jar=name                  - Name of a Jar to include
43
#                -Aar=name                  - Name of an Aar to include
44
#                -lname                     - Name of a Jats library to include
45
#                -Lname                     - Name of a 3rd party library to include
46
#
47
# Note: This function may be provided by several packages, 
48
#       thus the interface must not change - this include the name of 
49
#       this file. See the AndroidBuilder package too.
50
#
51
#
52
#......................................................................#
53
 
54
require 5.008_002;
55
use strict;
56
use warnings;
57
 
58
use Getopt::Long qw(:config pass_through);
59
use File::Path;
60
 
61
use JatsError;
62
use JatsSystem;
63
use JatsEnv;
64
use FileUtils;
65
use JatsProperties;
66
use JatsVersionUtils;
67
use ReadBuildConfig;
68
use JatsCopy;
69
use ArrayHashUtils;
70
 
71
#
72
#   Globals
73
#   Command line arguments
74
#
75
my $opt_verbose = $ENV{GBE_VERBOSE};
76
my $opt_buildFile;
77
my $opt_interface;
78
my $opt_gbetype = 'P';
79
my $opt_clean;
80
my $opt_pkgname;
81
my $opt_pkgversion;
82
my $opt_platform;
83
my $opt_populate;
84
my @opt_jlibs;                  # List of Jats Libraries
85
my @opt_elibs;                  # List of 3rd party libraries
86
my @opt_jars;                   # List of JARs
87
my @opt_aars;                   # List of AARs
88
 
89
#
90
#   Configuration
91
#   Map JATS platforms to Shared library targets
92
#
93
my %SharedLibMap = (
94
    'ANDROIDARM'    => 'armeabi',
95
    'ANDROIDMIPS'   => 'mips',
96
    'ANDROIDX86'    => 'x86',
97
    );
98
 
99
our $GBE_HOSTMACH;              # Sanity Test of machine type
100
our $GBE_MAKE_TARGET;           # Current build target
101
 
102
my $androidJars;                # Root of injected JARs and AARs
103
my $androidJniBase;             # Root of injected JNI files
104
my $androidJniProd;             # Root of injected JNI files - Prod
105
my $androidJniDebug;            # Root of injected JNI files - Debug
106
my $androidBuildSuffix = '';    # Prefix build commands
107
 
108
#-------------------------------------------------------------------------------
109
# Function        : Main Entry Point 
110
#
111
# Description     : Main entry to this program
112
#
113
# Inputs          : @ARGV           - Array of command line arguments
114
#                                     See file header
115
#
116
# Returns         : 0               - No Error
117
#                   1               - Error encountered    
118
#
119
InitFileUtils();
120
ErrorConfig( 'name'    => 'ANDROIDBUILDER',
121
             'verbose' => $opt_verbose);
122
$opt_verbose = $::ScmVerbose;               # Get the calculated verbosity level
123
 
124
#
125
#   Install local signal handlers to process GetOptions messages
126
#
127
local $SIG{__WARN__} = sub { ReportError('AndroidBuilder.' . "@_"); };
128
local $SIG{__DIE__} = sub { ReportError('AndroidBuilder.' . "@_"); };
129
my $result = GetOptions (
130
                "verbose:+"     => \$opt_verbose,       # flag
131
                "f=s"           => \$opt_buildFile,     # string
132
                "i=s"           => \$opt_interface,     # Interface directory
133
                "t=s"           => \$opt_gbetype,       # string
134
                "pn=s"          => \$opt_pkgname,       # string
135
                "pv=s"          => \$opt_pkgversion,    # string
136
                "pf=s"          => \$opt_platform,      # string
137
                "clean"         => \$opt_clean,         # flag
138
                "populate"      => \$opt_populate,      # flag
139
                "Jar=s"         => \@opt_jars,
140
                "Aar=s"         => \@opt_aars,
141
                );
142
 
143
#
144
#   Restore signal handlers and report parse errors
145
#
146
$SIG{__WARN__} = 'DEFAULT';
147
$SIG{__DIE__} = 'DEFAULT';
148
Error('AndroidBuilder. Invalid call options detected') if (!$result);
149
 
150
#
151
#   Process remaining arguments
152
#   Only --Lname and --lname are valid
153
#
154
foreach my $arg (@ARGV) {
155
    if ($arg =~ m~^[-]{1,2}l(.*)~) {
156
        push @opt_jlibs, $1;
157
    } elsif ($arg =~ m~^[-]{1,2}L(.*)~) {
158
        push @opt_elibs, $1;
159
    } else {
160
        ReportError("Invalid option: $arg");
161
    }
162
}
163
ErrorDoExit();
164
 
165
#
166
#   Sanity Test
167
#
168
ReportError ("Gradle build file not specified") unless ( defined $opt_buildFile); 
169
ReportError ("Gradle build file not found: $opt_buildFile") unless ( -f $opt_buildFile);
170
 
171
ReportError ("Interface directory not specified") unless ( defined $opt_interface);
172
ReportError ("Interface directory not found: $opt_interface") unless ( -d $opt_interface);
173
 
174
ReportError ("Package Name not specified") unless ( defined $opt_pkgname); 
175
ReportError ("Package Version not specified") unless ( defined $opt_pkgversion); 
176
 
177
EnvImport('GBE_HOSTMACH');
178
ReportError ("AndroidStudioBuilder is only supported under win32","This machine is: ".$::GBE_HOSTMACH ) unless ( $::GBE_HOSTMACH eq 'win32' );
179
ReportError ("Platform not found") unless ( defined $opt_platform );
180
 
181
ErrorDoExit();
182
 
183
#
184
#   Basic setup
185
#
186
$androidBuildSuffix = ($opt_gbetype eq 'P') ? 'Release' : 'Debug';
187
 
188
#
189
#   The user provides the root build.gradle file
190
#   There MUST be a settings.gradle in the same directory
191
#       This is a JATS assumption - subject to change
192
#   There will be some other files there too
193
#   Calculate the root of the project
194
#
195
$opt_buildFile = RelPath(AbsPath($opt_buildFile));
196
my $project_root = StripFileExt($opt_buildFile);
197
   $project_root = '.' unless $project_root;
198
my $project_settingsFile = catfile($project_root, 'settings.gradle');
199
 
200
Message ("Project Base:" . Getcwd());
201
Message ("Project Root:" . $project_root);
202
Verbose ("Project Settings file:" . $project_settingsFile);
203
 
204
#
205
#   Directories to store Jar's, Aar's and JNI shared libarares
206
#   are created in the interface directory
207
#
208
$androidJars      = catdir($opt_interface, 'jatsLibs');
209
$androidJniBase   = catdir($opt_interface, 'jatsJni');
210
$androidJniProd   = catdir($androidJniBase, 'Release');
211
$androidJniDebug  = catdir($androidJniBase, 'Debug');
212
 
213
Verbose ("Interface:" . $opt_interface);
214
Verbose ("Android Jars: $androidJars");
215
Verbose ("Android JNI : $androidJniBase");
216
 
217
Error ("Gradle settings file not found: $project_settingsFile") unless ( -f $project_settingsFile);
218
 
219
#
220
#   Essential tool
221
#       gradle     - setup 
222
#                    GRADLE_USER_HOME
223
#                    JAVA_HOME
224
#                    
225
ReadBuildConfig( $opt_interface, $opt_platform, '--NoTest' );
226
 
227
my $gradleTool = getToolInfo('gradle', 'JAVA_VERSION', 'GRADLE_BIN');
228
my $gradleBinDir = catdir($gradleTool->{PKGBASE}, $gradleTool->{TOOLROOT}, $gradleTool->{GRADLE_BIN});
229
 
230
#
231
#   Setup a gradle home
232
#   Its used to cache stuff - create it within the interface directory
233
#
234
my $gradleHomeTarget = CleanPath(FullPath(catdir($opt_interface, 'gradleUserHome')));
235
mkpath($gradleHomeTarget, 0, 0775) 
236
    unless ( -d $gradleHomeTarget);
237
$ENV{GRADLE_USER_HOME} = $gradleHomeTarget;
238
Verbose("GRADLE_USER_HOME:", $ENV{GRADLE_USER_HOME});
239
 
240
#
241
#   Setup the required version of Java for the tool
5289 dpurdie 242
#   Force JAVA_OPTS to set Min/Max Heap
243
#       Use JAVA_OPTS because
244
#           _JAVA_OPTIONS causes ssytem to emit a lot of warnings that _JAVA_OPTIONS is being used
245
#           Use of org.gradle.jvmargs in gradle.properties causes warnins about forking speed
246
#           Fixing the max size will provide consistent builds
247
#           Perhaps one day it will be configured 
4937 dpurdie 248
#
249
my $javaVersion = $gradleTool->{JAVA_VERSION};
250
ReportError ("$javaVersion not defined.", "Building ANDROID requires $javaVersion be installed and correctly configured.") 
251
    unless $ENV{$javaVersion};
252
$ENV{JAVA_HOME}=$ENV{$javaVersion};
5289 dpurdie 253
$ENV{JAVA_OPTS} = '-Xms256m -Xmx1024m';
4937 dpurdie 254
 
255
#
256
#   Essential tool
257
#       androidSdk  - setup path to the android executable
258
#
259
my $androidSdkTool = getToolInfo('androidSdk');
260
my $androidSdk = catdir($androidSdkTool->{PKGBASE}, $androidSdkTool->{TOOLROOT} );
261
Verbose ("Android SDK : $androidSdk");
262
ReportError("Tool Package 'androidSdk' - Invalid SDK Basedir", "Sdk Base: $androidSdk" )
263
    unless -d ($androidSdk);
264
 
265
#   Essential tool
266
#       androidGradleRepo   - A repo of gradle plugings for android
267
#
268
my $androidGradleRepo = getToolInfo('androidGradleRepo');
269
my $gradleMavenRepo = catdir($androidGradleRepo->{PKGBASE}, $androidGradleRepo->{TOOLROOT});
270
Verbose ("Maven Repo. Gradle support for android : $gradleMavenRepo");
271
 
272
ErrorDoExit();
273
 
274
#
275
#   Create a gradle file with JATS provided version information
276
#   and paths for use within the gradle build.
277
#
278
#   Always do this as the 'clean' will need them
279
#
280
createGradleFiles($opt_clean);
281
 
282
#
283
#   Clean out any build artifacts
284
#
285
if ($opt_clean)
286
{
287
    #
288
    #   Invoke GRADLE on the build script - if present
289
    #
290
    Message ("Clean the existing build");
291
    runGradle ('clean');
292
    deleteGeneratedFiles();
293
    exit 0;
294
}
295
 
296
#
297
#   If we are only populating the build then we 
298
#   need to inject dependencies.
299
#
300
if ($opt_populate)
301
{
302
    deleteInjectedFiles();
303
    injectDependencies();
304
 
305
    Verbose ("Populate complete");
306
    exit 0;
307
}
308
 
309
#
310
#   Build the Android project through gradle
311
#
312
Message ("Build the android project: $androidBuildSuffix");
313
my $rv = runGradle( 'assemble' . $androidBuildSuffix);
314
Error("Cannot build AndroidStudio project") if $rv;
315
exit(0);
316
 
317
#-------------------------------------------------------------------------------
318
# Function        : runGradle 
319
#
320
# Description     : Run gradle to build the project
321
#                   Generate a command like:
322
#                   PathToGradle/gradle --offline -I SomePath/init.gradle <task> 
323
#
324
#                   Use an init-script to inject a sanity test into the build
325
#                   Ensure that the user is using our version numbers.
326
#
327
# Inputs          : task        - Task to run
328
#
329
# Returns         : Returns the error code of the build
330
#
331
sub runGradle
332
{
333
    my ($task) = @_;
334
    Verbose ("runGradle: $task");
335
 
336
    #   The Windows batch file can run in debug mode
337
    #   Make sure that it doesn't by default
338
    $ENV{DEBUG} = "" unless $opt_verbose;
339
 
340
    my $gradleProg = catdir($gradleBinDir, 'gradle');
341
    Verbose ("GradleProg: $gradleProg");
342
 
343
    #
344
    #   Locate the 'init.gradle' script
345
    #   Its co-located with this script
346
    #
347
    my $initScript = catdir(StripFileExt(__FILE__), 'init.gradle');
348
    Verbose ("Gradle Init Script: $initScript");
349
 
350
    #
351
    #   Build up the arg list
352
    #
353
    my @gradleArgs;
354
    push (@gradleArgs, '--offline');
355
#    push (@gradleArgs, '--info');
356
#    push (@gradleArgs, '--debug');
357
    push (@gradleArgs, '--info') if $opt_verbose;
358
    push (@gradleArgs, '--debug') if ($opt_verbose > 2);
359
    push (@gradleArgs, '-I', $initScript) unless ($task =~ m/clean/); 
360
 
361
    my $rv = System('--NoShell', '--NoExit', $gradleProg, @gradleArgs, $task);
362
    return $rv;
363
}
364
 
365
#-------------------------------------------------------------------------------
366
# Function        : createGradleFiles 
367
#
368
# Description     : Calculate Version information
369
#                       gradle.properies
370
#                       local.properties
371
#
372
# Inputs          : quiet           - No output 
373
#
374
# Returns         : Nothing
375
#
376
sub createGradleFiles
377
{
378
    my ($quiet) = @_;
379
 
380
    #
381
    #   Generate Package Versioning information   
382
    #       Need a text string and a number
383
    #       Generate the 'number' from the version number
384
    #
385
    my $version_text;
386
    my $version_num;
387
 
388
    $version_text = $opt_pkgversion;
389
    my ($major, $minor, $patch, $build )= SplitVersion($opt_pkgversion);
390
    foreach my $item ($major, $minor, $patch, $build)
391
    {
392
        Error("Package version has invalid form. It contains non-numeric parts", $item)
393
            unless ( $item =~ m~^\d+$~);
394
    }
395
    $version_num = ($major << 24) + ($minor << 16) + ($patch << 8) + $build;
396
 
397
    Message ("Project Version Txt:" . $version_text) unless $quiet;
398
    Message ("Project Version Num:" . $version_num) unless $quiet;
399
 
400
    #
401
    #   Create the gradle.properties file
402
    #       It needs to be in the projects root directory
403
    #
404
    my $gradleProperies = catfile($project_root,'gradle.properties');
405
    Message ("Create gradle.properties file: " . $gradleProperies) unless $quiet;
406
 
407
    my $data = JatsProperties::New();
408
 
409
    $data->setProperty('GBE_VERSION_NAME' , $version_text);
410
    $data->setProperty('GBE_VERSION_CODE' , $version_num);
411
 
412
    $data->setProperty('GBE_JARLIBS'        , NicePath($androidJars));
413
    $data->setProperty('GBE_JNI_RELEASE'    , NicePath($androidJniProd));
414
    $data->setProperty('GBE_JNI_DEBUG'      , NicePath($androidJniDebug));
415
    $data->setProperty('GBE_GRADLE_REPO'    , NicePath($gradleMavenRepo));
416
 
417
    $data->store( $gradleProperies );
418
 
419
    #
420
    #   Create the local.properties file
421
    #       It needs to be in the projects root directory
422
    #
423
    #   May be able to do without this file - iff we set ANDROID_HOME
424
    #
425
    my $localProperies = catfile($project_root,'local.properties');
426
    Message ("Create local.properties file: " . $localProperies) unless $quiet;
427
 
428
    $data = JatsProperties::New();
429
    $data->setProperty('sdk.dir' , NicePath($androidSdk));
430
    $data->store( $localProperies );
431
}
432
 
433
#-------------------------------------------------------------------------------
434
# Function        : injectDependencies 
435
#
436
# Description     : Inject dependencies
437
#
438
#                   The android build can make use of files in a specific directory
439
#                   Place Jar and Aar files in a specific directory under the root of the project
440
#                   Use a directory called jatsLibs
441
#                   There are two types of files that can be placed in that directory
442
#                   These appear to be:
443
#                       1) .jar files
444
#                       2) .aar files
445
#
446
#                   NDK files will be process automatically by the builder, once the build is made
447
#                   aware of the location. We are not using the AndroidStudio default location
448
#                   Place them into jatsJni within the project root
449
#                       1) Shared libraries provided by NDK components
450
#
451
#                   Need to keep the production and debug JNI files seperate
452
#
453
#                   The gradle dependency processing needs both production and
454
#                   debug dependencies to be present at all times
455
#                   
456
#                   Create three areas:
457
#                       jatsLibs        - Prod and Debug Jars and Ars
458
#                       jatsJniDebug    - Debug JNI files
459
#                       jatsJniProd     - Production JNI files
460
#
461
# Inputs          : 
462
#
463
# Returns         : 
464
#
465
sub injectDependencies
466
{
467
    my @jlist;                  # List of JARs from default directories
468
    my @jpathlist;              # List of JARs from named directories
469
    my @alist;                  # List of AARs from default directories
470
    my @apathlist;              # List of AARs from named directories
471
    my @libListProd;            # List of production libraries
472
    my @libListDebug;           # List of debug libraries
473
    my @platformParts;          # Platforms Parts
474
 
4990 dpurdie 475
    my @jarSearch;              # Search paths - diagnostic display
476
    my @aarSearch;
477
    my @libSearch;
4937 dpurdie 478
 
4990 dpurdie 479
 
4937 dpurdie 480
    #
481
    #   Only if we need to do something
482
    #
483
    return unless (@opt_jars || @opt_aars || @opt_elibs || @opt_jlibs);
484
 
485
    #
486
    #   Determine the list of platformm parts
487
    #   This is where 'lib' files will be found
488
    #
489
    @platformParts = getPlatformParts();
490
    Verbose("Platform Parts", @platformParts);
491
 
492
    #
493
    #   Create search entries suitable for the CopyDir
494
    #   We will delete entries as the files are copied
495
    #   Allow for:
496
    #       jar/aar files to have a .jar /.aar suffix (optional)
497
    #       jar/aar files to have path specified with a package
498
    #
499
    #   Split into two lists ( per type ): 
500
    #       Those with a path and those without
501
    #
502
    foreach my $item ( @opt_jars) {
503
        $item =~ s~\.jar~~i;
504
        if ($item =~ m~/~) {
505
            UniquePush \@jpathlist, $item;
506
        } else {
507
            UniquePush \@jlist, $item;
508
        }
509
    }
510
 
511
    foreach my $item ( @opt_aars) {
512
        $item =~ s~\.aar~~i;
513
        if ($item =~ m~/~) {
514
            UniquePush \@apathlist, $item;
515
        } else {
516
            UniquePush \@alist, $item;
517
        }
518
    }
519
 
520
    #   Shared libraries
521
    #   Create full names
522
    foreach my $item ( @opt_elibs) {
523
        UniquePush \@libListDebug, 'lib' . $item . '.so';
524
        UniquePush \@libListProd,  'lib' . $item . '.so';
525
    }
526
 
527
    foreach my $item ( @opt_jlibs) {
528
        UniquePush \@libListDebug, 'lib' . $item . 'D.so';
529
        UniquePush \@libListProd , 'lib' . $item . 'P.so';
530
    }
531
 
532
    #
533
    #   Where does it go
534
    #       JARs/AARs - ROOT/jatsLibs
535
    #       LIBS      - ROOT/jatsJni
536
    #
537
    #   Scan all external packages, and the interface directory
538
    #       Transfer in the required file types
539
    #
540
    my @pkg_paths = getPackagePaths("--Interface=$opt_interface");
541
    foreach my $pkg ( @pkg_paths)
542
    {
543
        #
544
        #   Copy in all JAR files found in dependent packages
545
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
546
        #
547
        my $jarDir = catdir($pkg,'jar');
4990 dpurdie 548
        push @jarSearch, $jarDir;
4937 dpurdie 549
        if (-d $jarDir && @jlist)
550
        {
551
            Verbose("Jar Dir Found found", $jarDir);
552
            Message ("Copy in: $jarDir");
553
 
554
            #
555
            #   Create a matchlist from the JAR list
556
            #   Create a regular expresssion to find a suitable file
557
            #
558
            my @mlist;
559
            foreach  ( @jlist) {
560
                push @mlist, $_ . '.jar|' . $_ . 'P.jar|'. $_ . 'D.jar';
561
            }
562
            CopyDir ( $jarDir, $androidJars,
563
                        'MatchRE' => \@mlist,
564
                        'Log' => $opt_verbose + 1,
565
                        'SymlinkFiles' => 1,
566
                        'Examine' => sub 
567
                            {
568
                                my ($opt) = @_;
569
                                my $baseName = $opt->{file};
570
                                $baseName =~ s~\.jar~~;
571
                                $baseName =~ s~[PD]$~~;
572
                                ArrayDelete \@jlist, $baseName;
573
                                return 1;
574
                            },
575
                    );
576
        }
577
 
578
        #
579
        #   Copy in JARs specified by a full pathname
580
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
581
        #
582
        my @jpathlistBase = @jpathlist;
583
        foreach my $file (@jpathlistBase) 
584
        {
585
            foreach my $suffix ( '', 'P' ,'D')
586
            {
587
                my $jarFile = catdir($pkg, $file . $suffix . '.jar');
4990 dpurdie 588
                push @jarSearch, $jarFile;
4937 dpurdie 589
                if (-f $jarFile)
590
                {
591
                    Verbose("Jar File Found found", $jarDir);
592
                    Message ("Copy in: $jarFile");
593
                    CopyFile ( $jarFile, $androidJars,
594
                                'Log' => $opt_verbose + 1,
595
                                'SymlinkFiles' => 1,
596
                             );
597
                    ArrayDelete \@jpathlist, $file;
598
                }
599
            }
600
        }
601
 
602
        #
603
        #   Copy in AAR files found in dependent packages
604
        #   Need to allow for both AAR files with a -debug/-release suffix 
605
        #   as well as those without
606
        #
607
        foreach my $part (@platformParts)
608
        {
609
            my $aarDir = catdir($pkg,'lib/' . $part);
4990 dpurdie 610
            push @aarSearch, $aarDir;
4937 dpurdie 611
            if (-d $aarDir && @alist)
612
            {
613
                Verbose("Library Dir Found found", $aarDir);
614
                Message ("Copy in: $aarDir");
615
 
616
                #
617
                #   Create a matchlist from the AAR list
618
                #   Create a regular expresssion to find a suitable file
619
                #
620
                my @mlist;
621
                foreach  ( @alist) {
622
                    push @mlist, $_ . '.aar|' . $_ . '-debug.aar|' . $_ . '-release.aar';
623
                }
624
 
625
                CopyDir ( $aarDir, $androidJars,
626
                            'MatchRE' => \@mlist,
627
                            'Log' => $opt_verbose + 1,
628
                            'SymlinkFiles' => 1,
629
                            'Examine' => sub 
630
                                {
631
                                    my ($opt) = @_;
632
                                    my $baseName = $opt->{file};
633
                                    $baseName =~ s~\.aar$~~;
634
                                    $baseName =~ s~-release$~~;
635
                                    $baseName =~ s~-debug$~~;
636
                                    ArrayDelete \@alist, $baseName;
637
                                    return 1;
638
                                },
639
                            );
640
            }
641
        }
642
 
643
 
644
        #
645
        #   Copy in AAR files specified by a full pathname
646
        #   Need to allow for both AAR files with a -debug/-release suffix 
647
        #   as well as those without
648
        #
649
        my @apathlistBase = @apathlist;
650
        foreach my $file (@apathlistBase) 
651
        {
652
            foreach my $suffix ( '', '-release', '-debug')
653
            {
654
                my $aarFile = catdir($pkg, $file . $suffix . '.aar');
4990 dpurdie 655
                push @aarSearch, $aarFile;
4937 dpurdie 656
                if (-f $aarFile)
657
                {
658
                    Verbose("Aar File Found found", $aarFile);
659
                    Message ("Copy in: $aarFile");
660
                    CopyFile ( $aarFile, $androidJars,
661
                                'Log' => $opt_verbose + 1,
662
                                'SymlinkFiles' => 1,
663
                             );
664
                    ArrayDelete \@apathlist, $file;
665
                }
666
            }
667
        }
668
 
669
        #
670
        #   Build up the Shared Library structure as used by JNI
671
        #   Note: Only support current JATS format
672
        #   Copy in .so files and in to process massage the pathname so that
673
        #   it confirms to that expected by the Android Project
674
        #
675
        my $libDir = catdir($pkg, 'lib');
4990 dpurdie 676
        push @libSearch, $libDir;
4937 dpurdie 677
        if (-d $libDir && @libListProd)
678
        {
679
            Verbose("Lib Dir Found found", $libDir);
680
            Message ("Copy in: $libDir");
681
            CopyDir ( $libDir, $androidJniProd,
682
                        'Match' => \@libListProd,
683
                        'Log' => $opt_verbose + 1,
684
                        'SymlinkFiles' => 1,
685
                        'Examine' => sub 
686
                            { 
687
                                my ($opt) = @_;
688
                                foreach my $platform ( keys %SharedLibMap ) {
689
                                    my $replace = $SharedLibMap{$platform};
690
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
691
                                    {
692
                                        ArrayDelete \@libListProd, $opt->{file};
693
                                        return 1;
694
                                    }
695
                                }
696
                                return 0;
697
                            },
698
                    );
699
        }
700
 
701
        if (-d $libDir && @libListDebug)
702
        {
703
            Verbose("Lib Dir Found found", $libDir);
704
            Message ("Copy in: $libDir");
705
            CopyDir ( $libDir, $androidJniDebug,
706
                        'Match' => \@libListDebug,
707
                        'Log' => $opt_verbose + 1,
708
                        'SymlinkFiles' => 1,
709
                        'Examine' => sub 
710
                            { 
711
                                my ($opt) = @_;
712
                                foreach my $platform ( keys %SharedLibMap ) {
713
                                    my $replace = $SharedLibMap{$platform};
714
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
715
                                    {
716
                                        ArrayDelete \@libListDebug, $opt->{file};
717
                                        return 1;
718
                                    }
719
                                }
720
                                return 0;
721
                            },
722
                    );
723
        }
724
 
725
    }
726
 
727
    #
728
    #   Report files that could not be located. They were deleted from the lists
729
    #   as they were processed
730
    #
4990 dpurdie 731
    if (@jlist || @jpathlist || @alist || @apathlist ||  @libListProd || @libListDebug )
4937 dpurdie 732
    {
4990 dpurdie 733
        ReportError("External dependencies not found:", @jlist , @jpathlist , @alist , @apathlist ,  @libListProd , @libListDebug);
734
        if (@jlist || @jpathlist)
735
        {
736
            ReportError("Jar Search Path", @jarSearch);
737
        }
738
 
739
        if (@alist || @apathlist)
740
        {
741
            ReportError("Aar Search Path", @aarSearch);
742
        }
743
 
744
        if ( @libListProd || @libListDebug)
745
        {
746
            ReportError("Lib Search Path", @libSearch);
747
        }
748
    ErrorDoExit();
4937 dpurdie 749
    }
750
}
751
 
752
#-------------------------------------------------------------------------------
753
# Function        : deleteGeneratedFiles 
754
#
755
# Description     : Delete files that we generate
756
#
757
# Inputs          : 
758
#
759
# Returns         : 
760
#
761
sub deleteGeneratedFiles
762
{
763
    #
764
    #   Delete files that we will create
765
    #
766
    my @deleteList = qw(local.properties gradle.properties);
767
    foreach my $file (@deleteList)
768
    {
769
        Verbose ("Deleting $project_root/$file");
770
        unlink catfile($project_root, $file);
771
    }
772
 
773
}
774
 
775
#-------------------------------------------------------------------------------
776
# Function        : deleteInjectedFiles 
777
#
778
# Description     : Delete files that we inject
779
#
780
# Inputs          : 
781
#
782
# Returns         : 
783
#
784
sub deleteInjectedFiles
785
{
786
    #
787
    #   Remove the jatsJars and JatsJni directories
788
    #   These are created by this tool
789
    #
790
    Verbose("RmDirTree($androidJars)");
791
    RmDirTree($androidJars);
792
 
793
    Verbose("RmDirTree($androidJniBase)");
794
    RmDirTree($androidJniBase);
795
}
796
 
797
 
798
#-------------------------------------------------------------------------------
799
# Function        : NicePath 
800
#
801
# Description     : Process a path and return one that is
802
#                       An absolute Path
803
#                       Uses '/'
804
#
805
# Inputs          : path            - Path to process
806
#
807
# Returns         : A Nice version of path
808
#
809
sub NicePath
810
{
811
    my ($path) = @_;
812
    $path = FullPath($path);
813
    $path =~ s~\\~/~g;
814
    $path = CleanPath($path);
815
    return $path;
816
}
817