diff --git a/CommonJS/Jakefile b/CommonJS/Jakefile index 3bb461275..925054ece 100644 --- a/CommonJS/Jakefile +++ b/CommonJS/Jakefile @@ -8,7 +8,7 @@ new FileList("**/*").exclude("Jakefile").forEach(function(aFilename) if (!FILE.isFile(aFilename)) return; - var buildFilename = FILE.join($BUILD_CONFIGURATION_DIR, "CommonJS", "cappuccino", aFilename); + var buildFilename = FILE.join($BUILD_CJS_CAPPUCCINO, aFilename); filedir (buildFilename, [aFilename], function () { @@ -27,3 +27,7 @@ new FileList("**/*").exclude("Jakefile").forEach(function(aFilename) task ("build", buildFilename); CLOBBER.include(buildFilename); }); + +task ("build", function() { + setPackageMetadata(FILE.join($BUILD_CJS_CAPPUCCINO, "package.json")); +}); diff --git a/CommonJS/lib/cappuccino.js b/CommonJS/lib/cappuccino.js new file mode 100644 index 000000000..797c6e461 --- /dev/null +++ b/CommonJS/lib/cappuccino.js @@ -0,0 +1,23 @@ +var FILE = require("file"); +var sprintf = require("printf").sprintf; + +var pkg = null; +function getPackage() { + if (!pkg) + pkg = JSON.parse(FILE.path(module.path).dirname().dirname().join("package.json").read({ charset : "UTF-8" })); + return pkg; +} + +exports.version = function() { return getPackage()["version"]; } +exports.revision = function() { return getPackage()["cappuccino-revision"]; } +exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); } + +exports.fullVersionString = function() { + return sprintf("cappuccino %s (%04d-%02d-%02d %s)", + exports.version(), + exports.timestamp().getUTCFullYear(), + exports.timestamp().getUTCMonth()+1, + exports.timestamp().getUTCDate(), + exports.revision().slice(0,6) + ); +} diff --git a/CommonJS/package.json b/CommonJS/package.json index daa210ca2..25d48cdcf 100644 --- a/CommonJS/package.json +++ b/CommonJS/package.json @@ -4,7 +4,6 @@ "description": "Cappuccino module", "keywords": ["objective-j", "objj", "objective j", "capp", "cappuccino"], "author": "280 North, Inc. (http://280north.com/)", - "version": "0.8.0", "objj-frameworks": ["Frameworks"], "objj-debug-frameworks": ["Frameworks/Debug"], "contributors": [ diff --git a/Jakefile b/Jakefile index 0263cc66f..94112040d 100644 --- a/Jakefile +++ b/Jakefile @@ -280,21 +280,23 @@ task("push-objective-j", function() { function pushPackage(path, remote, branch) { branch = branch || "master"; - + + var pushPackagesPath = FILE.path(".push-package") + + pushPackagesPath.mkdirs(); + + var packagePath = pushPackagesPath.join(remote.replace(/[^\w]/g, "_")); + stream.print("Pushing \0blue(" + path + "\0) to "+branch+" of \0blue(" + remote + "\0)"); - FILE.mkdirs(".push-package"); - - var pushPackageDir = FILE.join(".push-package", remote.replace(/[^\w]/g, "_")); - - if (FILE.exists(pushPackageDir)) - OS.system(buildCmd([["cd", pushPackageDir], ["git", "fetch"]])); + if (packagePath.isDirectory()) + OS.system(buildCmd([["cd", packagePath], ["git", "fetch"]])); else - OS.system(["git", "clone", remote, pushPackageDir]); + OS.system(["git", "clone", remote, packagePath]); - if (OS.system(buildCmd([["cd", pushPackageDir], ["git", "checkout", "origin/"+branch]]))) { + if (OS.system(buildCmd([["cd", packagePath], ["git", "checkout", "origin/"+branch]]))) { if (OS.system(buildCmd([ - ["cd", pushPackageDir], + ["cd", packagePath], ["git", "symbolic-ref", "HEAD", "refs/heads/"+branch], ["rm", ".git/index"], ["git", "clean", "-fdx"] @@ -302,20 +304,30 @@ function pushPackage(path, remote, branch) throw "pushPackage failed"; } - if (OS.system("cd "+OS.enquote(pushPackageDir)+" && git rm --ignore-unmatch -r * && rm -rf *")) + if (OS.system("cd "+OS.enquote(packagePath)+" && git rm --ignore-unmatch -r * && rm -rf *")) throw "pushPackage failed"; - if (OS.system("cp -R "+OS.enquote(path)+"/* "+OS.enquote(pushPackageDir)+"/.")) + if (OS.system("cp -R "+OS.enquote(path)+"/* "+OS.enquote(packagePath)+"/.")) throw "pushPackage failed"; - OS.system(buildCmd([ - ["cd", pushPackageDir], + var pkg = JSON.parse(packagePath.join("package.json").read({ charset : "UTF-8" })); + + stream.print(" Version: \0purple(" + pkg["version"] + "\0)"); + stream.print(" Revision: \0purple(" + pkg["cappuccino-revision"] + "\0)"); + stream.print(" Timestamp: \0purple(" + pkg["cappuccino-timestamp"] + "\0)"); + + var cmd = [ + ["cd", packagePath], ["git", "add", "."], - ["git", "commit", "-m", "Pushed on " + new Date()] - ])); + ["git", "commit", "-m", "version="+pkg.version+"; revision="+pkg["cappuccino-revision"]+"; timestamp="+pkg["cappuccino-timestamp"]+";"] + ]; + if (pkg["cappuccino-revision"]) + cmd.push(["git", "tag", "rev-"+pkg["cappuccino-revision"].slice(0,6)]); + + OS.system(buildCmd(cmd)); if (OS.system(buildCmd([ - ["cd", pushPackageDir], - ["git", "push", "origin", "HEAD:"+branch] + ["cd", packagePath], + ["git", "push", "--tags", "origin", "HEAD:"+branch] ]))) throw "pushPackage failed"; } diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 565137440..754616d47 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -1,5 +1,7 @@ var FILE = require("file"); +var sprintf = require("printf").sprintf; + var window = exports.window = require("browser/window"); if (system.engine === "rhino") @@ -7,7 +9,7 @@ if (system.engine === "rhino") window.__parent__ = null; window.__proto__ = global; } - + // setup OBJJ_HOME, OBJJ_INCLUDE_PATHS, etc window.OBJJ_HOME = exports.OBJJ_HOME = FILE.resolve(module.path, ".."); @@ -77,6 +79,12 @@ exports.run = function(args) // copy the args since we're going to modify them var argv = args.slice(1); + if (argv[0] === "--version") + { + print(exports.fullVersionString()); + return; + } + while (argv.length && argv[0].indexOf('-I') === 0) OBJJ_INCLUDE_PATHS.unshift.apply(OBJJ_INCLUDE_PATHS, argv.shift().substr(2).split(':')); } @@ -178,5 +186,26 @@ exports.make_narwhal_factory = function(path) } // end "with" +var pkg = null; +function getPackage() { + if (!pkg) + pkg = JSON.parse(FILE.path(module.path).dirname().dirname().join("package.json").read({ charset : "UTF-8" })); + return pkg; +} + +exports.version = function() { return getPackage()["version"]; } +exports.revision = function() { return getPackage()["cappuccino-revision"]; } +exports.timestamp = function() { return new Date(getPackage()["cappuccino-timestamp"]); } + +exports.fullVersionString = function() { + return sprintf("objective-j %s (%04d-%02d-%02d %s)", + exports.version(), + exports.timestamp().getUTCFullYear(), + exports.timestamp().getUTCMonth()+1, + exports.timestamp().getUTCDate(), + exports.revision().slice(0,6) + ); +} + if (require.main == module.id) exports.run(system.args); diff --git a/Objective-J/CommonJS/package.json b/Objective-J/CommonJS/package.json index 8a01f5605..b6739053f 100644 --- a/Objective-J/CommonJS/package.json +++ b/Objective-J/CommonJS/package.json @@ -5,7 +5,6 @@ "description": "Objective-J and Cappuccino module", "keywords": ["objective-j", "objj", "objective j", "cappuccino"], "author": "280 North, Inc. (http://280north.com/)", - "version": "0.8.0", "contributors": [ "Francisco Tolmasky (http://tolmasky.com/)", "Ross Boucher (http://rossboucher.com/)", diff --git a/Objective-J/Jakefile b/Objective-J/Jakefile index f7c474127..58f2de2db 100644 --- a/Objective-J/Jakefile +++ b/Objective-J/Jakefile @@ -87,6 +87,10 @@ new FileList("CommonJS/**/*").forEach(function(aFilename) CLOBBER.include(buildFilename); }); +task ("build", function() { + setPackageMetadata(FILE.join($BUILD_CJS_OBJECTIVE_J, "package.json")); +}); + $BUILD_CJS_OBJECTIVE_J_FRAMEWORK = FILE.join($BUILD_CJS_OBJECTIVE_J, "Frameworks", "Objective-J"); filedir($BUILD_CJS_OBJECTIVE_J_FRAMEWORK, function() diff --git a/Tools/capp/main.j b/Tools/capp/main.j index 1639b5f72..5ec66b33b 100644 --- a/Tools/capp/main.j +++ b/Tools/capp/main.j @@ -22,7 +22,7 @@ function main(args) switch (argument) { case "version": - case "--version": return print("capp version 0.8.0"); + case "--version": return print(require("cappuccino").fullVersionString()); case "-h": case "--help": return printUsage(); diff --git a/common.jake b/common.jake index 4266c22d3..74bfc08a7 100644 --- a/common.jake +++ b/common.jake @@ -2,6 +2,7 @@ var SYSTEM = require("system"); var FILE = require("file"); var OS = require("os"); var UTIL = require("util"); +var stream = require("term").stream; var requiresSudo = false; @@ -288,6 +289,31 @@ global.symlink_executable = function(source) FILE.symlink(relative, destination); } +function getCappuccinoVersion() { + var versionFile = FILE.path(module.path).dirname().join("version.json"); + return JSON.parse(versionFile.read({ charset : "UTF-8" })).version; +} + +global.setPackageMetadata = function(packagePath) { + var pkg = JSON.parse(FILE.read(packagePath, { charset : "UTF-8" })); + + var p = OS.popen(["git", "rev-parse", "--verify", "HEAD"]); + if (p.wait() === 0) { + var sha = p.stdout.read().split("\n")[0]; + if (sha.length === 40) + pkg["cappuccino-revision"] = sha; + } + + pkg["cappuccino-timestamp"] = new Date().getTime(); + pkg["version"] = getCappuccinoVersion(); + + stream.print(" Version: \0purple(" + pkg["version"] + "\0)"); + stream.print(" Revision: \0purple(" + pkg["cappuccino-revision"] + "\0)"); + stream.print(" Timestamp: \0purple(" + pkg["cappuccino-timestamp"] + "\0)"); + + FILE.write(packagePath, JSON.stringify(pkg, null, 4), { charset : "UTF-8" }); +} + global.subtasks = function(subprojects, taskNames) { taskNames.forEach(function(aTaskName) diff --git a/version.json b/version.json new file mode 100644 index 000000000..a997bfb09 --- /dev/null +++ b/version.json @@ -0,0 +1,3 @@ +{ + "version": "0.8.0" +} \ No newline at end of file