mirror of https://gitlab.com/nakst/essence
add PathCreateLeadingDirectories to script engine
This commit is contained in:
parent
91ae02eb8b
commit
fbab565c91
|
@ -56,14 +56,11 @@ void Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create folders.
|
// Create folders.
|
||||||
assert PathCreateDirectory("bin");
|
assert PathCreateLeadingDirectories("bin");
|
||||||
assert PathCreateDirectory("root");
|
assert PathCreateLeadingDirectories("root/Essence");
|
||||||
assert PathCreateDirectory("root/Essence");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/bin");
|
||||||
assert PathCreateDirectory("root/Applications");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/include");
|
||||||
assert PathCreateDirectory("root/Applications/POSIX");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/lib");
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/bin");
|
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/include");
|
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/lib");
|
|
||||||
|
|
||||||
// Load the persistent variables.
|
// Load the persistent variables.
|
||||||
assert PersistRead("bin/build_gcc_state.dat");
|
assert PersistRead("bin/build_gcc_state.dat");
|
||||||
|
|
|
@ -25,7 +25,7 @@ void Start() {
|
||||||
"find . -type f -exec %sed% -i 's/#include <%headers[i]%.h>/#include <essence.h>/g' {} \\;");
|
"find . -type f -exec %sed% -i 's/#include <%headers[i]%.h>/#include <essence.h>/g' {} \\;");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/include/harfbuzz");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/include/harfbuzz");
|
||||||
assert SystemShellExecute("cp -p bin/harfbuzz/src/*.h root/Applications/POSIX/include/harfbuzz");
|
assert SystemShellExecute("cp -p bin/harfbuzz/src/*.h root/Applications/POSIX/include/harfbuzz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,8 @@ void Start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if install {
|
if install {
|
||||||
assert PathCreateDirectory("root");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/lib");
|
||||||
assert PathCreateDirectory("root/Applications");
|
assert PathCreateLeadingDirectories("root/Applications/POSIX/include");
|
||||||
assert PathCreateDirectory("root/Applications/POSIX");
|
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/lib");
|
|
||||||
assert PathCreateDirectory("root/Applications/POSIX/include");
|
|
||||||
|
|
||||||
assert FileCopy("ports/musl/libc.a", "root/Applications/POSIX/lib/libc.a");
|
assert FileCopy("ports/musl/libc.a", "root/Applications/POSIX/lib/libc.a");
|
||||||
assert FileCopy("ports/musl/empty.a", "root/Applications/POSIX/lib/libm.a");
|
assert FileCopy("ports/musl/empty.a", "root/Applications/POSIX/lib/libm.a");
|
||||||
|
|
|
@ -6,8 +6,7 @@ void Get(str url, str directoryName, str checksum) {
|
||||||
assert url != "";
|
assert url != "";
|
||||||
assert directoryName != "";
|
assert directoryName != "";
|
||||||
|
|
||||||
assert PathCreateDirectory("bin");
|
assert PathCreateLeadingDirectories("bin/cache");
|
||||||
assert PathCreateDirectory("bin/cache");
|
|
||||||
assert PathDeleteRecursively("bin/source");
|
assert PathDeleteRecursively("bin/source");
|
||||||
|
|
||||||
str url2 = "";
|
str url2 = "";
|
||||||
|
|
|
@ -357,6 +357,7 @@ char baseModuleSource[] = {
|
||||||
|
|
||||||
"bool PathExists(str x) #extcall;"
|
"bool PathExists(str x) #extcall;"
|
||||||
"bool PathCreateDirectory(str x) #extcall;" // TODO Replace the return value with a enum.
|
"bool PathCreateDirectory(str x) #extcall;" // TODO Replace the return value with a enum.
|
||||||
|
"bool PathCreateLeadingDirectories(str x) #extcall;"
|
||||||
"bool PathDelete(str x) #extcall;" // TODO Replace the return value with a enum.
|
"bool PathDelete(str x) #extcall;" // TODO Replace the return value with a enum.
|
||||||
"bool PathDeleteRecursively(str x) #extcall;"
|
"bool PathDeleteRecursively(str x) #extcall;"
|
||||||
"bool PathMove(str source, str destination) #extcall;"
|
"bool PathMove(str source, str destination) #extcall;"
|
||||||
|
@ -397,6 +398,7 @@ int ExternalSystemGetProcessorCount(ExecutionContext *context, Value *returnValu
|
||||||
int ExternalSystemGetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
int ExternalSystemGetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
||||||
int ExternalSystemSetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
int ExternalSystemSetEnvironmentVariable(ExecutionContext *context, Value *returnValue);
|
||||||
int ExternalPathCreateDirectory(ExecutionContext *context, Value *returnValue);
|
int ExternalPathCreateDirectory(ExecutionContext *context, Value *returnValue);
|
||||||
|
int ExternalPathCreateLeadingDirectories(ExecutionContext *context, Value *returnValue);
|
||||||
int ExternalPathDelete(ExecutionContext *context, Value *returnValue);
|
int ExternalPathDelete(ExecutionContext *context, Value *returnValue);
|
||||||
int ExternalPathDeleteRecursively(ExecutionContext *context, Value *returnValue);
|
int ExternalPathDeleteRecursively(ExecutionContext *context, Value *returnValue);
|
||||||
int ExternalPathExists(ExecutionContext *context, Value *returnValue);
|
int ExternalPathExists(ExecutionContext *context, Value *returnValue);
|
||||||
|
@ -424,6 +426,7 @@ ExternalFunction externalFunctions[] = {
|
||||||
{ .cName = "SystemSetEnvironmentVariable", .callback = ExternalSystemSetEnvironmentVariable },
|
{ .cName = "SystemSetEnvironmentVariable", .callback = ExternalSystemSetEnvironmentVariable },
|
||||||
{ .cName = "PathExists", .callback = ExternalPathExists },
|
{ .cName = "PathExists", .callback = ExternalPathExists },
|
||||||
{ .cName = "PathCreateDirectory", .callback = ExternalPathCreateDirectory },
|
{ .cName = "PathCreateDirectory", .callback = ExternalPathCreateDirectory },
|
||||||
|
{ .cName = "PathCreateLeadingDirectories", .callback = ExternalPathCreateLeadingDirectories },
|
||||||
{ .cName = "PathDelete", .callback = ExternalPathDelete },
|
{ .cName = "PathDelete", .callback = ExternalPathDelete },
|
||||||
{ .cName = "PathDeleteRecursively", .callback = ExternalPathDeleteRecursively },
|
{ .cName = "PathDeleteRecursively", .callback = ExternalPathDeleteRecursively },
|
||||||
{ .cName = "PathMove", .callback = ExternalPathMove },
|
{ .cName = "PathMove", .callback = ExternalPathMove },
|
||||||
|
@ -4050,6 +4053,39 @@ int ExternalPathCreateDirectory(ExecutionContext *context, Value *returnValue) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ExternalPathCreateLeadingDirectories(ExecutionContext *context, Value *returnValue) {
|
||||||
|
(void) returnValue;
|
||||||
|
if (context->stackPointer < 1) return -1;
|
||||||
|
uint64_t index = context->stack[--context->stackPointer].i;
|
||||||
|
if (!context->stackIsManaged[context->stackPointer]) return -1;
|
||||||
|
if (context->heapEntriesAllocated <= index) return -1;
|
||||||
|
HeapEntry *entry = &context->heap[index];
|
||||||
|
returnValue->i = 0;
|
||||||
|
if (entry->type == T_EOF) return 2;
|
||||||
|
if (entry->type != T_STR) return -1;
|
||||||
|
char *temporary = malloc(entry->bytes + 1);
|
||||||
|
if (!temporary) return 2;
|
||||||
|
memcpy(temporary, entry->text, entry->bytes);
|
||||||
|
temporary[entry->bytes] = 0;
|
||||||
|
returnValue->i = 1;
|
||||||
|
#ifdef _WIN32
|
||||||
|
#pragma message ("ExternalPathCreateLeadingDirectories unimplemented")
|
||||||
|
returnValue->i = 0;
|
||||||
|
#else
|
||||||
|
for (uintptr_t i = 1; i < entry->bytes; i++) {
|
||||||
|
if (temporary[i] == '/') {
|
||||||
|
temporary[i] = 0;
|
||||||
|
mkdir(temporary, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
temporary[i] = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mkdir(temporary, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) returnValue->i = errno == EEXIST;
|
||||||
|
#endif
|
||||||
|
free(temporary);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
int ExternalPathDelete(ExecutionContext *context, Value *returnValue) {
|
int ExternalPathDelete(ExecutionContext *context, Value *returnValue) {
|
||||||
(void) returnValue;
|
(void) returnValue;
|
||||||
if (context->stackPointer < 1) return -1;
|
if (context->stackPointer < 1) return -1;
|
||||||
|
|
Loading…
Reference in New Issue