From 515cd699aca93c845e57a04c14075f57f1cbde9a Mon Sep 17 00:00:00 2001 From: Misha Bunte Date: Tue, 15 Jul 2025 14:14:28 +0800 Subject: [PATCH] compile_database: fix missing iOS flags for SwiftPM packages If a checkout lacks a local `.compile-*`, _InferFlagsForSwift_ now re-searches from cwd. This picks up the workspace-level `.compile` written for SourcePackages and stops library files from falling back to macOS SDK. --- compile_database.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compile_database.py b/compile_database.py index 7fa7b0d..316c313 100644 --- a/compile_database.py +++ b/compile_database.py @@ -150,10 +150,11 @@ def filterFlags(items, fileCache): pass -def findSwiftModuleRoot(filename): +def findSwiftModuleRoot(filename, directory=None): """return project root or None. if not found""" filename = os.path.abspath(filename) - directory = os.path.dirname(filename) + if not directory: + directory = os.path.dirname(filename) flagFile = None compileFile = None while directory and directory != "/": @@ -352,6 +353,10 @@ def GetFlags(filename: str, compileFile=None, store=None): def InferFlagsForSwift(filename, compileFile, store): """try infer flags by convention and workspace files""" project_root, flagFile, compileFile = findSwiftModuleRoot(filename) + if not compileFile: + # search for workspace from current directory if no compile file found + project_root, flagFile, compileFile = findSwiftModuleRoot(filename, directory=os.getcwd()) + logging.debug(f"infer root: {project_root}, {compileFile}") final_flags = GetFlagsInCompile(filename, compileFile, store)