From 6afc5faab042d4536bda6bf6491b75c626714593 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Wed, 23 Mar 2011 12:18:11 -0400 Subject: [PATCH] Moved some useful functions to common.jake and made some private functions global so they can be reused by our Jakefiles --- Jakefile | 63 +++---------------------------------- common.jake | 90 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 68 deletions(-) diff --git a/Jakefile b/Jakefile index a4812b8d5..2e53e6257 100644 --- a/Jakefile +++ b/Jakefile @@ -59,8 +59,7 @@ task ("sudo-install", ["CommonJS"], function() if (OS.system(["sudo", "tusk", "install", "--force", $BUILD_CJS_OBJECTIVE_J, $BUILD_CJS_CAPPUCCINO])) { // Attempt a hackish work-around for sudo compiled with the --with-secure-path option - if (OS.system("sudo bash -c 'source " + getShellConfigFile() + "; tusk install --force " + $BUILD_CJS_OBJECTIVE_J + " " + $BUILD_CJS_CAPPUCCINO + "'")) - OS.exit(1); //rake abort if ($? != 0) + sudo("tusk install --force " + $BUILD_CJS_OBJECTIVE_J + " " + $BUILD_CJS_CAPPUCCINO) } }); @@ -70,50 +69,12 @@ task ("install-symlinks", function() installSymlink($BUILD_CJS_CAPPUCCINO); }); -task ("sudo-install-symlinks", function() +task ("install-debug-symlinks", function() { - if (OS.system("sudo bash -c 'source " + getShellConfigFile() + "; jake install-symlinks'")) - OS.exit(1); //rake abort if ($? != 0) + SYSTEM.env["CONFIG"] = "Debug"; + spawnJake("install-symlinks"); }); -function installSymlink(sourcePath) -{ - if (!FILE.isDirectory(sourcePath)) - return; - - var packageName = FILE.basename(sourcePath), - targetPath = FILE.join(SYSTEM.prefix, "packages", packageName); - - if (FILE.isDirectory(targetPath)) - FILE.rmtree(targetPath); - else if (FILE.linkExists(targetPath)) - FILE.remove(targetPath); - - stream.print("Symlinking \0cyan(" + targetPath + "\0) ==> \0cyan(" + sourcePath + "\0)"); - FILE.symlink(sourcePath, targetPath); - - var binPath = FILE.Path(FILE.join(targetPath, "bin")); - - if (binPath.isDirectory()) - { - var narwhalBin = FILE.Path(FILE.join(SYSTEM.prefix, "bin")); - - binPath.list().forEach(function (name) - { - var binary = binPath.join(name); - binary.chmod(0755); - - var target = narwhalBin.join(name), - relative = FILE.relative(target, binary); - - if (target.linkExists()) - target.remove(); - - FILE.symlink(relative, target); - }); - } -} - // Documentation $DOCUMENTATION_BUILD = FILE.join($BUILD_DIR, "Documentation"); @@ -387,19 +348,3 @@ function buildCmd(arrayOfCommands) return cmd.map(OS.enquote).join(" "); }).join(" && "); } - -function getShellConfigFile() -{ - var homeDir = SYSTEM.env["HOME"] + "/"; - // use order outlined by http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup - var possibilities = [homeDir + ".bash_profile", - homeDir + ".bash_login", - homeDir + ".profile", - homeDir + ".bashrc"]; - - for (var i = 0; i < possibilities.length; i++) - { - if (FILE.exists(possibilities[i])) - return possibilities[i]; - } -} diff --git a/common.jake b/common.jake index 19f58d1c5..c00ed9377 100644 --- a/common.jake +++ b/common.jake @@ -14,7 +14,7 @@ SYSTEM.args.slice(1).forEach(function(arg){ function ensurePackageUpToDate(packageName, requiredVersion, options) { options = options || {}; - + var packageInfo = require("narwhal/packages").catalog[packageName]; if (!packageInfo) { @@ -28,7 +28,7 @@ function ensurePackageUpToDate(packageName, requiredVersion, options) var version = packageInfo.version; if (typeof version === "string") version = version.split("."); - + if (typeof requiredVersion === "string") requiredVersion = requiredVersion.split("."); @@ -152,21 +152,21 @@ function additionalPackages() { var builtObjectiveJPackage = FILE.path($BUILD_CONFIGURATION_DIR).join("CommonJS", "objective-j", ""); var builtCappuccinoPackage = FILE.path($BUILD_CONFIGURATION_DIR).join("CommonJS", "cappuccino", ""); - + var packages = []; - + // load built objective-j if exists, otherwise unbuilt if (builtObjectiveJPackage.join("package.json").exists()) { if (!packageInCatalog(builtObjectiveJPackage)) packages.push(builtObjectiveJPackage); } - + // load built cappuccino if it exists if (builtCappuccinoPackage.join("package.json").exists()) { if (!packageInCatalog(builtCappuccinoPackage)) packages.push(builtCappuccinoPackage); } - + return packages; } @@ -183,7 +183,7 @@ function packageInCatalog(path) serializedENV = function() { var envNew = {}; - + // add changed keys to the new ENV Object.keys(SYSTEM.env).forEach(function(key) { if (SYSTEM.env[key] !== envInitial[key]) @@ -202,6 +202,22 @@ serializedENV = function() }).join(" "); } +function getShellConfigFile() +{ + var homeDir = SYSTEM.env["HOME"] + "/"; + // use order outlined by http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup + var possibilities = [homeDir + ".bash_profile", + homeDir + ".bash_login", + homeDir + ".profile", + homeDir + ".bashrc"]; + + for (var i = 0; i < possibilities.length; i++) + { + if (FILE.exists(possibilities[i])) + return possibilities[i]; + } +} + function reforkWithPackages() { if (additionalPackages().length > 0) { @@ -251,7 +267,7 @@ global.cp_r = function(/*String*/ from, /*String*/ to) global.cp = function(/*String*/ from, /*String*/ to) { FILE.copy(from, to); -// FILE.chmod(to, FILE.mod(from)); +// FILE.chmod(to, FILE.mod(from)); } global.mv = function(/*String*/ from, /*String*/ to) @@ -344,12 +360,58 @@ global.subtasks = function(subprojects, taskNames) }); } -function spawnJake(/*String*/ aTaskName) +global.installSymlink = function(sourcePath) +{ + if (!FILE.isDirectory(sourcePath)) + return; + + var packageName = FILE.basename(sourcePath), + targetPath = FILE.join(SYSTEM.prefix, "packages", packageName); + + if (FILE.isDirectory(targetPath)) + FILE.rmtree(targetPath); + else if (FILE.linkExists(targetPath)) + FILE.remove(targetPath); + + stream.print("Symlinking \0cyan(" + targetPath + "\0) ==> \0cyan(" + sourcePath + "\0)"); + FILE.symlink(sourcePath, targetPath); + + var binPath = FILE.Path(FILE.join(targetPath, "bin")); + + if (binPath.isDirectory()) + { + var narwhalBin = FILE.Path(FILE.join(SYSTEM.prefix, "bin")); + + binPath.list().forEach(function (name) + { + var binary = binPath.join(name); + binary.chmod(0755); + + var target = narwhalBin.join(name), + relative = FILE.relative(target, binary); + + if (target.linkExists()) + target.remove(); + + FILE.symlink(relative, target); + }); + } +} + +global.spawnJake = function(/*String*/ aTaskName) { if (OS.system(serializedENV() + " " + SYSTEM.args[0] + " " + aTaskName)) OS.exit(1);//rake abort if ($? != 0) } +global.sudo = function(/*String*/ aTaskName) +{ + var cmd = "sudo bash -c 'source " + getShellConfigFile() + "; " + aTaskName + "'"; + + if (OS.system(cmd)) + OS.exit(1); //rake abort if ($? != 0) +} + // built in tasks task ("build"); @@ -369,6 +431,16 @@ task ("debug", function() task ("all", ["debug", "release"]); +task ("sudo-install-symlinks", function() +{ + sudo("jake install-symlinks"); +}); + +task ("sudo-install-debug-symlinks", function() +{ + sudo("jake install-debug-symlinks") +}); + task ("clean-debug", function() { SYSTEM.env['CONFIG'] = 'Debug'