Add capp_env

This commit is contained in:
Antoine Mercadal committed 2015-06-01 15:20:20 -07:00
1 parent de7951f4db
commit 245da9b422
5 files changed
+187 -1

No files matched your search

+1 -1
View File
@@ -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"]);
+12
View File
@@ -0,0 +1,12 @@
require ("../../common.jake");
var OS = require("os"),
task = require("jake").task;
task ("build", function()
{
sudo(["./install.sh"]);
});
task ("default", ["build"]);
+45
View File
@@ -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
+120
View File
@@ -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)
+9
View File
@@ -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