From e8bd0f55ff834e19d008d10345ff43c31313d9b6 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Sun, 6 Feb 2022 09:08:17 +0000 Subject: [PATCH] build busybox automatically if the POSIX subsystem is enabled --- ports/port.script | 4 ++++ util/build.c | 4 ++++ util/script.c | 35 ++++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ports/port.script b/ports/port.script index acef6d4..7ef1f78 100644 --- a/ports/port.script +++ b/ports/port.script @@ -112,6 +112,10 @@ void PortBochs() { } void PortBusybox() { + if PathExists("%posixRoot%/bin/busybox") { + return; + } + str version = "1.33.1"; if SystemGetHostName() == "Darwin" { diff --git a/util/build.c b/util/build.c index c147035..44d1e81 100644 --- a/util/build.c +++ b/util/build.c @@ -178,6 +178,10 @@ bool BuildAPIDependencies() { if (CallSystem("bin/script ports/port.script portName=harfbuzz targetName=" TARGET_NAME " toolchainPrefix=" TOOLCHAIN_PREFIX)) return false; } + if (IsOptionEnabled("Flag.ENABLE_POSIX_SUBSYSTEM")) { + if (CallSystem("bin/script ports/port.script portName=busybox targetName=" TARGET_NAME " toolchainPrefix=" TOOLCHAIN_PREFIX)) return false; + } + if (CallSystem("cp -p kernel/module.h root/Applications/POSIX/include")) return false; return true; diff --git a/util/script.c b/util/script.c index 66ec50b..0072fc6 100644 --- a/util/script.c +++ b/util/script.c @@ -3448,6 +3448,8 @@ void ScriptHeapEntryToString(ExecutionContext *context, HeapEntry *entry, const ScriptHeapEntryToString(context, entry, text, bytes); } else { Assert(false); + *text = ""; + *bytes = 0; } } @@ -4822,8 +4824,8 @@ void PrintLine(ImportData *importData, uintptr_t line) { uintptr_t length = 0; - for (uintptr_t i = position; i < importData->fileDataBytes; i++) { - if (((char *) importData->fileData)[i] == '\n') { + for (uintptr_t i = position; i <= importData->fileDataBytes; i++) { + if (i == importData->fileDataBytes || ((char *) importData->fileData)[i] == '\n') { length = i - position; break; } @@ -4832,21 +4834,17 @@ void PrintLine(ImportData *importData, uintptr_t line) { PrintDebug(">> %.*s\n", (int) length, &((char *) importData->fileData)[position]); } -int ScriptExecuteFromPath(char *scriptPath, size_t scriptPathBytes) { +int ScriptExecuteFromFile(char *scriptPath, size_t scriptPathBytes, char *fileData, size_t fileDataBytes) { Tokenizer tokenizer = { 0 }; ImportData importData = { 0 }; importData.path = scriptPath; importData.pathBytes = scriptPathBytes; - importData.fileData = FileLoad(scriptPath, &tokenizer.inputBytes); - importData.fileDataBytes = tokenizer.inputBytes; + importData.fileData = fileData; + importData.fileDataBytes = fileDataBytes; tokenizer.module = &importData; tokenizer.line = 1; - tokenizer.input = (const char *) importData.fileData; - - if (!tokenizer.input) { - PrintDebug("Error: Could not load the input file '%s'.\n", scriptPath); - return 1; - } + tokenizer.input = fileData; + tokenizer.inputBytes = fileDataBytes; FunctionBuilder builder = { 0 }; ExecutionContext context = { 0 }; @@ -4868,6 +4866,10 @@ int ScriptExecuteFromPath(char *scriptPath, size_t scriptPathBytes) { int result = ScriptLoad(tokenizer, &context, &importData) ? ScriptExecute(&context, &importData) : 1; ScriptFree(&context); + + importedModules = NULL; + importedModulesLink = &importedModules; + return result; } @@ -5250,7 +5252,6 @@ int ExternalPathMove(ExecutionContext *context, Value *returnValue) { } int ExternalFileCopy(ExecutionContext *context, Value *returnValue) { - (void) returnValue; STACK_POP_STRING_2(entryText, entryBytes, entry2Text, entry2Bytes); returnValue->i = 0; if (entryBytes == 0 || entry2Bytes == 0) return 2; @@ -5776,7 +5777,15 @@ int main(int argc, char **argv) { if (lastSlash) *lastSlash = 0; else strcpy(scriptSourceDirectory, "."); - int result = ScriptExecuteFromPath(scriptPath, strlen(scriptPath)); + size_t dataBytes; + void *data = FileLoad(scriptPath, &dataBytes); + + if (!data) { + PrintDebug("Error: Could not load the input file '%s'.\n", scriptPath); + return 1; + } + + int result = ScriptExecuteFromFile(scriptPath, strlen(scriptPath), data, dataBytes); while (fixedAllocationBlocks) { void *block = fixedAllocationBlocks;