Skip to content

Commit

Permalink
platform selection via SH script
Browse files Browse the repository at this point in the history
  • Loading branch information
cadorn committed Sep 29, 2011
1 parent e436bf0 commit a9d2653
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/Demos.md
Expand Up @@ -9,6 +9,8 @@ These demos work on the following platforms:
* NodeJS (default): `node` (**Tested**)
* Narwhal: `narwhal` (**Not tested lately**)
* RingoJS: `ringo` (**Not tested yet**)
* RingoJS: `gpsee` (**Not tested yet**)
* RingoJS: `v8cgi` (**Not tested yet**)

To use a specific platform specify `--platform <alias>`. `node` is used by default.

Expand Down
10 changes: 7 additions & 3 deletions lib/pinf-loader-js/loader.js
Expand Up @@ -3,7 +3,7 @@

var boot = exports.boot = function(options)
{
const VERSION = "0.2.9";
const VERSION = "0.2.10";
var timers = {
start: new Date().getTime(),
loadAdditional: 0
Expand Down Expand Up @@ -207,6 +207,9 @@ var boot = exports.boot = function(options)

var knownCliPlatforms = [
"node",
"gsr",
"v8cgi",
"ringo",
"narwhal"
];

Expand Down Expand Up @@ -253,8 +256,9 @@ var boot = exports.boot = function(options)
else
if (typeof cliOptions.platform != "undefined" && cliOptions.platform != API.ENV.platform)
{
spawnForPlatform(cliOptions.platform);
return;
// Do nothing! `./pinf-loader.sh` already directed arguments to correct binary.
// spawnForPlatform(cliOptions.platform);
// return;
}

function run()
Expand Down
29 changes: 19 additions & 10 deletions pinf-loader.sh
@@ -1,15 +1,24 @@
#!/bin/bash

# TODO: Check --platform to invoke correct platform binary.
# For now we let the loader check and have node spawn a process if needed.
# Need to check for `node`, `gsr` (gpsee) and `ringo` to realize: https://github.com/pinf/test-programs-js

BASE_PATH=$(dirname $(readlink $0))
NODE_PATH=$(which "node")
# TODO: Only match until first non-option argument is found. i.e. argument not prefixed by '-'
PLATFORM_ALIAS=$(echo "$@" | perl -lpe '($_) = /\s*--platform\s*(\S*)\s*/')
PLATFORM_BIN_NAME=$PLATFORM_ALIAS

if [ "$PLATFORM_ALIAS" = "gpsee" ]; then
PLATFORM_BIN_NAME="gsr"
fi

if [ "$NODE_PATH" ]; then
exec "$NODE_PATH" "$BASE_PATH/pinf-loader.js" "$@"
else
echo "ERROR: Need NodeJS installed. 'node' must be on the PATH."
exit 1
if [ -z $PLATFORM_BIN_NAME ]; then
PLATFORM_ALIAS="node"
PLATFORM_BIN_NAME="node"
fi

PLATFORM_BIN_PATH=$(which "$PLATFORM_BIN_NAME")

if [ -z $PLATFORM_BIN_PATH ]; then
echo "Fatal Error: No binary '$PLATFORM_BIN_NAME' found for '--platform $PLATFORM_ALIAS' on PATH '$PATH'!"
exit 1;
fi

exec "$PLATFORM_BIN_PATH" "$BASE_PATH/pinf-loader.js" "$@"

0 comments on commit a9d2653

Please sign in to comment.