Subversion Repositories DevTools

Rev

Rev 4937 | Rev 5289 | 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
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
 
4990 dpurdie 468
    my @jarSearch;              # Search paths - diagnostic display
469
    my @aarSearch;
470
    my @libSearch;
4937 dpurdie 471
 
4990 dpurdie 472
 
4937 dpurdie 473
    #
474
    #   Only if we need to do something
475
    #
476
    return unless (@opt_jars || @opt_aars || @opt_elibs || @opt_jlibs);
477
 
478
    #
479
    #   Determine the list of platformm parts
480
    #   This is where 'lib' files will be found
481
    #
482
    @platformParts = getPlatformParts();
483
    Verbose("Platform Parts", @platformParts);
484
 
485
    #
486
    #   Create search entries suitable for the CopyDir
487
    #   We will delete entries as the files are copied
488
    #   Allow for:
489
    #       jar/aar files to have a .jar /.aar suffix (optional)
490
    #       jar/aar files to have path specified with a package
491
    #
492
    #   Split into two lists ( per type ): 
493
    #       Those with a path and those without
494
    #
495
    foreach my $item ( @opt_jars) {
496
        $item =~ s~\.jar~~i;
497
        if ($item =~ m~/~) {
498
            UniquePush \@jpathlist, $item;
499
        } else {
500
            UniquePush \@jlist, $item;
501
        }
502
    }
503
 
504
    foreach my $item ( @opt_aars) {
505
        $item =~ s~\.aar~~i;
506
        if ($item =~ m~/~) {
507
            UniquePush \@apathlist, $item;
508
        } else {
509
            UniquePush \@alist, $item;
510
        }
511
    }
512
 
513
    #   Shared libraries
514
    #   Create full names
515
    foreach my $item ( @opt_elibs) {
516
        UniquePush \@libListDebug, 'lib' . $item . '.so';
517
        UniquePush \@libListProd,  'lib' . $item . '.so';
518
    }
519
 
520
    foreach my $item ( @opt_jlibs) {
521
        UniquePush \@libListDebug, 'lib' . $item . 'D.so';
522
        UniquePush \@libListProd , 'lib' . $item . 'P.so';
523
    }
524
 
525
    #
526
    #   Where does it go
527
    #       JARs/AARs - ROOT/jatsLibs
528
    #       LIBS      - ROOT/jatsJni
529
    #
530
    #   Scan all external packages, and the interface directory
531
    #       Transfer in the required file types
532
    #
533
    my @pkg_paths = getPackagePaths("--Interface=$opt_interface");
534
    foreach my $pkg ( @pkg_paths)
535
    {
536
        #
537
        #   Copy in all JAR files found in dependent packages
538
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
539
        #
540
        my $jarDir = catdir($pkg,'jar');
4990 dpurdie 541
        push @jarSearch, $jarDir;
4937 dpurdie 542
        if (-d $jarDir && @jlist)
543
        {
544
            Verbose("Jar Dir Found found", $jarDir);
545
            Message ("Copy in: $jarDir");
546
 
547
            #
548
            #   Create a matchlist from the JAR list
549
            #   Create a regular expresssion to find a suitable file
550
            #
551
            my @mlist;
552
            foreach  ( @jlist) {
553
                push @mlist, $_ . '.jar|' . $_ . 'P.jar|'. $_ . 'D.jar';
554
            }
555
            CopyDir ( $jarDir, $androidJars,
556
                        'MatchRE' => \@mlist,
557
                        'Log' => $opt_verbose + 1,
558
                        'SymlinkFiles' => 1,
559
                        'Examine' => sub 
560
                            {
561
                                my ($opt) = @_;
562
                                my $baseName = $opt->{file};
563
                                $baseName =~ s~\.jar~~;
564
                                $baseName =~ s~[PD]$~~;
565
                                ArrayDelete \@jlist, $baseName;
566
                                return 1;
567
                            },
568
                    );
569
        }
570
 
571
        #
572
        #   Copy in JARs specified by a full pathname
573
        #   Need to allow for Jars that have a P/D suffix as well as those that don't
574
        #
575
        my @jpathlistBase = @jpathlist;
576
        foreach my $file (@jpathlistBase) 
577
        {
578
            foreach my $suffix ( '', 'P' ,'D')
579
            {
580
                my $jarFile = catdir($pkg, $file . $suffix . '.jar');
4990 dpurdie 581
                push @jarSearch, $jarFile;
4937 dpurdie 582
                if (-f $jarFile)
583
                {
584
                    Verbose("Jar File Found found", $jarDir);
585
                    Message ("Copy in: $jarFile");
586
                    CopyFile ( $jarFile, $androidJars,
587
                                'Log' => $opt_verbose + 1,
588
                                'SymlinkFiles' => 1,
589
                             );
590
                    ArrayDelete \@jpathlist, $file;
591
                }
592
            }
593
        }
594
 
595
        #
596
        #   Copy in AAR files found in dependent packages
597
        #   Need to allow for both AAR files with a -debug/-release suffix 
598
        #   as well as those without
599
        #
600
        foreach my $part (@platformParts)
601
        {
602
            my $aarDir = catdir($pkg,'lib/' . $part);
4990 dpurdie 603
            push @aarSearch, $aarDir;
4937 dpurdie 604
            if (-d $aarDir && @alist)
605
            {
606
                Verbose("Library Dir Found found", $aarDir);
607
                Message ("Copy in: $aarDir");
608
 
609
                #
610
                #   Create a matchlist from the AAR list
611
                #   Create a regular expresssion to find a suitable file
612
                #
613
                my @mlist;
614
                foreach  ( @alist) {
615
                    push @mlist, $_ . '.aar|' . $_ . '-debug.aar|' . $_ . '-release.aar';
616
                }
617
 
618
                CopyDir ( $aarDir, $androidJars,
619
                            'MatchRE' => \@mlist,
620
                            'Log' => $opt_verbose + 1,
621
                            'SymlinkFiles' => 1,
622
                            'Examine' => sub 
623
                                {
624
                                    my ($opt) = @_;
625
                                    my $baseName = $opt->{file};
626
                                    $baseName =~ s~\.aar$~~;
627
                                    $baseName =~ s~-release$~~;
628
                                    $baseName =~ s~-debug$~~;
629
                                    ArrayDelete \@alist, $baseName;
630
                                    return 1;
631
                                },
632
                            );
633
            }
634
        }
635
 
636
 
637
        #
638
        #   Copy in AAR files specified by a full pathname
639
        #   Need to allow for both AAR files with a -debug/-release suffix 
640
        #   as well as those without
641
        #
642
        my @apathlistBase = @apathlist;
643
        foreach my $file (@apathlistBase) 
644
        {
645
            foreach my $suffix ( '', '-release', '-debug')
646
            {
647
                my $aarFile = catdir($pkg, $file . $suffix . '.aar');
4990 dpurdie 648
                push @aarSearch, $aarFile;
4937 dpurdie 649
                if (-f $aarFile)
650
                {
651
                    Verbose("Aar File Found found", $aarFile);
652
                    Message ("Copy in: $aarFile");
653
                    CopyFile ( $aarFile, $androidJars,
654
                                'Log' => $opt_verbose + 1,
655
                                'SymlinkFiles' => 1,
656
                             );
657
                    ArrayDelete \@apathlist, $file;
658
                }
659
            }
660
        }
661
 
662
        #
663
        #   Build up the Shared Library structure as used by JNI
664
        #   Note: Only support current JATS format
665
        #   Copy in .so files and in to process massage the pathname so that
666
        #   it confirms to that expected by the Android Project
667
        #
668
        my $libDir = catdir($pkg, 'lib');
4990 dpurdie 669
        push @libSearch, $libDir;
4937 dpurdie 670
        if (-d $libDir && @libListProd)
671
        {
672
            Verbose("Lib Dir Found found", $libDir);
673
            Message ("Copy in: $libDir");
674
            CopyDir ( $libDir, $androidJniProd,
675
                        'Match' => \@libListProd,
676
                        'Log' => $opt_verbose + 1,
677
                        'SymlinkFiles' => 1,
678
                        'Examine' => sub 
679
                            { 
680
                                my ($opt) = @_;
681
                                foreach my $platform ( keys %SharedLibMap ) {
682
                                    my $replace = $SharedLibMap{$platform};
683
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
684
                                    {
685
                                        ArrayDelete \@libListProd, $opt->{file};
686
                                        return 1;
687
                                    }
688
                                }
689
                                return 0;
690
                            },
691
                    );
692
        }
693
 
694
        if (-d $libDir && @libListDebug)
695
        {
696
            Verbose("Lib Dir Found found", $libDir);
697
            Message ("Copy in: $libDir");
698
            CopyDir ( $libDir, $androidJniDebug,
699
                        'Match' => \@libListDebug,
700
                        'Log' => $opt_verbose + 1,
701
                        'SymlinkFiles' => 1,
702
                        'Examine' => sub 
703
                            { 
704
                                my ($opt) = @_;
705
                                foreach my $platform ( keys %SharedLibMap ) {
706
                                    my $replace = $SharedLibMap{$platform};
707
                                    if ($opt->{'target'} =~ s~/$platform/~/$replace/~)
708
                                    {
709
                                        ArrayDelete \@libListDebug, $opt->{file};
710
                                        return 1;
711
                                    }
712
                                }
713
                                return 0;
714
                            },
715
                    );
716
        }
717
 
718
    }
719
 
720
    #
721
    #   Report files that could not be located. They were deleted from the lists
722
    #   as they were processed
723
    #
4990 dpurdie 724
    if (@jlist || @jpathlist || @alist || @apathlist ||  @libListProd || @libListDebug )
4937 dpurdie 725
    {
4990 dpurdie 726
        ReportError("External dependencies not found:", @jlist , @jpathlist , @alist , @apathlist ,  @libListProd , @libListDebug);
727
        if (@jlist || @jpathlist)
728
        {
729
            ReportError("Jar Search Path", @jarSearch);
730
        }
731
 
732
        if (@alist || @apathlist)
733
        {
734
            ReportError("Aar Search Path", @aarSearch);
735
        }
736
 
737
        if ( @libListProd || @libListDebug)
738
        {
739
            ReportError("Lib Search Path", @libSearch);
740
        }
741
    ErrorDoExit();
4937 dpurdie 742
    }
743
}
744
 
745
#-------------------------------------------------------------------------------
746
# Function        : deleteGeneratedFiles 
747
#
748
# Description     : Delete files that we generate
749
#
750
# Inputs          : 
751
#
752
# Returns         : 
753
#
754
sub deleteGeneratedFiles
755
{
756
    #
757
    #   Delete files that we will create
758
    #
759
    my @deleteList = qw(local.properties gradle.properties);
760
    foreach my $file (@deleteList)
761
    {
762
        Verbose ("Deleting $project_root/$file");
763
        unlink catfile($project_root, $file);
764
    }
765
 
766
}
767
 
768
#-------------------------------------------------------------------------------
769
# Function        : deleteInjectedFiles 
770
#
771
# Description     : Delete files that we inject
772
#
773
# Inputs          : 
774
#
775
# Returns         : 
776
#
777
sub deleteInjectedFiles
778
{
779
    #
780
    #   Remove the jatsJars and JatsJni directories
781
    #   These are created by this tool
782
    #
783
    Verbose("RmDirTree($androidJars)");
784
    RmDirTree($androidJars);
785
 
786
    Verbose("RmDirTree($androidJniBase)");
787
    RmDirTree($androidJniBase);
788
}
789
 
790
 
791
#-------------------------------------------------------------------------------
792
# Function        : NicePath 
793
#
794
# Description     : Process a path and return one that is
795
#                       An absolute Path
796
#                       Uses '/'
797
#
798
# Inputs          : path            - Path to process
799
#
800
# Returns         : A Nice version of path
801
#
802
sub NicePath
803
{
804
    my ($path) = @_;
805
    $path = FullPath($path);
806
    $path =~ s~\\~/~g;
807
    $path = CleanPath($path);
808
    return $path;
809
}
810