scripting engine add PathCopyFilteredInto

This commit is contained in:
nakst 2022-02-05 09:29:11 +00:00
parent 129d072a49
commit 01985396c5
3 changed files with 77 additions and 4 deletions

View File

@ -165,7 +165,7 @@ long EsPOSIXSystemCall(long n, long a1, long a2, long a3, long a4, long a5, long
#endif
if ((uintptr_t) n < sizeof(syscallNames) / sizeof(syscallNames[0])) {
EsPrint(":: %z %x %x %x\n", syscallNames[n], a1, a2, a3);
// EsPrint(":: %z %x %x %x\n", syscallNames[n], a1, a2, a3);
}
if (!posixMountPointBase) {

View File

@ -1,4 +1,4 @@
// TODO Replace the remaining few calls to sed/cp.
// TODO Replace the remaining few calls to sed.
#import "util/get_source.script" get_source;
@ -485,7 +485,7 @@ void PortHarfBuzz() {
if !PathExists("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"); // TODO Replace.
assert PathCopyFilteredInto("bin/harfbuzz/src", ["*.h"], -1, "root/Applications/POSIX/include/harfbuzz");
}
if !PathExists("bin/harfbuzz/libharfbuzz_%targetName%.a") {

View File

@ -551,7 +551,80 @@ char baseModuleSource[] = {
" }"
" return true;"
"}"
"bool PathCopyInto(str sourceDirectory, str item, str destinationDirectory) {"
" str sourceItem = sourceDirectory + \"/\"+ item;"
" str destinationItem = destinationDirectory + \"/\"+ item;"
" PathCreateLeadingDirectories(PathGetLeadingDirectories(destinationItem));"
" if PathIsDirectory(sourceItem) {"
" return PathCreateDirectory(destinationItem);"
" } else {"
" return FileCopy(sourceItem, destinationItem);"
" }"
"}"
"bool PathCopyAllInto(str sourceDirectory, str[] items, str destinationDirectory) {"
" for int i = 0; i < items:len(); i += 1 {"
" if !PathCopyInto(sourceDirectory, items[i], destinationDirectory) { return false; }"
" }"
" return true;"
"}"
"bool PathCopyFilteredInto(str sourceDirectory, str[] filter, int filterWildcard, str destinationDirectory) {"
" str[] items;"
" assert filter:len() > 0;"
" if filterWildcard != -1 || filter:len() > 1 { items = DirectoryEnumerateChildrenRecursively(sourceDirectory); }"
" else { items = DirectoryEnumerateChildren(sourceDirectory); }"
" for int i = 0; i < items:len(); i += 1 {"
" if PathMatchesFilter(items[i], filter, filterWildcard) {"
" if !PathCopyInto(sourceDirectory, items[i], destinationDirectory) { return false; }"
" }"
" }"
" return true;"
"}"
"bool PathMatchesFilter(str path, str[] filterComponents, int _filterWildcard) {"
" str[] pathComponents = StringSplitByCharacter(path, \"/\", false);"
" int filterWildcard = _filterWildcard;"
" if filterWildcard == -1 { "
" filterWildcard = pathComponents:len(); "
" }"
" if filterComponents:len() > pathComponents:len() { "
" return false; "
" }"
" for int i = 0; i < filterComponents:len(); i += 1 {"
" str filterComponent = filterComponents[i];"
" str pathComponent;"
" int wildcard = filterComponent:len();"
" if i < filterWildcard { "
" pathComponent = pathComponents[i]; "
" } else { "
" pathComponent = pathComponents[pathComponents:len() - filterComponents:len() + i]; "
" }"
" for int j = 0; j < filterComponent:len(); j += 1 { "
" if filterComponent[j] == \"*\" { "
" wildcard = j; "
" if pathComponent:len() < filterComponent:len() - 1 {"
" return false;"
" }"
" } "
" }"
" for int j = 0; j < filterComponent:len(); j += 1 {"
" if j < wildcard {"
" if filterComponent[j] != pathComponent[j] { return false; }"
" } else if j > wildcard {"
" if filterComponent[j] != pathComponent[pathComponent:len() - filterComponent:len() + j] { return false; }"
" }"
" }"
" }"
" return true;"
"}"
"str PathGetLeadingDirectories(str path) {"
" for int i = path:len() - 1; i >= 0; i -= 1 {"
" if path[i] == \"/\" {"
" return StringSlice(path, 0, i);"
" }"
" }"
" return \"\";"
"}"
// Persistent variables:
"bool PersistRead(str path) #extcall;"