Subversion Repositories DevTools

Rev

Go to most recent revision | Details | 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
242
#
243
my $javaVersion = $gradleTool->{JAVA_VERSION};
244
ReportError ("$javaVersion not defined.", "Building ANDROID requires $javaVersion be installed and correctly configured.") 
245
    unless $ENV{$javaVersion};
246
$ENV{JAVA_HOME}=$ENV{$javaVersion};
247
 
248
#
249
#   Essential tool
250
#       androidSdk  - setup path to the android executable
251
#
252
my $androidSdkTool = getToolInfo('androidSdk');
253
my $androidSdk = catdir($androidSdkTool->{PKGBASE}, $androidSdkTool->{TOOLROOT} );
254
Verbose ("Android SDK : $androidSdk");
255
ReportError("Tool Package 'androidSdk' - Invalid SDK Basedir", "Sdk Base: $androidSdk" )
256
    unless -d ($androidSdk);
257
 
258
#   Essential tool
259
#       androidGradleRepo   - A repo of gradle plugings for android
260
#
261
my $androidGradleRepo = getToolInfo('androidGradleRepo');
262
my $gradleMavenRepo = catdir($androidGradleRepo->{PKGBASE}, $androidGradleRepo->{TOOLROOT});
263
Verbose ("Maven Repo. Gradle support for android : $gradleMavenRepo");
264
 
265
ErrorDoExit();
266
 
267
#
268
#   Create a gradle file with JATS provided version information
269
#   and paths for use within the gradle build.
270
#
271
#   Always do this as the 'clean' will need them
272
#
273
createGradleFiles($opt_clean);
274
 
275
#
276
#   Clean out any build artifacts
277
#
278
if ($opt_clean)
279
{
280
    #
281
    #   Invoke GRADLE on the build script - if present
282
    #
283
    Message ("Clean the existing build");
284
    runGradle ('clean');
285
    deleteGeneratedFiles();
286
    exit 0;
287
}
288
 
289
#
290
#   If we are only populating the build then we 
291
#   need to inject dependencies.
292
#
293
if ($opt_populate)
294
{
295
    deleteInjectedFiles();
296
    injectDependencies();
297
 
298
    Verbose ("Populate complete");
299
    exit 0;
300
}
301
 
302
#
303
#   Build the Android project through gradle
304
#
305
Message ("Build the android project: $androidBuildSuffix");
306
my $rv = runGradle( 'assemble' . $androidBuildSuffix);
307
Error("Cannot build AndroidStudio project") if $rv;
308
exit(0);
309
 
310
#-------------------------------------------------------------------------------
311
# Function        : runGradle 
312
#
313
# Description     : Run gradle to build the project
314
#                   Generate a command like:
315
#                   PathToGradle/gradle --offline -I SomePath/init.gradle <task> 
316
#
317
#                   Use an init-script to inject a sanity test into the build
318
#                   Ensure that the user is using our version numbers.
319
#
320
# Inputs          : task        - Task to run
321
#
322
# Returns         : Returns the error code of the build
323
#
324
sub runGradle
325
{
326
    my ($task) = @_;
327
    Verbose ("runGradle: $task");
328
 
329
    #   The Windows batch file can run in debug mode
330
    #   Make sure that it doesn't by default
331
    $ENV{DEBUG} = "" unless $opt_verbose;
332
 
333
    my $gradleProg = catdir($gradleBinDir, 'gradle');
334
    Verbose ("GradleProg: $gradleProg");
335
 
336
    #
337
    #   Locate the 'init.gradle' script
338
    #   Its co-located with this script
339
    #
340
    my $initScript = catdir(StripFileExt(__FILE__), 'init.gradle');
341
    Verbose ("Gradle Init Script: $initScript");
342
 
343
    #
344
    #   Build up the arg list
345
    #
346
    my @gradleArgs;
347
    push (@gradleArgs, '--offline');
348
#    push (@gradleArgs, '--info');
349
#    push (@gradleArgs, '--debug');
350
    push (@gradleArgs, '--info') if $opt_verbose;
351
    push (@gradleArgs, '--debug') if ($opt_verbose > 2);
352
    push (@gradleArgs, '-I', $initScript) unless ($task =~ m/clean/); 
353
 
354
    my $rv = System('--NoShell', '--NoExit', $gradleProg, @gradleArgs, $task);
355
    return $rv;
356
}
357
 
358
#-------------------------------------------------------------------------------
359
# Function        : createGradleFiles 
360
#
361
# Description     : Calculate Version information
362
#                       gradle.properies
363
#                       local.properties
364
#
365
# Inputs          : quiet           - No output 
366
#
367
# Returns         : Nothing
368
#
369
sub createGradleFiles
370
{
371
    my ($quiet) = @_;
372
 
373
    #
374
    #   Generate Package Versioning information   
375
    #       Need a text string and a number
376
    #       Generate the 'number' from the version number
377
    #
378
    my $version_text;
379
    my $version_num;
380
 
381
    $version_text = $opt_pkgversion;
382
    my ($major, $minor, $patch, $build )= SplitVersion($opt_pkgversion);
383
    foreach my $item ($major, $minor, $patch, $build)
384
    {
385
        Error("Package version has invalid form. It contains non-numeric parts", $item)
386
            unless ( $item =~ m~^\d+$~);
387
    }
388
    $version_num = ($major << 24) + ($minor << 16) + ($patch << 8) + $build;
389
 
390
    Message ("Project Version Txt:" . $version_text) unless $quiet;
391
    Message ("Project Version Num:" . $version_num) unless $quiet;
392
 
393
    #
394
    #   Create the gradle.properties file
395
    #       It needs to be in the projects root directory
396
    #
397
    my $gradleProperies = catfile($project_root,'gradle.properties');
398
    Message ("Create gradle.properties file: " . $gradleProperies) unless $quiet;
399
 
400
    my $data = JatsProperties::New();
401
 
402
    $data->setProperty('GBE_VERSION_NAME' , $version_text);
403
    $data->setProperty('GBE_VERSION_CODE' , $version_num);
404
 
405
    $data->setProperty('GBE_JARLIBS'        , NicePath($androidJars));
406
    $data->setProperty('GBE_JNI_RELEASE'    , NicePath($androidJniProd));
407
    $data->setProperty('GBE_JNI_DEBUG'      , NicePath($androidJniDebug));
408
    $data->setProperty('GBE_GRADLE_REPO'    , NicePath($gradleMavenRepo));
409
 
410
    $data->store( $gradleProperies );
411
 
412
    #
413
    #   Create the local.properties file
414
    #       It needs to be in the projects root directory
415
    #
416
    #   May be able to do without this file - iff we set ANDROID_HOME
417
    #
418
    my $localProperies = catfile($project_root,'local.properties');
419
    Message ("Create local.properties file: " . $localProperies) unless $quiet;
420
 
421
    $data = JatsProperties::New();
422
    $data->setProperty('sdk.dir' , NicePath($androidSdk));
423
    $data->store( $localProperies );
424
}
425
 
426
#-------------------------------------------------------------------------------
427
# Function        : injectDependencies 
428
#
429
# Description     : Inject dependencies
430
#
431
#                   The android build can make use of files in a specific directory
432
#                   Place Jar and Aar files in a specific directory under the root of the project
433
#                   Use a directory called jatsLibs
434
#                   There are two types of files that can be placed in that directory
435
#                   These appear to be:
436
#                       1) .jar files
437
#                       2) .aar files
438
#
439
#                   NDK files will be process automatically by the builder, once the build is made
440
#                   aware of the location. We are not using the AndroidStudio default location
441
#                   Place them into jatsJni within the project root
442
#                       1) Shared libraries provided by NDK components
443
#
444
#                   Need to keep the production and debug JNI files seperate
445
#
446
#                   The gradle dependency processing needs both production and
447
#                   debug dependencies to be present at all times
448
#                   
449
#                   Create three areas:
450
#                       jatsLibs        - Prod and Debug Jars and Ars
451
#                       jatsJniDebug    - Debug JNI files
452
#                       jatsJniProd     - Production JNI files
453
#
454
# Inputs          : 
455
#
456
# Returns         : 
457
#
458
sub injectDependencies
459
{
460
    my @jlist;                  # List of JARs from default directories
461
    my @jpathlist;              # List of JARs from named directories
462
    my @alist;                  # List of AARs from default directories
463
    my @apathlist;              # List of AARs from named directories
464
    my @libListProd;            # List of production libraries
465
    my @libListDebug;           # List of debug libraries
466
    my @platformParts;          # Platforms Parts
467
 
468
 
469
    #
470
    #   Only if we need to do something
471
    #
472
    return unless (@opt_jars || @opt_aars || @opt_elibs || @opt_jlibs);
473
 
474
    #
475
    #   Determine the list of platformm parts
476
    #   This is where 'lib' files will be found
477
    #
478
    @platformParts = getPlatformParts();
479
    Verbose("Platform Parts", @platformParts);
480
 
481
    #
482
    #   Create search entries suitable for the CopyDir
483
    #   We will delete entries as the files are copied
484
    #   Allow for:
485
    #       jar/aar files to have a .jar /.aar suffix (optional)
486
    #       jar/aar files to have path specified with a package
487
    #
488
    #   Split into two lists ( per type ): 
489
    #       Those with a path and those without
490
    #
491
    foreach my $item ( @opt_jars) {
492
        $item =~ s~\.jar~~i;
493
        if ($item =~ m~/~) {
494
            UniquePush \@jpathlist, $item;
495
        } else {
496
            UniquePush \@jlist, $item;
497
        }
498
    }
499
 
500
    foreach my $item ( @opt_aars) {
501
        $item =~ s~\.aar~~i;
502
        if ($item =~ m~/~) {
503
            UniquePush \@apathlist, $item;
504
        } else {
505
            UniquePush \@alist, $item;
506
        }
507
    }
508
 
509
    #   Shared libraries
510
    #   Create full names
511
    foreach my $item ( @opt_elibs) {
512
        UniquePush \@libListDebug, 'lib' . $item . '.so';
513
        UniquePush \@libListProd,  'lib' . $item . '.so';
514
    }
515
 
516
    foreach my $item ( @opt_jlibs) {
517
        UniquePush \@libListDebug, 'lib' . $item . 'D.so';
518
        UniquePush \@libListProd , 'lib' . $item . 'P.so';
519
    }
520
 
521
    #
522
    #   Where does it go
523
    #       JARs/AARs - ROOT/jatsLibs
524
    #       LIBS      - ROOT/jatsJni
525
    #
526
    #   Scan all external packages, and the interface directory
527
    #       Transfer in the required file types
528
    #
529
    my @pkg_paths = getPackagePaths("--Interface=$opt_interface");
530
    foreach my $pkg ( @pkg_paths)
531
    {
532
        #
533
        #   Copy in all JAR files found in dependent packages
534
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
535
        #
536
        my $jarDir = catdir($pkg,'jar');
537
        if (-d $jarDir && @jlist)
538
        {
539
            Verbose("Jar Dir Found found", $jarDir);
540
            Message ("Copy in: $jarDir");
541
 
542
            #
543
            #   Create a matchlist from the JAR list
544
            #   Create a regular expresssion to find a suitable file
545
            #
546
            my @mlist;
547
            foreach  ( @jlist) {
548
                push @mlist, $_ . '.jar|' . $_ . 'P.jar|'. $_ . 'D.jar';
549
            }
550
            CopyDir ( $jarDir, $androidJars,
551
                        'MatchRE' => \@mlist,
552
                        'Log' => $opt_verbose + 1,
553
                        'SymlinkFiles' => 1,
554
                        'Examine' => sub 
555
                            {
556
                                my ($opt) = @_;
557
                                my $baseName = $opt->{file};
558
                                $baseName =~ s~\.jar~~;
559
                                $baseName =~ s~[PD]$~~;
560
                                ArrayDelete \@jlist, $baseName;
561
                                return 1;
562
                            },
563
                    );
564
        }
565
 
566
        #
567
        #   Copy in JARs specified by a full pathname
568
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
569
        #
570
        my @jpathlistBase = @jpathlist;
571
        foreach my $file (@jpathlistBase) 
572
        {
573
            foreach my $suffix ( '', 'P' ,'D')
574
            {
575
                my $jarFile = catdir($pkg, $file . $suffix . '.jar');
576
                if (-f $jarFile)
577
                {
578
                    Verbose("Jar File Found found", $jarDir);
579
                    Message ("Copy in: $jarFile");
580
                    CopyFile ( $jarFile, $androidJars,
581
                                'Log' => $opt_verbose + 1,
582
                                'SymlinkFiles' => 1,
583
                             );
584
                    ArrayDelete \@jpathlist, $file;
585
                }
586
            }
587
        }
588
 
589
        #
590
        #   Copy in AAR files found in dependent packages
591
        #   Need to allow for both AAR files with a -debug/-release suffix 
592
        #   as well as those without
593
        #
594
        foreach my $part (@platformParts)
595
        {
596
            my $aarDir = catdir($pkg,'lib/' . $part);
597
            if (-d $aarDir && @alist)
598
            {
599
                Verbose("Library Dir Found found", $aarDir);
600
                Message ("Copy in: $aarDir");
601
 
602
                #
603
                #   Create a matchlist from the AAR list
604
                #   Create a regular expresssion to find a suitable file
605
                #
606
                my @mlist;
607
                foreach  ( @alist) {
608
                    push @mlist, $_ . '.aar|' . $_ . '-debug.aar|' . $_ . '-release.aar';
609
                }
610
 
611
                CopyDir ( $aarDir, $androidJars,
612
                            'MatchRE' => \@mlist,
613
                            'Log' => $opt_verbose + 1,
614
                            'SymlinkFiles' => 1,
615
                            'Examine' => sub 
616
                                {
617
                                    my ($opt) = @_;
618
                                    my $baseName = $opt->{file};
619
                                    $baseName =~ s~\.aar$~~;
620
                                    $baseName =~ s~-release$~~;
621
                                    $baseName =~ s~-debug$~~;
622
                                    ArrayDelete \@alist, $baseName;
623
                                    return 1;
624
                                },
625
                            );
626
            }
627
        }
628
 
629
 
630
        #
631
        #   Copy in AAR files specified by a full pathname
632
        #   Need to allow for both AAR files with a -debug/-release suffix 
633
        #   as well as those without
634
        #
635
        my @apathlistBase = @apathlist;
636
        foreach my $file (@apathlistBase) 
637
        {
638
            foreach my $suffix ( '', '-release', '-debug')
639
            {
640
                my $aarFile = catdir($pkg, $file . $suffix . '.aar');
641
                if (-f $aarFile)
642
                {
643
                    Verbose("Aar File Found found", $aarFile);
644
                    Message ("Copy in: $aarFile");
645
                    CopyFile ( $aarFile, $androidJars,
646
                                'Log' => $opt_verbose + 1,
647
                                'SymlinkFiles' => 1,
648
                             );
649
                    ArrayDelete \@apathlist, $file;
650
                }
651
            }
652
        }
653
 
654
        #
655
        #   Build up the Shared Library structure as used by JNI
656
        #   Note: Only support current JATS format
657
        #   Copy in .so files and in to process massage the pathname so that
658
        #   it confirms to that expected by the Android Project
659
        #
660
        my $libDir = catdir($pkg, 'lib');
661
        if (-d $libDir && @libListProd)
662
        {
663
            Verbose("Lib Dir Found found", $libDir);
664
            Message ("Copy in: $libDir");
665
            CopyDir ( $libDir, $androidJniProd,
666
                        'Match' => \@libListProd,
667
                        'Log' => $opt_verbose + 1,
668
                        'SymlinkFiles' => 1,
669
                        'Examine' => sub 
670
                            { 
671
                                my ($opt) = @_;
672
                                foreach my $platform ( keys %SharedLibMap ) {
673
                                    my $replace = $SharedLibMap{$platform};
674
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
675
                                    {
676
                                        ArrayDelete \@libListProd, $opt->{file};
677
                                        return 1;
678
                                    }
679
                                }
680
                                return 0;
681
                            },
682
                    );
683
        }
684
 
685
        if (-d $libDir && @libListDebug)
686
        {
687
            Verbose("Lib Dir Found found", $libDir);
688
            Message ("Copy in: $libDir");
689
            CopyDir ( $libDir, $androidJniDebug,
690
                        'Match' => \@libListDebug,
691
                        'Log' => $opt_verbose + 1,
692
                        'SymlinkFiles' => 1,
693
                        'Examine' => sub 
694
                            { 
695
                                my ($opt) = @_;
696
                                foreach my $platform ( keys %SharedLibMap ) {
697
                                    my $replace = $SharedLibMap{$platform};
698
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
699
                                    {
700
                                        ArrayDelete \@libListDebug, $opt->{file};
701
                                        return 1;
702
                                    }
703
                                }
704
                                return 0;
705
                            },
706
                    );
707
        }
708
 
709
    }
710
 
711
    #
712
    #   Report files that could not be located. They were deleted from the lists
713
    #   as they were processed
714
    #       These are Warnings in populate Mode
715
    #       and errors at build time
716
    #
717
    if (@jlist || @libListProd || @libListDebug || @jpathlist || @alist || @apathlist)
718
    {
719
        my $fn = $opt_populate ? \&Warning : \&Error; 
720
        &$fn("External dependencies not found:", @jlist, @jpathlist, @alist, @apathlist, @libListProd , @libListDebug);
721
    }
722
}
723
 
724
#-------------------------------------------------------------------------------
725
# Function        : deleteGeneratedFiles 
726
#
727
# Description     : Delete files that we generate
728
#
729
# Inputs          : 
730
#
731
# Returns         : 
732
#
733
sub deleteGeneratedFiles
734
{
735
    #
736
    #   Delete files that we will create
737
    #
738
    my @deleteList = qw(local.properties gradle.properties);
739
    foreach my $file (@deleteList)
740
    {
741
        Verbose ("Deleting $project_root/$file");
742
        unlink catfile($project_root, $file);
743
    }
744
 
745
}
746
 
747
#-------------------------------------------------------------------------------
748
# Function        : deleteInjectedFiles 
749
#
750
# Description     : Delete files that we inject
751
#
752
# Inputs          : 
753
#
754
# Returns         : 
755
#
756
sub deleteInjectedFiles
757
{
758
    #
759
    #   Remove the jatsJars and JatsJni directories
760
    #   These are created by this tool
761
    #
762
    Verbose("RmDirTree($androidJars)");
763
    RmDirTree($androidJars);
764
 
765
    Verbose("RmDirTree($androidJniBase)");
766
    RmDirTree($androidJniBase);
767
}
768
 
769
 
770
#-------------------------------------------------------------------------------
771
# Function        : NicePath 
772
#
773
# Description     : Process a path and return one that is
774
#                       An absolute Path
775
#                       Uses '/'
776
#
777
# Inputs          : path            - Path to process
778
#
779
# Returns         : A Nice version of path
780
#
781
sub NicePath
782
{
783
    my ($path) = @_;
784
    $path = FullPath($path);
785
    $path =~ s~\\~/~g;
786
    $path = CleanPath($path);
787
    return $path;
788
}
789