cell shop env var
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Hidden vars (os, args, core_path, use_mcode) come from env
|
||||
// Hidden vars (os, args, shop_path, use_mcode) come from env
|
||||
var core_path = shop_path + '/packages/core'
|
||||
// args[0] = script name, args[1..] = user args
|
||||
var load_internal = os.load_internal
|
||||
function use_embed(name) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Hidden vars (os, actorsym, init, core_path) come from env
|
||||
// Hidden vars (os, actorsym, init, shop_path) come from env
|
||||
var ACTORDATA = actorsym
|
||||
var SYSYM = '__SYSTEM__'
|
||||
|
||||
@@ -52,21 +52,10 @@ function ends_with(str, suffix) {
|
||||
var js = use_embed('js')
|
||||
var fd = use_embed('fd')
|
||||
|
||||
// Get the shop path from HOME environment
|
||||
var home = os.getenv('HOME') || os.getenv('USERPROFILE')
|
||||
if (!home) {
|
||||
os.print('Could not determine home directory\n')
|
||||
os.exit(1)
|
||||
}
|
||||
var shop_path = home + '/.cell'
|
||||
// shop_path comes from hidden env (set by cell.c)
|
||||
var packages_path = shop_path + '/packages'
|
||||
var core_path = packages_path + '/core'
|
||||
|
||||
if (!fd.is_dir(core_path)) {
|
||||
os.print('Cell shop not found at ' + shop_path + '. Run "cell install" to set up.\n')
|
||||
os.exit(1)
|
||||
}
|
||||
|
||||
var use_cache = {}
|
||||
use_cache['core/os'] = os
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ int run_c_test_suite(JSContext *ctx);
|
||||
static int run_test_suite(size_t heap_size);
|
||||
|
||||
cell_rt *root_cell = NULL;
|
||||
static char *shop_path = NULL;
|
||||
static char *core_path = NULL;
|
||||
static JSRuntime *g_runtime = NULL;
|
||||
|
||||
@@ -38,31 +39,52 @@ static const char* get_home_dir(void) {
|
||||
return home;
|
||||
}
|
||||
|
||||
// Find and verify the cell shop at ~/.cell
|
||||
int find_cell_shop(void)
|
||||
// Find and verify the cell shop
|
||||
// Precedence: override (--shop flag) > CELL_SHOP env var > ~/.cell
|
||||
int find_cell_shop(const char *override_path)
|
||||
{
|
||||
const char *home = get_home_dir();
|
||||
if (!home) {
|
||||
printf("ERROR: Could not determine home directory. Set HOME environment variable.\n");
|
||||
return 0;
|
||||
if (override_path) {
|
||||
shop_path = strdup(override_path);
|
||||
} else {
|
||||
const char *env = getenv("CELL_SHOP");
|
||||
if (env) {
|
||||
shop_path = strdup(env);
|
||||
} else {
|
||||
const char *home = get_home_dir();
|
||||
if (!home) {
|
||||
printf("ERROR: Could not determine home directory. Set HOME environment variable.\n");
|
||||
return 0;
|
||||
}
|
||||
size_t path_len = strlen(home) + strlen("/" CELL_SHOP_DIR) + 1;
|
||||
shop_path = malloc(path_len);
|
||||
if (!shop_path) {
|
||||
printf("ERROR: Could not allocate memory for shop path\n");
|
||||
return 0;
|
||||
}
|
||||
snprintf(shop_path, path_len, "%s/" CELL_SHOP_DIR, home);
|
||||
}
|
||||
}
|
||||
|
||||
// Build path to ~/.cell/core
|
||||
size_t path_len = strlen(home) + strlen("/" CELL_SHOP_DIR "/" CELL_CORE_DIR) + 1;
|
||||
core_path = malloc(path_len);
|
||||
// Derive core_path from shop_path
|
||||
size_t core_len = strlen(shop_path) + strlen("/" CELL_CORE_DIR) + 1;
|
||||
core_path = malloc(core_len);
|
||||
if (!core_path) {
|
||||
printf("ERROR: Could not allocate memory for core path\n");
|
||||
free(shop_path);
|
||||
shop_path = NULL;
|
||||
return 0;
|
||||
}
|
||||
snprintf(core_path, path_len, "%s/" CELL_SHOP_DIR "/" CELL_CORE_DIR, home);
|
||||
snprintf(core_path, core_len, "%s/" CELL_CORE_DIR, shop_path);
|
||||
|
||||
// Check if the core directory exists
|
||||
struct stat st;
|
||||
if (stat(core_path, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
||||
printf("ERROR: Cell shop not found at %s/" CELL_SHOP_DIR "\n", home);
|
||||
printf("ERROR: Cell shop not found at %s\n", shop_path);
|
||||
printf("Run 'cell install' to set up the cell environment.\n");
|
||||
free(core_path);
|
||||
free(shop_path);
|
||||
core_path = NULL;
|
||||
shop_path = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -183,8 +205,8 @@ void script_startup(cell_rt *prt)
|
||||
JS_SetPropertyStr(js, hidden_env, "init", JS_NULL);
|
||||
}
|
||||
|
||||
if (core_path) {
|
||||
JS_SetPropertyStr(js, hidden_env, "core_path", JS_NewString(js, core_path));
|
||||
if (shop_path) {
|
||||
JS_SetPropertyStr(js, hidden_env, "shop_path", JS_NewString(js, shop_path));
|
||||
}
|
||||
|
||||
// Stone the environment
|
||||
@@ -255,6 +277,7 @@ static void print_usage(const char *prog)
|
||||
printf("Usage: %s [options] <script> [args...]\n\n", prog);
|
||||
printf("Run a cell script (.ce actor or .cm module).\n\n");
|
||||
printf("Options:\n");
|
||||
printf(" --shop <path> Set shop path (overrides CELL_SHOP env var)\n");
|
||||
printf(" --mcode <script> [args] Run through mcode compilation pipeline\n");
|
||||
printf(" --test [heap_size] Run C test suite\n");
|
||||
printf(" -h, --help Show this help message\n");
|
||||
@@ -286,12 +309,26 @@ int cell_init(int argc, char **argv)
|
||||
/* Default: run script through bootstrap pipeline */
|
||||
int use_mcode = 0;
|
||||
int arg_start = 1;
|
||||
if (argc >= 3 && strcmp(argv[1], "--mcode") == 0) {
|
||||
use_mcode = 1;
|
||||
arg_start = 2;
|
||||
const char *shop_override = NULL;
|
||||
|
||||
// Parse flags (order-independent)
|
||||
while (arg_start < argc && argv[arg_start][0] == '-') {
|
||||
if (strcmp(argv[arg_start], "--mcode") == 0) {
|
||||
use_mcode = 1;
|
||||
arg_start++;
|
||||
} else if (strcmp(argv[arg_start], "--shop") == 0) {
|
||||
if (arg_start + 1 >= argc) {
|
||||
printf("ERROR: --shop requires a path argument\n");
|
||||
return 1;
|
||||
}
|
||||
shop_override = argv[arg_start + 1];
|
||||
arg_start += 2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find_cell_shop()) return 1;
|
||||
if (!find_cell_shop(shop_override)) return 1;
|
||||
|
||||
size_t boot_size;
|
||||
int boot_is_bin = 1;
|
||||
@@ -322,7 +359,7 @@ int cell_init(int argc, char **argv)
|
||||
|
||||
JSValue hidden_env = JS_NewObject(ctx);
|
||||
JS_SetPropertyStr(ctx, hidden_env, "os", js_os_use(ctx));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "core_path", JS_NewString(ctx, core_path));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "shop_path", JS_NewString(ctx, shop_path));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "use_mcode", JS_NewBool(ctx, use_mcode));
|
||||
JSValue args_arr = JS_NewArray(ctx);
|
||||
for (int i = arg_start; i < argc; i++) {
|
||||
|
||||
Reference in New Issue
Block a user