From d8bdcd4d39633170d53df9f820077622bf97d744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 May 2023 11:23:29 +0800 Subject: [PATCH 1/3] Silence more warnings --- .gitignore | 3 ++- MacDependency/ArchitectureModel.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b90654c..028fedc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ xcuserdata/ # End of https://www.toptal.com/developers/gitignore/api/xcode build/ -build.xcresult/ \ No newline at end of file +build.xcresult/ +/archive.xcarchive diff --git a/MacDependency/ArchitectureModel.h b/MacDependency/ArchitectureModel.h index 3a6c995..7e61ffe 100644 --- a/MacDependency/ArchitectureModel.h +++ b/MacDependency/ArchitectureModel.h @@ -8,7 +8,7 @@ #import #import "MachOModel.h" -#include "macho/machoarchitecture.h" +#include "MachO/machoarchitecture.h" #include "MachO/machoheader.h" @class MyDocument; From 513629474c98f4a426474fefbd126c0567f3d829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 May 2023 11:25:15 +0800 Subject: [PATCH 2/3] Make cached library a warning Ref: https://github.com/kwin/macdependency/issues/15#issuecomment-1272392605 --- MacDependency/MachOModel.mm | 9 ++++----- MachO/internalfile.cpp | 12 +++++++++--- MachO/machoexception.cpp | 5 ++++- MachO/machoexception.h | 3 +++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/MacDependency/MachOModel.mm b/MacDependency/MachOModel.mm index a341663..7c67bfe 100644 --- a/MacDependency/MachOModel.mm +++ b/MacDependency/MachOModel.mm @@ -51,9 +51,8 @@ - (id) initWithFilename:(std::string&)filename command:(DylibCommand*)aCommand d NSString* log = [NSString stringWithFormat:NSLocalizedString(@"ERR_ARCHITECTURE_MISMATCH", nil), filename.c_str(), [parent name]]; [aDocument appendLogLine:log withModel:self state:state]; } - - } catch (MachOException& exc) { - [self setStateWithWarning:isWeakReference]; + } catch (MachOException& exc) { + [self setStateWithWarning:isWeakReference || exc.isWarning()]; NSString* log = [NSString stringWithStdString:exc.getCause()]; [aDocument appendLogLine:log withModel:self state:state]; // distinguish between weak and strong. In both cases append to tree with a status color @@ -176,10 +175,10 @@ - (NSColor*) textColor { NSColor* color; switch(state) { case StateWarning: - color = [NSColor systemOrangeColor]; + color = [NSColor systemYellowColor]; break; case StateError: - color = [NSColor systemOrangeColor]; + color = [NSColor systemRedColor]; break; default: color = [NSColor labelColor]; diff --git a/MachO/internalfile.cpp b/MachO/internalfile.cpp index c138410..5de50a0 100644 --- a/MachO/internalfile.cpp +++ b/MachO/internalfile.cpp @@ -1,6 +1,8 @@ #include "internalfile.h" #include "machoexception.h" +#include + // use reference counting to reuse files for all used architectures InternalFile* InternalFile::create(InternalFile* file) { file->counter++; @@ -24,9 +26,13 @@ filename(filename), counter(1) // open file handle file.open(this->filename, std::ios_base::in | std::ios_base::binary); if (file.fail()) { - std::ostringstream error; - error << "Couldn't open file '" << filename << "'."; - throw MachOException(error.str()); + void* dylib = dlopen(this->filename.c_str(), RTLD_LAZY); + if (dylib) { + dlclose(dylib); + throw MachOException("System cached library '" + filename + "'.", true); + } else { + throw MachOException("Couldn't open file '" + filename + "'."); + } } struct stat buffer; diff --git a/MachO/machoexception.cpp b/MachO/machoexception.cpp index 66ba42c..8496298 100644 --- a/MachO/machoexception.cpp +++ b/MachO/machoexception.cpp @@ -1,6 +1,9 @@ #include "machoexception.h" -MachOException::MachOException(const std::string& cause) : cause(cause) +MachOException::MachOException(const std::string& cause) : cause(cause), warning(false) { } +MachOException::MachOException(const std::string& cause, bool warning) : cause(cause), warning(warning) +{ +} diff --git a/MachO/machoexception.h b/MachO/machoexception.h index a6b3c08..e6580bb 100644 --- a/MachO/machoexception.h +++ b/MachO/machoexception.h @@ -7,9 +7,12 @@ class EXPORT MachOException { public: MachOException(const std::string&); + MachOException(const std::string&, bool warning); const std::string& getCause() { return cause; } + const bool isWarning() { return warning; } private: const std::string cause; + bool warning; }; #endif // MACHOEXCEPTION_H From 95e87efc1e634ed82b24259ecb22b3a2518c0f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 25 May 2023 11:30:25 +0800 Subject: [PATCH 3/3] Bump MACOSX_DEPLOYMENT_TARGET to 10.13 as 10.9 won't work with the latest XCode --- .../MacDependency.xcodeproj/project.pbxproj | 18 ++++++++++++------ .../xcschemes/MacDependency.xcscheme | 2 +- MachO/MachO.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/xcschemes/MachO.xcscheme | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/MacDependency/MacDependency.xcodeproj/project.pbxproj b/MacDependency/MacDependency.xcodeproj/project.pbxproj index fb48979..53f187d 100644 --- a/MacDependency/MacDependency.xcodeproj/project.pbxproj +++ b/MacDependency/MacDependency.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 53; objects = { /* Begin PBXBuildFile section */ @@ -263,7 +263,8 @@ 2A37F4A9FDCFA73011CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1310; + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = "Konrad Windszus"; }; buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "MacDependency" */; @@ -399,11 +400,12 @@ CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; GCC_DYNAMIC_NO_PIC = NO; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = Info.plist; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = MacDependency; SDKROOT = macosx; @@ -416,10 +418,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_OBJC_ARC = YES; CODE_SIGN_IDENTITY = "-"; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; INFOPLIST_FILE = Info.plist; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.13; PRODUCT_BUNDLE_IDENTIFIER = "com.googlecode.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = MacDependency; SDKROOT = macosx; @@ -430,6 +433,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; @@ -450,6 +454,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + DEAD_CODE_STRIPPING = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = c99; @@ -478,7 +483,7 @@ /opt/local/include, ./../, ); - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.13; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; @@ -509,6 +514,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + DEAD_CODE_STRIPPING = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = c99; GCC_NO_COMMON_BLOCKS = YES; @@ -521,7 +527,7 @@ /opt/local/include, ./../, ); - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.13; SDKROOT = macosx; }; name = Release; diff --git a/MacDependency/MacDependency.xcodeproj/xcshareddata/xcschemes/MacDependency.xcscheme b/MacDependency/MacDependency.xcodeproj/xcshareddata/xcschemes/MacDependency.xcscheme index d7d53df..77183b4 100644 --- a/MacDependency/MacDependency.xcodeproj/xcshareddata/xcschemes/MacDependency.xcscheme +++ b/MacDependency/MacDependency.xcodeproj/xcshareddata/xcschemes/MacDependency.xcscheme @@ -1,6 +1,6 @@