cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [04/11] git commit: bin/build: switch to async shelljs.exec
Date Mon, 05 May 2014 23:43:10 GMT
bin/build: switch to async shelljs.exec


Project: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/commit/e4d45807
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/tree/e4d45807
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/diff/e4d45807

Branch: refs/heads/master
Commit: e4d45807644f8f0a453b112ae674727b24b1f4e0
Parents: 9d3f614
Author: Maxim Ermilov <maxim.ermilov@canonical.com>
Authored: Mon Apr 14 15:04:35 2014 +0400
Committer: Maxim Ermilov <maxim.ermilov@canonical.com>
Committed: Wed Apr 16 14:28:08 2014 +0400

----------------------------------------------------------------------
 bin/build/lib/ubuntu.js | 160 ++++++++++++++++++++++++++-----------------
 bin/create              |   1 +
 bin/package.json        |   1 +
 3 files changed, 100 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/e4d45807/bin/build/lib/ubuntu.js
----------------------------------------------------------------------
diff --git a/bin/build/lib/ubuntu.js b/bin/build/lib/ubuntu.js
index 35ff185..4285a21 100644
--- a/bin/build/lib/ubuntu.js
+++ b/bin/build/lib/ubuntu.js
@@ -25,6 +25,7 @@ var fs = require('fs');
 var msg = require('./msg');
 var assert = require('assert');
 var colors = require('colors');
+var Q = require("q");
 
 function exec(cmd) {
     console.log(cmd.green);
@@ -38,6 +39,24 @@ function exec(cmd) {
     return res;
 }
 
+function execAsync(cmd) {
+    var deferred = Q.defer();
+
+    console.log(cmd.green);
+
+    shell.exec(cmd, { async: true }, function (code, output) {
+        var res = { code: code, output: output };
+        if (res.code !== 0) {
+            console.error(cmd.green + " " + "FAILED".underline.red);
+            process.exit(1);
+        }
+        deferred.resolve(res);
+    });
+
+    return deferred.promise;
+}
+
+
 function cp(source, dest) {
     console.log(('cp -Rf ' + source + ' ' + dest).green);
 
@@ -73,27 +92,32 @@ function buildArmPackage(campoDir, ubuntuDir, nobuild) {
 
     pushd(path.join(armhfDir, 'build'));
 
-    exec('click chroot -aarmhf -s trusty run cmake ' + campoDir + ' -DCMAKE_TOOLCHAIN_FILE=/etc/dpkg-cross/cmake/CMakeCross.txt
-DCMAKE_INSTALL_PREFIX="' + prefixDir + '"');
-    exec('find . -name AutomocInfo.cmake | xargs sed -i \'s;AM_QT_MOC_EXECUTABLE .*;AM_QT_MOC_EXECUTABLE
"/usr/lib/\'$(dpkg-architecture -qDEB_BUILD_MULTIARCH)\'/qt5/bin/moc");\'');
-    exec('click chroot -aarmhf -s trusty run make -j 6');
-    exec('click chroot -aarmhf -s trusty run make install');
-    cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www'));
-    cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml'));
-    cp(path.join(ubuntuDir, 'apparmor.json'), prefixDir);
-    cp(path.join(ubuntuDir, 'cordova.desktop'), prefixDir);
-    cp(path.join(ubuntuDir, 'config.xml'), prefixDir);
-
-    var content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding:
"utf8"}));
-    content.architecture = "armhf";
-    fs.writeFileSync(path.join(prefixDir, 'manifest.json'), JSON.stringify(content));
-
-    pushd(prefixDir);
-
-    exec('click build .');
-
-    popd();
-
-    popd();
+    return execAsync('click chroot -aarmhf -s trusty run cmake ' + campoDir
+              + ' -DCMAKE_TOOLCHAIN_FILE=/etc/dpkg-cross/cmake/CMakeCross.txt -DCMAKE_INSTALL_PREFIX="'
+              + prefixDir + '"').then(function () {
+        exec('find . -name AutomocInfo.cmake | xargs sed -i \'s;AM_QT_MOC_EXECUTABLE .*;AM_QT_MOC_EXECUTABLE
"/usr/lib/\'$(dpkg-architecture -qDEB_BUILD_MULTIARCH)\'/qt5/bin/moc");\'');
+        return execAsync('click chroot -aarmhf -s trusty run make -j 6');
+    }).then(function () {
+        return execAsync('click chroot -aarmhf -s trusty run make install');
+    }).then(function () {
+        cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www'));
+        cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml'));
+        cp(path.join(ubuntuDir, 'apparmor.json'), prefixDir);
+        cp(path.join(ubuntuDir, 'cordova.desktop'), prefixDir);
+        cp(path.join(ubuntuDir, 'config.xml'), prefixDir);
+
+        var content = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding:
"utf8"}));
+        content.architecture = "armhf";
+        fs.writeFileSync(path.join(prefixDir, 'manifest.json'), JSON.stringify(content));
+
+        pushd(prefixDir);
+
+        return execAsync('click build .');
+    }).then(function () {
+        popd();
+
+        popd();
+    });
 }
 
 function buildNative(campoDir, ubuntuDir, nobuild) {
@@ -112,38 +136,40 @@ function buildNative(campoDir, ubuntuDir, nobuild) {
 
     pushd(path.join(nativeDir, 'build'));
 
-    exec('cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"');
-    exec('make -j 6; make install');
+    return execAsync('cmake ' + campoDir + ' -DCMAKE_INSTALL_PREFIX="' + prefixDir + '"').then(function
() {
+        return execAsync('make -j 6; make install');
+    }).then(function () {
+        cp(path.join(ubuntuDir, 'config.xml'), prefixDir);
+        cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www'));
+        cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml'));
 
-    cp(path.join(ubuntuDir, 'config.xml'), prefixDir);
-    cp(path.join(ubuntuDir, 'www', '*'), path.join(prefixDir, 'www'));
-    cp(path.join(ubuntuDir, 'qml', '*'), path.join(prefixDir, 'qml'));
+        popd();
 
-    popd();
+        var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'),
{encoding: "utf8"}));
 
-    var manifest = JSON.parse(fs.readFileSync(path.join(ubuntuDir, 'manifest.json'), {encoding:
"utf8"}));
-
-    assert(manifest.name.length);
-    assert(manifest.name.indexOf(' ') == -1);
+        assert(manifest.name.length);
+        assert(manifest.name.indexOf(' ') == -1);
 
-    var debDir = path.join(nativeDir, manifest.name);
+        var debDir = path.join(nativeDir, manifest.name);
 
-    shell.rm('-rf', debDir);
-    shell.mkdir('-p', path.join(debDir, 'opt', manifest.name));
-    cp(path.join(prefixDir, '*'), path.join(debDir, 'opt', manifest.name));
+        shell.rm('-rf', debDir);
+        shell.mkdir('-p', path.join(debDir, 'opt', manifest.name));
+        cp(path.join(prefixDir, '*'), path.join(debDir, 'opt', manifest.name));
 
-    var destDir = path.join('/opt', manifest.name);
-    shell.mkdir('-p', path.join(debDir, 'usr', 'share', 'applications'));
-    shell.mkdir('-p', path.join(debDir, 'DEBIAN'));
-    fs.writeFileSync(path.join(debDir, 'DEBIAN', 'control'), 'Package: ' + manifest.name
+ '\nVersion: ' + manifest.version + '\nMaintainer: ' + manifest.maintainer + '\nArchitecture:
' + manifest.architecture + '\nDescription: ' + manifest.description + '\n')
-    fs.writeFileSync(path.join(debDir, 'usr', 'share', 'applications', manifest.name + '.desktop'),
'[Desktop Entry]\nName=' + manifest.title + '\nExec=' + path.join(destDir, 'cordova-ubuntu')
+ ' ' + path.join(destDir, 'www') + '\nIcon=qmlscene\nTerminal=false\nType=Application\nX-Ubuntu-Touch=true\n');
+        var destDir = path.join('/opt', manifest.name);
+        shell.mkdir('-p', path.join(debDir, 'usr', 'share', 'applications'));
+        shell.mkdir('-p', path.join(debDir, 'DEBIAN'));
+        fs.writeFileSync(path.join(debDir, 'DEBIAN', 'control'), 'Package: ' + manifest.name
+ '\nVersion: ' + manifest.version + '\nMaintainer: ' + manifest.maintainer + '\nArchitecture:
' + manifest.architecture + '\nDescription: ' + manifest.description + '\n')
+        fs.writeFileSync(path.join(debDir, 'usr', 'share', 'applications', manifest.name
+ '.desktop'), '[Desktop Entry]\nName=' + manifest.title + '\nExec=' + path.join(destDir,
'cordova-ubuntu') + ' ' + path.join(destDir, 'www') + '\nIcon=qmlscene\nTerminal=false\nType=Application\nX-Ubuntu-Touch=true\n');
 
-    pushd(nativeDir);
+        pushd(nativeDir);
 
-    exec('dpkg-deb -b "' + manifest.name + '" .');
-    shell.rm('-rf', debDir);
+        return execAsync('dpkg-deb -b "' + manifest.name + '" .');
+    }).then(function () {
+        shell.rm('-rf', debDir);
 
-    popd();
+        popd();
+    });
 }
 
 module.exports.ALL = 2;
@@ -157,10 +183,15 @@ module.exports.build = function(rootDir, target, nobuild) {
     assert.ok(fs.existsSync(ubuntuDir));
     assert.ok(fs.existsSync(campoDir));
 
-    if (target === module.exports.PHONE || target === module.exports.ALL)
-        buildArmPackage(campoDir, ubuntuDir, nobuild);
-    if (target === module.exports.DESKTOP || target === module.exports.ALL)
-        buildNative(campoDir, ubuntuDir, nobuild);
+    if (target === module.exports.PHONE)
+        return buildArmPackage(campoDir, ubuntuDir, nobuild);
+    if (target === module.exports.DESKTOP)
+        return buildNative(campoDir, ubuntuDir, nobuild);
+    if (target === module.exports.ALL) {
+        return buildArmPackage(campoDir, ubuntuDir, nobuild).then(function () {
+            return buildNative(campoDir, ubuntuDir, nobuild);
+        });
+    }
 }
 
 function runNative(rootDir, debug) {
@@ -169,14 +200,12 @@ function runNative(rootDir, debug) {
 
     pushd(path.join(nativeDir, 'prefix'));
 
-    if (debug) {
+    if (debug)
         console.error('Debug enabled. Try pointing a WebKit browser to http://127.0.0.1:9222');
-        exec('QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/');
-    } else {
-        exec('./cordova-ubuntu www/');
-    }
 
-    popd();
+    return execAsync('QTWEBKIT_INSPECTOR_SERVER=9222 ./cordova-ubuntu www/').then(function
() {
+        popd();
+    });
 }
 
 function deviceList() {
@@ -199,6 +228,11 @@ function adbExec(target, command) {
     return exec('adb -s ' + target + ' ' + command);
 }
 
+function adbExecAsync(target, command) {
+    assert.ok(target && command);
+    return execAsync('adb -s ' + target + ' ' + command);
+}
+
 function isDeviceAttached(target) {
     var res = adbExec(target, 'get-state');
 
@@ -248,17 +282,18 @@ function runOnDevice(rootDir, debug, target) {
         adbExec(target, 'forward tcp:9222 tcp:9222');
     }
 
-    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);
+
+    return adbExecAsync(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\'"').then(function () {
+        popd();
+    });
 }
 
 module.exports.run = function(rootDir, desktop, debug, target, nobuild) {
     if (desktop) {
-        module.exports.build(rootDir, module.exports.DESKTOP, nobuild);
-        runNative(rootDir, debug);
+        return module.exports.build(rootDir, module.exports.DESKTOP, nobuild).then(function
() {
+            return runNative(rootDir, debug);
+        });
     } else {
         if (!target) {
             var devices = deviceList();
@@ -276,7 +311,8 @@ module.exports.run = function(rootDir, desktop, debug, target, nobuild)
{
             }
         }
 
-        module.exports.build(rootDir, module.exports.PHONE, nobuild);
-        runOnDevice(rootDir, debug, target);
+        return module.exports.build(rootDir, module.exports.PHONE, nobuild).then(function
() {
+             return runOnDevice(rootDir, debug, target);
+        });
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/e4d45807/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 3399672..2d83bef 100755
--- a/bin/create
+++ b/bin/create
@@ -57,6 +57,7 @@ function create(project_path, package_name, project_name, project_template_dir)
         require.resolve("elementtree");
         require.resolve("colors");
         require.resolve("optimist");
+        require.resolve("q");
         create_project();
     } catch(e) {
         console.log('Shelljs module was not found, running \'npm install\'.....');

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/e4d45807/bin/package.json
----------------------------------------------------------------------
diff --git a/bin/package.json b/bin/package.json
index c3991fc..bb2dc7a 100644
--- a/bin/package.json
+++ b/bin/package.json
@@ -18,6 +18,7 @@
         "node": ">=0.10.0"
     },
     "dependencies": {
+        "q": "2.0.*",
         "shelljs": "0.2.6",
         "elementtree": "*",
         "colors": "0.6.2",


Mime
View raw message