Merge branch 'loader' of github.com:280north/cappuccino into loader

This commit is contained in:
Ross Boucher
2010-02-15 21:28:58 -08:00
4 changed files with 41 additions and 61 deletions
@@ -11,37 +11,26 @@ var OBJJ_PREPROCESSOR_PREPROCESS = exports.OBJJ_PREPROCESSOR_PREPROCESS
var OBJJ_PREPROCESSOR_COMPRESS = exports.OBJJ_PREPROCESSOR_COMPRESS = 1 << 11;
var OBJJ_PREPROCESSOR_SYNTAX = exports.OBJJ_PREPROCESSOR_SYNTAX = 1 << 12;
var SHRINKSAFE_PATH = FILE.join(ObjectiveJ.OBJJ_HOME, "shrinksafe", "shrinksafe.jar"),
RHINO_PATH = FILE.join(ObjectiveJ.OBJJ_HOME, "shrinksafe", "js.jar");
var compressor = null;
function sharedCompressor()
{
if (!compressor)
compressor = OS.popen("java -server -Dfile.encoding=UTF-8 -classpath " + RHINO_PATH + ":" + SHRINKSAFE_PATH + " org.dojotoolkit.shrinksafe.Main", { charset:"UTF-8" });
return compressor;
}
function compress(/*String*/ aCode, /*String*/ FIXME)
{
var tmpFile = FILE.join("/tmp", FIXME + Math.random() + ".tmp");
FILE.write(tmpFile, aCode, { charset:"UTF-8" });
var compressor = sharedCompressor();
output = "",
chunk = "";
compressor.stdin.write(tmpFile + "\n");
compressor.stdin.flush();
while ((chunk = compressor.stdout.readLine()) !== "/*----*/\n")
output += chunk;
return output;
// return OS.command(["java", "-Dfile.encoding=UTF-8", "-classpath", [RHINO_PATH, SHRINKSAFE_PATH].join(":"), "org.dojotoolkit.shrinksafe.Main", tmpFile]);
var compressors = {
ss : { id : "minify/shrinksafe" }
//,yui : { id : "minify/yuicompressor" }
// ,cc : { id : "minify/closure-compiler" }
};
var compressorStats = {};
function compressor(code) {
var winner, winnerName;
compressorStats['original'] = (compressorStats['original'] || 0) + code.length;
for (var name in compressors) {
var compressor = require(compressors[name].id);
var result = compressor.compress(code, { charset : "UTF-8", useServer : true });
compressorStats[name] = (compressorStats[name] || 0) + result.length;
if (!winner || result < winner.length) {
winner = result;
winnerName = name;
}
}
// print("winner="+winnerName+" compressorStats="+JSON.stringify(compressorStats));
return winner;
}
function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags)
@@ -90,7 +79,7 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags)
if (shouldCompress)
{
var code = executable.code();
code = compress("function(){" + code + "}", FILE.basename(aFilePath));
code = compressor("function(){" + code + "}");
// more robust function wrapper stripping
code = code.replace(/^\s*function\s*\(\s*\)\s*{|}\s*;?\s*$/g, "");
executable.setCode(code);
+11 -21
View File
@@ -104,35 +104,25 @@ function environmentFlags()
}]).join(", ") + "]\"";
}
var SHRINKSAFE = require("minify/shrinksafe");
function compressor(code) {
return SHRINKSAFE.compress(code, { charset : "UTF-16", useServer : true });
}
function gcc(inputFilePath, outputFilePath, flags, compress)
{
stream.print("Building... \0green(" + outputFilePath +"\0)");
// GCC preprocess the file.
var gcc = OS.popen("gcc -E -x c -P " + flags + " " + inputFilePath, { charset:"UTF-8" }),
gccFilePath = FILE.join("", "tmp", "objj-gcc.js"),
chunk = null,
fileContents = FILE.read("header.txt", { charset : "UTF-8" });
var gcc = OS.popen("gcc -E -x c -P " + flags + " " + inputFilePath, { charset:"UTF-8" });
while (chunk = gcc.stdout.read())
fileContents += chunk;
FILE.write(gccFilePath, fileContents, { charset:"UTF-8" });
var contents = FILE.read("header.txt", { charset : "UTF-8" });
contents += gcc.stdout.read();
if (FILE.extension(inputFilePath) === ".js" && compress)
{
var compressor = OS.popen("java -server -Dfile.encoding=UTF-8 -classpath CommonJS/shrinksafe/js.jar:CommonJS/shrinksafe/shrinksafe.jar org.dojotoolkit.shrinksafe.Main", { charset:"UTF-8" });
compressor.stdin.write(FILE.absolute(gccFilePath) + "\n");
compressor.stdin.flush();
fileContents = "";
while ((chunk = compressor.stdout.readLine()) !== "/*----*/\n")
fileContents += chunk;
}
FILE.write(outputFilePath, fileContents, { charset : "UTF-8" });
contents = compressor(contents);
FILE.write(outputFilePath, contents, { charset : "UTF-8" });
}
task("build", [$BUILD_BROWSER_FILE, $BUILD_LICENSE, $BUILD_CJS_OBJECTIVE_J_FRAMEWORK]);
+8 -8
View File
@@ -166,13 +166,13 @@ if ! prompt; then
exit 1
fi
echo "================================================================================"
echo "Would you like to install the pre-built Objective-J and Cappuccino packages?"
echo "If you intend to build Cappuccino yourself this is not neccessary."
extra_packages=""
if prompt; then
extra_packages="objective-j cappuccino"
fi
# echo "================================================================================"
# echo "Would you like to install the pre-built Objective-J and Cappuccino packages?"
# echo "If you intend to build Cappuccino yourself this is not neccessary."
# extra_packages=""
# if prompt; then
# extra_packages="objective-j cappuccino"
# fi
echo "Installing necessary packages..."
@@ -181,7 +181,7 @@ if ! tusk update; then
exit 1
fi
tusk $tusk_install_command browserjs jake $extra_packages
tusk $tusk_install_command browserjs jake shrinksafe $extra_packages
if [ `uname` = "Darwin" ]; then
echo "================================================================================"
+1
View File
@@ -50,6 +50,7 @@ function ensurePackageUpToDate(packageName, requiredVersion, options)
// UPDATE THESE TO PICK UP CORRESPONDING CHANGES IN DEPENDENCIES
ensurePackageUpToDate("jake", "0.1.2");
ensurePackageUpToDate("browserjs", "0.1.1");
ensurePackageUpToDate("shrinksafe", "0.2");
ensurePackageUpToDate("narwhal", "0.2.1", {
noupdate : true,
message : "Update Narwhal to 0.2.1 by running bootstrap.sh, or pulling the latest from git (see: http://github.com/280north/narwhal)."