Skip to content

Commit

Permalink
Make jsrepl.js use relocatable info (and find it using the relocatabl…
Browse files Browse the repository at this point in the history
…e path)
  • Loading branch information
ashb committed Oct 11, 2009
1 parent 2b62654 commit f7b7caa
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -77,6 +77,13 @@ option(RELOCATABLE "Whether the binary should be relocatable" ON)

if(RELOCATABLE)
add_definitions("-DFLUSSPFERD_RELOCATABLE")
# TODO: should should probably use some relative_to funciton to be smarter
# That or being settable from a cmake option
add_definitions("-DFLUSSPFERD_ETC_PATH=\"../etc/flusspferd\"")
set(INSTALL_RELATIVE_MODULES_PATH "../lib/flusspferd/modules")
set(INSTALL_RELATIVE_LIBDATA_PATH "../lib/flusspferd")
else()
add_definitions("-DFLUSSPFERD_ETC_PATH=\"${INSTALL_ETC_PATH}\"")
endif()

set(CMAKE_SHARED_MODULE_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down
1 change: 1 addition & 0 deletions include/flusspferd/version.hpp
Expand Up @@ -32,6 +32,7 @@ THE SOFTWARE.
namespace flusspferd {

std::string version();
bool is_relocatable();

}

Expand Down
18 changes: 10 additions & 8 deletions src/core/flusspferd_module.cpp
Expand Up @@ -49,18 +49,12 @@ void flusspferd::load_flusspferd_module(object container, std::string const &arg
value(flusspferd::version()),
read_only_property | permanent_property);

#ifdef FLUSSPFERD_RELOCATABLE
exports.define_property(
"relocatable",
value(true),
read_only_property | permanent_property);

#else
exports.define_property(
"relocatable",
value(false),
value(is_relocatable()),
read_only_property | permanent_property);

#ifndef FLUSSPFERD_RELOCATABLE
exports.define_property(
"installPrefix",
value(INSTALL_PREFIX),
Expand All @@ -85,6 +79,14 @@ void flusspferd::load_flusspferd_module(object container, std::string const &arg
}
}

bool flusspferd::is_relocatable() {
#ifdef FLUSSPFERD_RELOCATABLE
return true;
#else
return false;
#endif
}

std::string flusspferd::version() {
return FLUSSPFERD_VERSION;
}
Expand Down
13 changes: 11 additions & 2 deletions src/js/jsrepl.js.in
Expand Up @@ -24,6 +24,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

require.paths.push('.', '@INSTALL_MODULES_PATH@');
if (require('flusspferd').relocatable) {
var binDir = require('flusspferd').executableName
.replace(/flusspferd(?:\.exe)?/, '');

prelude = '@INSTALL_LIBDATA_PATH@/prelude.js';
require.paths.push('.', binDir + '@INSTALL_RELATIVE_MODULES_PATH@');

prelude = binDir + '@INSTALL_RELATIVE_LIBDATA_PATH@prelude.js';
} else {
require.paths.push('.', '@INSTALL_MODULES_PATH@');

prelude = '@INSTALL_LIBDATA_PATH@/prelude.js';
}
17 changes: 17 additions & 0 deletions src/programs/flusspferd.cpp
Expand Up @@ -50,6 +50,10 @@ THE SOFTWARE.
#define HISTORY_FILE_DEFAULT "~/.flusspferd-history"
#endif

#ifdef FLUSSPFERD_RELOCATABLE
#include <boost/filesystem.hpp>
#endif

namespace phoenix = boost::phoenix;
namespace args = phoenix::arg_names;

Expand Down Expand Up @@ -127,6 +131,19 @@ flusspferd_repl::flusspferd_repl(int argc, char **argv)

flusspferd::load_core(g, argv[0]);

#ifdef FLUSSPFERD_RELOCATABLE
// Change the config to use the relative version
boost::filesystem::path p = g.call("require", "flusspferd")
.to_object()
.get_property("executableName")
.to_std_string();
p.remove_filename();
p /= boost::filesystem::path(FLUSSPFERD_ETC_PATH)
/ std::string("jsrepl.js");
config_file = p.string();
std::cout << "new config: " << config_file << "\n";
#endif

flusspferd::create_native_function<void (int)>(
g, "quit",
phoenix::bind(&flusspferd_repl::quit, this, args::arg1));
Expand Down

0 comments on commit f7b7caa

Please sign in to comment.