Skip to content

Build Foundation with DEPLOYMENT_RUNTIME_SWIFT disabled #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CoreFoundation/Locale.subproj/CFCalendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#include <CoreFoundation/CFCalendar.h>
#include <CoreFoundation/CFLocaleInternal.h>
#include <CoreFoundation/CFRuntime.h>
#include "CFInternal.h"
#include "CFPriv.h"
Expand Down
1 change: 1 addition & 0 deletions CoreFoundation/Locale.subproj/CFLocale.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Note the header file is in the OpenSource set (stripped to almost nothing), but not the .c file

#include <CoreFoundation/CFInternal.h>
#include <CoreFoundation/CFLocale.h>
#include <CoreFoundation/CFLocale_Private.h>
#include <CoreFoundation/CFString.h>
Expand Down
11 changes: 10 additions & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include <CoreFoundation/CFRuntime.h>
#include <CoreFoundation/CFInternal.h>
#include <libxml/globals.h>
#include <libxml/xmlerror.h>
#include <libxml/parser.h>
Expand All @@ -22,7 +23,7 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/dict.h>
#include "CFInternal.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't use CFInternal.h here at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't removed, it moved up & uses qualified path. Check line 15: <CoreFoundation/CFInternal.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks. Misread the diff.

#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.
Expand Down Expand Up @@ -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) {
Expand All @@ -119,30 +121,36 @@ 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();
// set up the external entity loader
__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;

Expand All @@ -168,6 +176,7 @@ _CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler() {
saxHandler->externalSubset = (externalSubsetSAXFunc)__CFSwiftBridge.NSXMLParser.externalSubset;

saxHandler->initialized = XML_SAX2_MAGIC; // make sure start/endElementNS are used
#endif //if DEPLOYMENT_RUNTIME_SWIFT
return saxHandler;
}

Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit more about what this is doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Lily to review this one. script is a string. items is a list containing strings and lists. On python 2.7 we can not append a list into a string, so we need to walk it, appending the strings on the array.
The comment is to highlight the fact that I found no usage for the nested lists... Not sure what the intended usage was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC: This path is triggered by the += [ … ] command that adds the block runtime, which is invoked if libdispatch is not available. Can you just build libdispatch as part of your CF build instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also fix that command to add single items instead of a list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, for context: this is the portion of build.py that is triggering that behavior:

# This code is already in libdispatch so is only needed if libdispatch is
# NOT being used
if "LIBDISPATCH_SOURCE_DIR" not in Configuration.current.variables:
    sources += (['closure/data.c', 'closure/runtime.c'])

It'd be nice to fix this bit, but in general you want to set your LIBDISPATCH_SOURCE_DIR environment variable correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying LIBDISPATCH_SOURCE_DIR did not work for me. I just auggested a more pythonic way of applying the product commands... hopefully that is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I'm compiling from within CoreFoundation, so the build.py I'm using is in CoreFoundation/build.py, that scripts do not have any references to LIBDISPATCH_SOURCE_DIR.


script += """

Expand Down