From 245da9b4220eece6b0df1ccfcfe51abce6dd2756 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Mon, 1 Jun 2015 15:20:20 -0700 Subject: [PATCH] Add capp_env --- Tools/Jakefile | 2 +- Tools/capp_env/Jakefile | 12 ++++ Tools/capp_env/README.md | 45 ++++++++++++++ Tools/capp_env/capp_env | 120 ++++++++++++++++++++++++++++++++++++++ Tools/capp_env/install.sh | 9 +++ 5 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 Tools/capp_env/Jakefile create mode 100644 Tools/capp_env/README.md create mode 100755 Tools/capp_env/capp_env create mode 100755 Tools/capp_env/install.sh diff --git a/Tools/Jakefile b/Tools/Jakefile index 92d48b9f92..440bf37137 100644 --- a/Tools/Jakefile +++ b/Tools/Jakefile @@ -2,6 +2,6 @@ require("../common.jake"); // nib2cib uses fontinfo and imagesize and capp uses nib2cib -subtasks(["fontinfo", "imagesize", "nib2cib", "objj2objcskeleton", "capp", "capp_lint", "dump_theme", "XcodeCapp"], ["build", /*"clean", "clobber"*/]); +subtasks(["fontinfo", "imagesize", "nib2cib", "objj2objcskeleton", "capp", "capp_lint", "capp_env", "dump_theme", "XcodeCapp"], ["build", /*"clean", "clobber"*/]); subtasks(["fontinfo", "imagesize"], ["clean", "clobber"]); diff --git a/Tools/capp_env/Jakefile b/Tools/capp_env/Jakefile new file mode 100644 index 0000000000..fd6dd37506 --- /dev/null +++ b/Tools/capp_env/Jakefile @@ -0,0 +1,12 @@ + +require ("../../common.jake"); + +var OS = require("os"), + task = require("jake").task; + +task ("build", function() +{ + sudo(["./install.sh"]); +}); + +task ("default", ["build"]); \ No newline at end of file diff --git a/Tools/capp_env/README.md b/Tools/capp_env/README.md new file mode 100644 index 0000000000..4d6458a415 --- /dev/null +++ b/Tools/capp_env/README.md @@ -0,0 +1,45 @@ +# capp_env + +`capp_env` is a simple virtual environment tool for Cappuccino. + + +## Usage + +To create a virtual environment: + + capp_env -p /path/to/the/env + +This will create + + /path/to/the/env + /bin + /build + /sources # if you want to put your sources here, but it is optional + /narwhal + +It will download the latest `cappuccino_base`, put it in `narwhal` and will create an `activate` file in `/path/to/the/env/bin` + +Then you can activate this environment by doing: + + source /path/to/the/env/bin/activate + +your current `PATH` will be updated to look for `jake` and `capp` and all the tools from `/path/to/the/env/narwhal/bin`, and will set `CAPP_BUILD` to be `/path/to/the/env/build`. + +From now on, you can clone the Cappuccino sources, (in `sources` for instance) and do + + jake install + +If you install the Cappuccino source while in an virtual env, all the tools will use the debug version that you just built (for instance, `nib2cib` will be used from `/path/to/the/env/build/Debug/CommonJS/cappuccino/bin/nib2cib`) + + +## Deactivate + +Just close the current terminal, or run + + deactivate + + +## TODOs + + - let a chance to select the current cappuccino base version to download + - find a way to make XcodeCapp to use these environements \ No newline at end of file diff --git a/Tools/capp_env/capp_env b/Tools/capp_env/capp_env new file mode 100755 index 0000000000..fe136849b1 --- /dev/null +++ b/Tools/capp_env/capp_env @@ -0,0 +1,120 @@ +#!/usr/bin/env python + +import os +import argparse + +ACTIVATE_SCRIPT = """ +deactivate() { + if [ -n "$__OLD_PATH" ] ; then + PATH="$__OLD_PATH" + export PATH + unset __OLD_PATH + fi; + + if [ -n "$__OLD_CAPP_BUILD" ] ; then + CAPP_BUILD="$__OLD_CAPP_BUILD" + export CAPP_BUILD + unset __OLD_CAPP_BUILD + fi; + + if [ -n "$__OLD_PS1" ] ; then + PS1="$__OLD_PS1" + export PS1 + unset __OLD_PS1 + fi; + + unset __VIRTUAL_ENV + if [ ! "$1" = "nondestructive" ] ; then + unset -f deactivate + fi +} + +deactivate nondestructive + +__VIRTUAL_ENV="%s" +__OLD_PATH="$PATH" +__OLD_CAPP_BUILD="$CAPP_BUILD" +__OLD_PS1="$PS1" + +CAPP_BUILD="$__VIRTUAL_ENV/build" +export CAPP_BUILD + +PATH="$CAPP_BUILD/Debug/CommonJS/cappuccino/bin:$CAPP_BUILD/Debug/CommonJS/objective-j/bin/:$__VIRTUAL_ENV/narwhal/bin:$PATH" +export PATH + +PS1="(`basename \"$__VIRTUAL_ENV\"`)$PS1" +export PS1 +""" + +def exec_shell(command, error_message=None, expected=0): + """ + Execute a shell command + """ + ret = os.system(command) + if ret != expected: + if error_message: + raise Exception(error_message) + else: + raise Exception("Error during command %s. expected %d, got %d" % (command, expected, ret)) + + +def create_environment(env_path): + """ + Create the base environement folder + """ + if os.path.exists(env_path): + print "Path already exists. abort" + return + os.makedirs(env_path) + os.makedirs("%s/sources" % env_path) + os.makedirs("%s/build" % env_path) + os.makedirs("%s/bin" % env_path) + + +def install_cappuccino_base(env_path): + """ + Install latest version of Cappuccino Base + """ + exec_shell("curl https://raw.githubusercontent.com/cappuccino/cappuccino/v0.9.7-1/bootstrap.sh >/tmp/cb.sh") + exec_shell("bash /tmp/cb.sh --directory '%s/narwhal' --noprompt" % (env_path)) + exec_shell("rm /tmp/cb.sh") + + +def install_activate(env_path): + """ + Create the env/bin/activate script + """ + absolute_path = os.path.abspath(env_path) + f = open("%s/bin/activate" % env_path, 'w') + f.write(ACTIVATE_SCRIPT % absolute_path) + f.close() + exec_shell("chmod u+x %s/bin/activate" % env_path) + + + + + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser(description="Virtual Env For Cappuccino.") + + parser.add_argument('-p', "--path", + dest="env_path", + help="Path of the virtual environement", + required=True, + type=str) + + parser.add_argument('-a', "--activate-only", + dest="activate_only", + help="Only reinstall the activate script", + action="store_true") + + args = parser.parse_args() + + if args.activate_only: + install_activate(args.env_path) + else: + create_environment(args.env_path) + install_cappuccino_base(args.env_path) + install_activate(args.env_path) \ No newline at end of file diff --git a/Tools/capp_env/install.sh b/Tools/capp_env/install.sh new file mode 100755 index 0000000000..7ecc1e1621 --- /dev/null +++ b/Tools/capp_env/install.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +chmod +x capp_env + +if [[ ! -d /usr/local/narwhal/bin ]]; then + mkdir -p /usr/local/narwhal/bin +fi + +cp capp_env /usr/local/narwhal/bin \ No newline at end of file