You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/01/31 00:25:29 UTC
[05/13] git commit: bin/build/run: --target option
bin/build/run: --target option
Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/c948125f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/c948125f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/c948125f
Branch: refs/heads/master
Commit: c948125f296847f30d4ee66b3e112a8517420a45
Parents: 537927d
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Mon Dec 23 19:22:14 2013 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Mon Dec 23 19:22:14 2013 +0400
----------------------------------------------------------------------
bin/build/lib/msg.js | 24 ++++++++++++++++
bin/build/lib/ubuntu.js | 65 ++++++++++++++++++++++++++++++++++----------
bin/build/run | 4 +--
3 files changed, 77 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/c948125f/bin/build/lib/msg.js
----------------------------------------------------------------------
diff --git a/bin/build/lib/msg.js b/bin/build/lib/msg.js
new file mode 100644
index 0000000..d45eb61
--- /dev/null
+++ b/bin/build/lib/msg.js
@@ -0,0 +1,24 @@
+#!/usr/bin/env node
+
+/*
+ *
+ * Copyright 2013 Canonical Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+module.exports = {
+ UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE: 'UbuntuTouch device is not attached'
+};
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/c948125f/bin/build/lib/ubuntu.js
----------------------------------------------------------------------
diff --git a/bin/build/lib/ubuntu.js b/bin/build/lib/ubuntu.js
index 6338388..476ed53 100644
--- a/bin/build/lib/ubuntu.js
+++ b/bin/build/lib/ubuntu.js
@@ -22,6 +22,7 @@
var shell = require('shelljs');
var path = require('path');
var fs = require('fs');
+var msg = require('./msg');
var assert = require('assert');
var colors = require('colors');
@@ -146,24 +147,44 @@ function runNative(rootDir, debug) {
popd();
}
-function isDeviceAttached() {
- var res = exec('adb get-state');
+function deviceList() {
+ var res = exec('adb devices');
+
+ var response = res.output.split('\n');
+ var deviceList = [];
+
+ for (var i = 1; i < response.length; i++) {
+ if (response[i].match(/\w+\tdevice/)) {
+ deviceList.push(response[i].replace(/\tdevice/, '').replace('\r', ''));
+ }
+ }
+
+ return deviceList;
+}
+
+function adbExec(target, command) {
+ assert.ok(target && command);
+ return exec('adb -s ' + target + ' ' + command);
+}
+
+function isDeviceAttached(target) {
+ var res = adbExec(target, 'get-state');
if (res.output.indexOf('device') == -1)
return false;
- res = exec('adb shell uname -a');
+ res = adbExec(target, 'shell uname -a');
if (res.output.indexOf('ubuntu-phablet') == -1)
return false;
return true;
}
-function runOnDevice(rootDir, debug) {
+function runOnDevice(rootDir, debug, target) {
var ubuntuDir = path.join(rootDir, 'platforms', 'ubuntu');
- if (!isDeviceAttached()) {
- console.error('UbuntuTouch device is not attached'.red)
+ if (!isDeviceAttached(target)) {
+ console.error(msg.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red)
process.exit(1);
}
@@ -181,33 +202,49 @@ function runOnDevice(rootDir, debug) {
assert.ok(names.length == 1);
- exec('adb shell "ps -A -eo pid,cmd | grep cordova-ubuntu | awk \'{ print \\$1 }\' | xargs kill -9"')
+ adbExec(target, 'shell "ps -A -eo pid,cmd | grep cordova-ubuntu | awk \'{ print \\$1 }\' | xargs kill -9"')
if (debug)
- exec('adb forward --remove-all');
+ adbExec(target, 'forward --remove-all');
- exec('adb push ' + names[0] + ' /home/phablet');
- exec('adb shell "cd /home/phablet/; click install ' + names[0] + ' --user=phablet"');
+ adbExec(target, 'push ' + names[0] + ' /home/phablet');
+ adbExec(target, 'shell "cd /home/phablet/; click install ' + names[0] + ' --user=phablet"');
if (debug) {
console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
- exec('adb forward tcp:9222 tcp:9222');
+ adbExec(target, 'forward tcp:9222 tcp:9222');
}
- exec('adb shell "su - phablet -c \'cd /opt/click.ubuntu.com/' + appId + '/current; QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/ --desktop_file_hint=/opt/click.ubuntu.com/' + appId + '/current/cordova.desktop\'"');
+ adbExec(target, 'shell "su - phablet -c \'cd /opt/click.ubuntu.com/' + appId + '/current; QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/ --desktop_file_hint=/opt/click.ubuntu.com/' + appId + '/current/cordova.desktop\'"');
popd();
console.log('have fun!'.rainbow);
}
-module.exports.run = function(rootDir, desktop, debug) {
+module.exports.run = function(rootDir, desktop, debug, target) {
if (desktop) {
module.exports.build(rootDir, module.exports.DESKTOP);
runNative(rootDir, debug);
} else {
+ if (!target) {
+ var devices = deviceList();
+
+ if (!devices.length) {
+ console.error(msg.UBUNTU_TOUCH_DEVICE_NOT_AVALIABLE.red)
+ process.exit(1);
+ }
+
+ target = devices[0];
+
+ if (devices.length > 1) {
+ console.warn('you can specify target with --target <device id>'.yellow);
+ console.warn(('running on ' + target).yellow);
+ }
+ }
+
module.exports.build(rootDir, module.exports.PHONE);
- runOnDevice(rootDir, debug);
+ runOnDevice(rootDir, debug, target);
}
}
http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/c948125f/bin/build/run
----------------------------------------------------------------------
diff --git a/bin/build/run b/bin/build/run
index 09a91e5..2b6e549 100755
--- a/bin/build/run
+++ b/bin/build/run
@@ -24,7 +24,7 @@ var platform = require('./lib/ubuntu');
var root = path.resolve();
var www = path.join(root, 'www');
-var argv = require('optimist').boolean(['device', 'debug']).argv;
+var argv = require('optimist').boolean(['device', 'debug']).string(['target']).argv;
-platform.run(root, !argv.device, argv.debug);
+platform.run(root, !argv.device, argv.debug, argv.target);