Skip to content

Commit

Permalink
CB-12546: more specs for android_sdk and check_reqs. added fixtures f…
Browse files Browse the repository at this point in the history
…or sdk targets. refactored target listing.
  • Loading branch information
filmaj committed Mar 20, 2017
1 parent f7687a2 commit 3554267
Show file tree
Hide file tree
Showing 6 changed files with 1,453 additions and 32 deletions.
77 changes: 47 additions & 30 deletions bin/templates/cordova/lib/android_sdk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node


/*
Licensed to the Apache Software Foundation (ASF) under one
Expand Down Expand Up @@ -44,51 +44,68 @@ module.exports.version_string_to_api_level = {
'7.1.1': 25
};

module.exports.list_targets = function() {
module.exports.list_targets_with_android = function() {
return superspawn.spawn('android', ['list', 'targets'])
.then(function(stdout) {
var target_out = stdout.split('\n');
var targets = [];
for (var i = target_out.length; i >= 0; i--) {
for (var i = target_out.length - 1; i >= 0; i--) {
if(target_out[i].match(/id:/)) {
targets.push(targets[i].split(' ')[1]);
targets.push(target_out[i].match(/"(.+)"/)[1]);
}
}
return targets;
});
};

module.exports.list_targets_with_sdkmanager = function() {
return superspawn.spawn('sdkmanager', ['--list'])
.then(function(stdout) {
var parsing_installed_packages = false;
var lines = stdout.split('\n');
var targets = [];
for (var i = 0, l = lines.length; i < l; i++) {
var line = lines[i];
if (line.match(/Installed packages/)) {
parsing_installed_packages = true;
} else if (line.match(/Available Packages/) || line.match(/Available Updates/)) {
// we are done working through installed packages, exit
break;
}
if (parsing_installed_packages) {
// Match stock android platform
if (line.match(/platforms;android-\d+/)) {
targets.push(line.match(/(android-\d+)/)[1]);
}
// Match Google APIs
if (line.match(/addon-google_apis-google-\d+/)) {
var description = lines[i + 1];
// munge description to match output from old android sdk tooling
var api_level = description.match(/Android (\d+)/); //[1];
if (api_level) {
targets.push('Google Inc.:Google APIs:' + api_level[1]);
}
}
// TODO: match anything else?
}
}
return targets;
}).catch(function(err) {
});
};

module.exports.list_targets = function() {
return module.exports.list_targets_with_android()
.catch(function(err) {
// there's a chance `android` no longer works.
// lets see if `sdkmanager` is available and we can figure it out
var avail_regex = /android command is no longer available/;
if (err.code && (err.stdout.match(avail_regex) || err.stderr.match(avail_regex))) {
return superspawn.spawn('sdkmanager', ['--list'])
.then(function(stdout) {
var parsing_installed_packages = false;
var lines = stdout.split('\n');
var targets = [];
for (var i = 0, l = lines.length; i < l; i++) {
var line = lines[i];
if (line.match(/Installed packages/)) {
parsing_installed_packages = true;
} else if (line.match(/Available Packages/) || line.match(/Available Updates/)) {
// we are done working through installed packages, exit
break;
}
if (parsing_installed_packages && line.match(/platforms;android-\d+/)) {
targets.push(line.match(/android-\d+/)[0].split('-')[1]);
}
}
return targets;
});
return module.exports.list_targets_with_sdkmanager();
} else throw err;
}).then(function(targets) {
if (targets.length === 0) {
return Q.reject(new Error('No android targets (SDKs) installed!'));
} else {
// Ensure we are working with integers
targets = targets.map(function(t) { return parseInt(t); });
// Sort them in descending order.
targets.sort(function(a, b) { return b-a; });
return targets;
}
return targets;
});
};
3 changes: 1 addition & 2 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ module.exports.check_android_target = function(originalError) {
// android-L
// Google Inc.:Google APIs:20
// Google Inc.:Glass Development Kit Preview:20
var desired_api_level = parseInt(module.exports.get_target().replace(/android-/, ''));
// Changing "targets" to "target" is stupid and makes more code. Thanks Google!
var desired_api_level = module.exports.get_target();
return android_sdk.list_targets()
.then(function(targets) {
if (targets.indexOf(desired_api_level) >= 0) {
Expand Down
116 changes: 116 additions & 0 deletions spec/fixtures/android_list_targets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Available Android targets:
----------
id: 1 or "android-20"
Name: Android 4.4W.2
Type: Platform
API level: 20
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : no ABIs.
----------
id: 2 or "android-21"
Name: Android 5.0.1
Type: Platform
API level: 21
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86, default/armeabi-v7a, default/x86, default/x86_64
----------
id: 3 or "android-22"
Name: Android 5.1.1
Type: Platform
API level: 22
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86, default/armeabi-v7a, default/x86, default/x86_64
----------
id: 4 or "android-MNC"
Name: Android M (Preview)
Type: Platform
API level: MNC
Revision: 1
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : no ABIs.
----------
id: 5 or "android-23"
Name: Android 6.0
Type: Platform
API level: 23
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86, default/x86, default/x86_64
----------
id: 6 or "android-N"
Name: Android N (Preview)
Type: Platform
API level: N
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : no ABIs.
----------
id: 7 or "android-24"
Name: Android 7.0
Type: Platform
API level: 24
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : android-tv/x86, default/x86, default/x86_64
----------
id: 8 or "android-25"
Name: Android 7.1.1
Type: Platform
API level: 25
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : android-tv/x86, google_apis/x86, google_apis/x86_64
----------
id: 9 or "Google Inc.:Google APIs:21"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 5.0.1 (API level 21)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : google_apis/armeabi-v7a, google_apis/x86, google_apis/x86_64
----------
id: 10 or "Google Inc.:Google APIs:22"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 5.1.1 (API level 22)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : google_apis/armeabi-v7a, google_apis/x86, google_apis/x86_64
----------
id: 11 or "Google Inc.:Google APIs:23"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 6.0 (API level 23)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : google_apis/armeabi-v7a, google_apis/x86, google_apis/x86_64
Loading

0 comments on commit 3554267

Please sign in to comment.