Permalink
Browse files

Add ability to load options from a file

Set RBX_OPTFILE to a path and config variables will be loaded from it.
  • Loading branch information...
Evan Phoenix
Evan Phoenix committed Jun 1, 2009
1 parent 94c725b commit 878ca1bf870e544a2c1b0e4bbe04f58aec944d32
Showing with 39 additions and 14 deletions.
  1. +11 −1 vm/drivers/cli.cpp
  2. +25 −12 vm/environment.cpp
  3. +3 −1 vm/environment.hpp
View
@@ -60,11 +60,21 @@ static void load_runtime_kernel(Environment& env, std::string root) {
* function does not deal with that subject.
*/
int main(int argc, char** argv) {
- Environment env(argc, argv);
+ Environment env;
env.state->init_stack_size();
env.state->set_stack_start(&env);
try {
+ if(const char* var = getenv("RBX_OPTIONS")) {
+ env.load_string(var);
+ }
+
+ if(const char* path = getenv("RBX_OPTFILE")) {
+ env.load_conf(path);
+ }
+
+ env.load_config_argv(argc, argv);
+
const char* runtime = getenv("RBX_RUNTIME");
if(!runtime) {
View
@@ -31,17 +31,21 @@
namespace rubinius {
- Environment::Environment(int argc, char** argv) {
- config_parser.process_argv(argc, argv);
- if(const char* var = getenv("RBX_OPTIONS")) {
- config_parser.import_many(var);
- }
- config_parser.update_configuration(config);
-
+ Environment::Environment() {
shared = new SharedState(config, config_parser);
state = shared->new_vm();
state->initialize();
+ }
+
+ Environment::~Environment() {
+ VM::discard(state);
+ SharedState::discard(shared);
+ }
+
+ void Environment::load_config_argv(int argc, char** argv) {
+ config_parser.process_argv(argc, argv);
+ config_parser.update_configuration(config);
if(config.print_config > 1) {
std::cout << "========= Configuration =========\n";
@@ -52,11 +56,6 @@ namespace rubinius {
}
}
- Environment::~Environment() {
- VM::discard(state);
- SharedState::discard(shared);
- }
-
void Environment::enable_preemption() {
state->setup_preemption();
}
@@ -125,6 +124,20 @@ namespace rubinius {
config_parser.import_stream(stream);
}
+ void Environment::load_conf(std::string path) {
+ std::ifstream stream(path.c_str());
+ if(!stream) {
+ std::string error = "Unable to load " + path + ", it is missing";
+ throw std::runtime_error(error);
+ }
+
+ config_parser.import_stream(stream);
+ }
+
+ void Environment::load_string(std::string str) {
+ config_parser.import_many(str);
+ }
+
void Environment::boot_vm() {
state->boot();
View
@@ -20,13 +20,15 @@ namespace rubinius {
ConfigParser config_parser;
Configuration config;
- Environment(int argc, char** argv);
+ Environment();
~Environment();
void load_config_argv(int argc, char** argv);
void load_argv(int argc, char** argv);
void load_directory(std::string dir);
void load_platform_conf(std::string dir);
+ void load_conf(std::string path);
+ void load_string(std::string str);
void run_file(std::string path);
void enable_preemption();
void boot_vm();

0 comments on commit 878ca1b

Please sign in to comment.