From 3817fa9a616806f0e093d2c2134e00fc7e2b81c6 Mon Sep 17 00:00:00 2001 From: Mattias Jansson Date: Sun, 5 Nov 2023 17:44:57 +0100 Subject: [PATCH] Fix fstat path handling on Windows --- build/ninja/generator.py | 7 +++++++ build/ninja/msvc.py | 2 +- build/ninja/toolchain.py | 4 +--- configure.py | 3 +-- foundation/fs.c | 16 ++++++++-------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/build/ninja/generator.py b/build/ninja/generator.py index 5de7ec1e..1296265b 100755 --- a/build/ninja/generator.py +++ b/build/ninja/generator.py @@ -43,6 +43,9 @@ def __init__(self, project, includepaths = [], dependlibs = [], libpaths = [], v parser.add_argument('--subninja', action='store', help = 'Build as subproject (exclude rules and pools) with the given subpath', default = '') + parser.add_argument('--notests', action='store_true', + help = 'Skip building the internal tests', + default = False) parser.add_argument('--buildprefs', action='store', help = 'Read the given build preferences file', default = '') @@ -58,6 +61,7 @@ def __init__(self, project, includepaths = [], dependlibs = [], libpaths = [], v self.target = platform.Platform(options.target) self.host = platform.Platform(options.host) self.subninja = options.subninja + self.notests = options.notests archs = options.arch configs = options.config if includepaths is None: @@ -127,6 +131,9 @@ def writer(self): def is_subninja(self): return self.subninja != '' + def skip_tests(self): + return self.notests + def lib(self, module, sources, libname = None, basepath = None, configs = None, includepaths = None, variables = None): return self.toolchain.lib(self.writer, module, sources, libname, basepath, configs, includepaths, variables) diff --git a/build/ninja/msvc.py b/build/ninja/msvc.py index 9f9d13af..ab486fa9 100755 --- a/build/ninja/msvc.py +++ b/build/ninja/msvc.py @@ -31,7 +31,7 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths self.linkcmd = '$toolchain$link $libpaths $configlibpaths $linkflags $linkarchflags $linkconfigflags /DEBUG /NOLOGO /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MANIFEST /MANIFESTUAC:\"level=\'asInvoker\' uiAccess=\'false\'\" /TLBID:1 /PDB:$pdbpath /OUT:$out $in $libs $archlibs $oslibs' self.dllcmd = self.linkcmd + ' /DLL' - self.cflags = ['/D', '"' + project.upper() + '_COMPILE=1"', '/D', '"_UNICODE"', '/D', '"UNICODE"', '/std:c17', '/Zi', '/Oi', '/Oy-', '/GS-', '/Gy-', '/Qpar-', '/fp:fast', '/fp:except-', '/Zc:forScope', '/Zc:wchar_t', '/GR-', '/openmp-'] + self.cflags = ['/D', '"' + project.upper() + '_COMPILE=1"', '/D', '"_UNICODE"', '/D', '"UNICODE"', '/std:c17', '/experimental:c11atomics', '/Zi', '/Oi', '/Oy-', '/GS-', '/Gy-', '/Qpar-', '/fp:fast', '/fp:except-', '/Zc:forScope', '/Zc:wchar_t', '/GR-', '/openmp-'] self.cwarnflags = ['/W4', '/WX', '/wd4201'] #Ignore nameless union/struct which is allowed in C11 self.cmoreflags = [] self.arflags = ['/ignore:4221'] #Ignore empty object file warning] diff --git a/build/ninja/toolchain.py b/build/ninja/toolchain.py index 2f7e395f..3e5072be 100755 --- a/build/ninja/toolchain.py +++ b/build/ninja/toolchain.py @@ -405,10 +405,8 @@ def build_sources(self, writer, nodetype, multitype, module, sources, binfile, b sourcevariables = (variables or {}).copy() sourcevariables.update({ 'includepaths': self.depend_includepaths + self.prefix_includepaths(list(includepaths))}) - if not libs and dependlibs != None: + if not libs: libs = [] - if dependlibs != None: - libs = (dependlibs or []) + libs nodevariables = (variables or {}).copy() nodevariables.update({ 'libs': libs, diff --git a/configure.py b/configure.py index 16f7f8f0..92baf5ce 100755 --- a/configure.py +++ b/configure.py @@ -37,8 +37,7 @@ test_lib = generator.lib(module = 'test', basepath = 'test', sources = ['test.c', 'test.m'], includepaths = includepaths) mock_lib = generator.lib(module = 'mock', basepath = 'test', sources = ['mock.c'], includepaths = includepaths) -#No test cases if we're a submodule -if generator.is_subninja(): +if generator.skip_tests(): sys.exit() test_cases = [ diff --git a/foundation/fs.c b/foundation/fs.c index bfabfd18..e3cebf21 100644 --- a/foundation/fs.c +++ b/foundation/fs.c @@ -620,14 +620,14 @@ fs_stat(const char* path, size_t length) { BOOL success = 0; string_const_t cpath = fs_strip_protocol(path, length); if (cpath.length) { - /* - wchar_t* wpath = wstring_allocate_from_string(STRING_ARGS(cpath)); - success = GetFileAttributesExW(wpath, GetFileExInfoStandard, &attrib); - wstring_deallocate(wpath); - */ char buffer[BUILD_MAX_PATHLEN]; - string_t cleanpath = string_copy(buffer, sizeof(buffer), path, length); + string_t cleanpath = string_copy(buffer, sizeof(buffer), STRING_ARGS(cpath)); success = GetFileAttributesExA(cleanpath.str, GetFileExInfoStandard, &attrib); + if (!success) { + wchar_t* wpath = wstring_allocate_from_string(STRING_ARGS(cpath)); + success = GetFileAttributesExW(wpath, GetFileExInfoStandard, &attrib); + wstring_deallocate(wpath); + } } if (success) { fsstat.size = ((uint64_t)attrib.nFileSizeHigh << 32ULL) + attrib.nFileSizeLow; @@ -1093,7 +1093,7 @@ fs_monitor_thread(void* monitorptr) { info = info->NextEntryOffset ? (PFILE_NOTIFY_INFORMATION)(pointer_offset(info, info->NextEntryOffset)) : - nullptr; + nullptr; } while (info); } } @@ -1382,7 +1382,7 @@ fs_file_seek(stream_t* stream, ssize_t offset, stream_seek_mode_t direction) { if (SetFilePointerEx(GET_FILE(stream)->fd, large_offset, 0, (direction == STREAM_SEEK_BEGIN) ? FILE_BEGIN : - ((direction == STREAM_SEEK_END) ? FILE_END : FILE_CURRENT)) == INVALID_SET_FILE_POINTER) { + ((direction == STREAM_SEEK_END) ? FILE_END : FILE_CURRENT)) == INVALID_SET_FILE_POINTER) { log_warnf(0, WARNING_SYSTEM_CALL_FAIL, STRING_CONST("Unable to seek to %" PRId64 ":%d in stream '%.*s'"), (int64_t)offset, (int)direction, STRING_FORMAT(stream->path)); }