From 4dc32169b87204af97b5133c7bd1cc0b55ad2364 Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Tue, 22 May 2018 14:37:15 -0700 Subject: [PATCH 1/3] Allow compilation of CF on more Linux platforms when DEPLOYMENT_RUNTIME_SWIFT is disabled. --- CoreFoundation/Locale.subproj/CFCalendar.c | 1 + CoreFoundation/Locale.subproj/CFLocale.c | 1 + CoreFoundation/Parsing.subproj/CFXMLInterface.c | 13 ++++++++++++- CoreFoundation/build.py | 2 +- lib/script.py | 10 +++++++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CoreFoundation/Locale.subproj/CFCalendar.c b/CoreFoundation/Locale.subproj/CFCalendar.c index 5332e96dbc..d02cf4b7cb 100644 --- a/CoreFoundation/Locale.subproj/CFCalendar.c +++ b/CoreFoundation/Locale.subproj/CFCalendar.c @@ -10,6 +10,7 @@ #include +#include #include #include "CFInternal.h" #include "CFPriv.h" diff --git a/CoreFoundation/Locale.subproj/CFLocale.c b/CoreFoundation/Locale.subproj/CFLocale.c index 10013909c9..78b072a8df 100644 --- a/CoreFoundation/Locale.subproj/CFLocale.c +++ b/CoreFoundation/Locale.subproj/CFLocale.c @@ -10,6 +10,7 @@ // Note the header file is in the OpenSource set (stripped to almost nothing), but not the .c file +#include #include #include #include diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c index f48c1e4c76..fcd4b0131f 100644 --- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c +++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -22,7 +23,7 @@ #include #include #include -#include "CFInternal.h" +#include "CFXMLInterface.h" /* libxml2 does not have nullability annotations and does not import well into swift when given potentially differing versions of the library that might be installed on the host operating system. This is a simple C wrapper to simplify some of that interface layer to libxml2. @@ -110,6 +111,7 @@ typedef struct { xmlNotationPtr notation; } _cfxmlNotation; +#if DEPLOYMENT_RUNTIME_SWIFT static xmlExternalEntityLoader __originalLoader = NULL; static xmlParserInputPtr _xmlExternalEntityLoader(const char *urlStr, const char * ID, xmlParserCtxtPtr context) { @@ -119,8 +121,10 @@ static xmlParserInputPtr _xmlExternalEntityLoader(const char *urlStr, const char } return __originalLoader(urlStr, ID, context); } +#endif // DEPLOYMENT_RUNTIME_SWIFT void _CFSetupXMLInterface(void) { +#if DEPLOYMENT_RUNTIME_SWIFT static dispatch_once_t xmlInitGuard; dispatch_once(&xmlInitGuard, ^{ xmlInitParser(); @@ -128,21 +132,25 @@ void _CFSetupXMLInterface(void) { __originalLoader = xmlGetExternalEntityLoader(); xmlSetExternalEntityLoader(_xmlExternalEntityLoader); }); +#endif // DEPLOYMENT_RUNTIME_SWIFT } _CFXMLInterfaceParserInput _CFXMLInterfaceNoNetExternalEntityLoader(const char *URL, const char *ID, _CFXMLInterfaceParserContext ctxt) { return xmlNoNetExternalEntityLoader(URL, ID, ctxt); } +#if DEPLOYMENT_RUNTIME_SWIFT static void _errorCallback(void *ctx, const char *msg, ...) { xmlParserCtxtPtr context = __CFSwiftBridge.NSXMLParser.getContext((_CFXMLInterface)ctx); xmlErrorPtr error = xmlCtxtGetLastError(context); // TODO: reporting // _reportError(error, (_CFXMLInterface)ctx); } +#endif // DEPLOYMENT_RUNTIME_SWIFT _CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() { _CFXMLInterfaceSAXHandler saxHandler = (_CFXMLInterfaceSAXHandler)calloc(1, sizeof(struct _xmlSAXHandler)); +#if DEPLOYMENT_RUNTIME_SWIFT saxHandler->internalSubset = (internalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.internalSubset; saxHandler->isStandalone = (isStandaloneSAXFunc)__CFSwiftBridge.NSXMLParser.isStandalone; @@ -168,6 +176,9 @@ _CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() { saxHandler->externalSubset = (externalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.externalSubset; saxHandler->initialized = XML_SAX2_MAGIC; // make sure start/endElementNS are used +#else + memset(&saxHandler, 0, sizeof(saxHandler)); +#endif //if DEPLOYMENT_RUNTIME_SWIFT return saxHandler; } diff --git a/CoreFoundation/build.py b/CoreFoundation/build.py index 046babba09..c105fc0782 100755 --- a/CoreFoundation/build.py +++ b/CoreFoundation/build.py @@ -293,7 +293,7 @@ 'String.subproj/CFRegularExpression.c', 'String.subproj/CFAttributedString.c', 'String.subproj/CFRunArray.c', - 'Base.subproj/CFKnownLocations.h', + 'Base.subproj/CFKnownLocations.c', ] sources = CompileSources(sources_list) diff --git a/lib/script.py b/lib/script.py index 27948f321e..16a170095b 100644 --- a/lib/script.py +++ b/lib/script.py @@ -226,7 +226,15 @@ def generate_products(self): script = flags + commands for product in self.products: - script += product.generate() + items = product.generate() + for item in items: + if isinstance(item, list): + for subitem in item: + #TODO: What to do with this elements? + #script += subitem + continue + else: + script += item script += """ From d3ce07c1e18f4273882ae4852ec62cdd811443c8 Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Tue, 22 May 2018 16:28:02 -0700 Subject: [PATCH 2/3] parkera's feedback: remove unnecessary memset. --- CoreFoundation/Parsing.subproj/CFXMLInterface.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/CoreFoundation/Parsing.subproj/CFXMLInterface.c b/CoreFoundation/Parsing.subproj/CFXMLInterface.c index fcd4b0131f..c21e354c9f 100644 --- a/CoreFoundation/Parsing.subproj/CFXMLInterface.c +++ b/CoreFoundation/Parsing.subproj/CFXMLInterface.c @@ -176,8 +176,6 @@ _CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() { saxHandler->externalSubset = (externalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.externalSubset; saxHandler->initialized = XML_SAX2_MAGIC; // make sure start/endElementNS are used -#else - memset(&saxHandler, 0, sizeof(saxHandler)); #endif //if DEPLOYMENT_RUNTIME_SWIFT return saxHandler; } From 3561f56f7c7dbbaf265c4ffdd562f73d8b9f2008 Mon Sep 17 00:00:00 2001 From: Mario Vera Date: Wed, 23 May 2018 17:04:16 -0700 Subject: [PATCH 3/3] Apply product commands in a more pythonic way --- lib/script.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/script.py b/lib/script.py index 16a170095b..2533fa8d4b 100644 --- a/lib/script.py +++ b/lib/script.py @@ -226,15 +226,7 @@ def generate_products(self): script = flags + commands for product in self.products: - items = product.generate() - for item in items: - if isinstance(item, list): - for subitem in item: - #TODO: What to do with this elements? - #script += subitem - continue - else: - script += item + script += "".join([product_build_command for product_build_command in product.generate() if not isinstance(product_build_command, list)]) script += """