Skip to content

Commit

Permalink
Fix fstat path handling on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansson committed Nov 5, 2023
1 parent 2a7c5bd commit 3817fa9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
7 changes: 7 additions & 0 deletions build/ninja/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '')
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion build/ninja/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions build/ninja/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 8 additions & 8 deletions foundation/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1093,7 +1093,7 @@ fs_monitor_thread(void* monitorptr) {

info = info->NextEntryOffset ?
(PFILE_NOTIFY_INFORMATION)(pointer_offset(info, info->NextEntryOffset)) :
nullptr;
nullptr;
} while (info);
}
}
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 3817fa9

Please sign in to comment.