-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Changes required for swift-4.1-branch port to Android #1518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ static void _CFBundleEnsureBundlesExistForImagePaths(CFArrayRef imagePaths); | |
|
||
#pragma mark - | ||
|
||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS | ||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID | ||
|
||
// Functions and constants for FHS bundles: | ||
#define _CFBundleFHSDirectory_share CFSTR("share") | ||
|
@@ -162,10 +162,10 @@ static Boolean _CFBundleURLIsForFHSInstalledBundle(CFURLRef bundleURL) { | |
|
||
return isFHSBundle; | ||
} | ||
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS | ||
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID | ||
|
||
Boolean _CFBundleSupportsFHSBundles() { | ||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS | ||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID | ||
return true; | ||
#else | ||
return false; | ||
|
@@ -714,7 +714,7 @@ static CFBundleRef _CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL, | |
|
||
bundle->_url = newURL; | ||
|
||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS | ||
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous comment on finding the other FHS declarations and disabling them still applies, I believe. It will break CFBundle if not so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve gone through the code again and gated anything I could find about FHS out for Android. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a bug in github where I can’t reply directly to your next comment about path(toResource:ofType:) so I’ll add a note here. One of the goals of the Android port is that code for iOS should run on Android and it’s likely that code will use the path(toResource:ofType:) pattern somewhere. On Android It’s up to the Java side of the app to copy resources required into the cache/tmp directory then the Swift/Foundation side can find these resources inside this directory as if it was a bundle so the code runs unmodified. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate the use case, but again, it breaks our contract that Bundle.main be where the resources for a specific bundle actually are (not potentially will be if the author is careful), and that this be a directory that's either specific to the application or at worst contains existing application executable and resource data for that one application. I outlined a workaround above — since apps need to write custom code to copy resources to some filesystem directory, it is no stretch, if they want I will also reiterate that any library code using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also — that breaks if multiple components on Android are using Swift, have equally-named resources or resource directories {which isn't that unlikely: I assume careless copying code could easily clobber an en.lproj folder}, and are running at the same time.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps there just is a misunderstanding here. This is not a system shared directory. It is the app's home, combination Documents and tmp directory on iOS with a path something like: /data/data/com.example.user.myapplication/cache and is the only directory an app has read write access to I am aware of. There's no candidate for a bundle directory other than the approach I suggest of copying resources into this directory on Android as resources are unpacked from their .apk (zip file) on demand. This is what the zip file for an Android app looks like:
Should I mark the whole Bundle api unavailable? There is also no prospect of a OSS fix upstream to Alamofire as the code I’m using is a fork of a fork. If it were me I would make the fix I suggest apply to all Linux systems in the interests of compatibility. If I were to fix Alamofire there just be some other library which falls at this hurdle. But we’ve discussed these issues a few times and we’re going around in circles. What are the minimum changes I have proposed you would have me remove to get this PR merged? I’ll have to maintain a fork (undesirable as that may be) to get what I need to get done done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following changes are, I believe, at issue:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, someone should send Alamofire a patch, I believe. (For the reasons I outlined, Alamofire's code is not well-formed.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK.. how does it look now? |
||
bundle->_isFHSInstalledBundle = _CFBundleURLIsForFHSInstalledBundle(newURL); | ||
#endif | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,10 @@ | |
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#if __has_include(<sys/syslog.h>) | ||
#include <sys/syslog.h> | ||
#elif __has_include(<syslog.h>) | ||
#if __has_include(<syslog.h>) | ||
#include <syslog.h> | ||
#else | ||
#include <sys/syslog.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a minor portability fix. We need a syslog.h but probably not both and if you include sys/syslog.h on android which has syslog.h you can end up including the host os one. |
||
#endif | ||
#include <CoreFoundation/CFURLPriv.h> | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1083,37 +1083,40 @@ class TestNSNumber : XCTestCase { | |
|
||
func test_stringValue() { | ||
|
||
// The following casts on subtraction are required for an Android compile | ||
// https://bugs.swift.org/browse/SR-7469 | ||
|
||
if UInt.max == UInt32.max { | ||
XCTAssertEqual(NSNumber(value: UInt.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt.max).stringValue, "4294967295") | ||
XCTAssertEqual(NSNumber(value: UInt.max - 1).stringValue, "4294967294") | ||
XCTAssertEqual(NSNumber(value: UInt.max - 1 as UInt).stringValue, "4294967294") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this and similar a 32-bit guarantee violation? Why doesn't it work on Android as written? If it is incorrect, it should be diagnosed as incorrect on all platforms to avoid forking the language. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a strange problem indeed which I don’t know the solution for other than the change you see. It doesn’t seem to be 32 bit specific but something not quite right about the compiler and subtraction. I’m seeing warnings I don’t expect and the errors I had to fix with this change. Sources/TestNSNumber.swift:1148:50: warning: '-' is deprecated: Please use explicit type conversions or Strideable methods for mixed-type arithmetics. The compiler is basically built right out of the swift-4.1-branch with only three minor unrelated patches. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is deeply weird with that error, but the fix makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to add a comment for this line (or jira if there is one) as otherwise it may get reverted by someone 'cleaning up' the tests in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need @spevans' suggested comment here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will include in next push |
||
} else if UInt.max == UInt64.max { | ||
XCTAssertEqual(NSNumber(value: UInt.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt.max).stringValue, "18446744073709551615") | ||
XCTAssertEqual(NSNumber(value: UInt.max - 1).stringValue, "18446744073709551614") | ||
XCTAssertEqual(NSNumber(value: UInt.max - 1 as UInt).stringValue, "18446744073709551614") | ||
} | ||
|
||
XCTAssertEqual(NSNumber(value: UInt8.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt8.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt8.max).stringValue, "255") | ||
XCTAssertEqual(NSNumber(value: UInt8.max - 1).stringValue, "254") | ||
XCTAssertEqual(NSNumber(value: UInt8.max - 1 as UInt8).stringValue, "254") | ||
|
||
XCTAssertEqual(NSNumber(value: UInt16.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt16.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt16.max).stringValue, "65535") | ||
XCTAssertEqual(NSNumber(value: UInt16.max - 1).stringValue, "65534") | ||
XCTAssertEqual(NSNumber(value: UInt16.max - 1 as UInt16).stringValue, "65534") | ||
|
||
XCTAssertEqual(NSNumber(value: UInt32.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt32.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt32.max).stringValue, "4294967295") | ||
XCTAssertEqual(NSNumber(value: UInt32.max - 1).stringValue, "4294967294") | ||
XCTAssertEqual(NSNumber(value: UInt32.max - 1 as UInt32).stringValue, "4294967294") | ||
|
||
XCTAssertEqual(NSNumber(value: UInt64.min).stringValue, "0") | ||
XCTAssertEqual(NSNumber(value: UInt64.min + 1).stringValue, "1") | ||
XCTAssertEqual(NSNumber(value: UInt64.max).stringValue, "18446744073709551615") | ||
XCTAssertEqual(NSNumber(value: UInt64.max - 1).stringValue, "18446744073709551614") | ||
XCTAssertEqual(NSNumber(value: UInt64.max - 1 as UInt64).stringValue, "18446744073709551614") | ||
|
||
if Int.max == Int32.max { | ||
XCTAssertEqual(NSNumber(value: Int.min).stringValue, "-2147483648") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Isn't
__android_log_print
enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is helpful when you are running an Android binary (such as the tests) from the command line using an “adb shell". Otherwise NSLogs are only visible using an “adb logcat” by which time the messages have lost their context. This doesn’t affect normal running of an actual application and the logging to stderr goes into the void.