Skip to content
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

Adding OSX target #56

Merged
merged 47 commits into from Jun 12, 2016
Merged

Adding OSX target #56

merged 47 commits into from Jun 12, 2016

Conversation

onekiloparsec
Copy link
Contributor

@onekiloparsec onekiloparsec commented Jun 5, 2016

Hi,

This PR is about adding an OSX target. After having looked around and tested various things, I think siesta is one of the best candidates for the app I am preparing. But it's an OSX app. I need an OSX target...

This PR introduces the OSX target. Apart from all UIKit stuff, there are 0 changes (and I've merged upstream). The problem of course is UIKit's stuff. Fortunately it is fairly easy to workaround, since many many classes share the same APIs between the various platforms.

For the cases where it is different, I've written a OSX.swift compatibility file where typealiases are defined (they allow to use the same type everywhere, mapping to the correct one depending on platform). And where I've written the little tricks necessary for the iOS siesta code to NOT change. That is, the tricks are here to adapt OSX interfaces to iOS ones, since I guess iOS remains the main ... target. :-)

I've been able to build an OSX Test target as well. However, given the various dependencies on other thing to build tests, this makes things quite a lot more difficult. In particular, I had to create an OSX target for Nocilla (and change the file Cartfile.private to point to it)

Anyway, I think the constraint of an OSX target is a good occasion to clearly separate class/code concerns/responsabilities. This PR is created maybe a bit toot early, but I wanted to expose/discuss it before siesta reach 1.0, to raise awareness. I am happy to discuss it for any changes and improvements necessary before merge, of course!

Thanks anyway for the great project.

@pcantrell
Copy link
Member

pcantrell commented Jun 5, 2016

Wow, thanks for taking on this huge task! This is fantastic. I’d been wanting to do this for a long time, but had been hoping somebody who knows more about OS X development than me would take it on. Thank you!

I have a new Siesta release coming soon, hopefully next week. My release strategy with this PR would be to get 1.0 beta 7 out the door first, then merge this and add OS X support in beta 8.

Main thoughts below; I’m also adding some minor notes in the code.


UIApplicationDidReceiveMemoryWarningNotification is the showstopper. Low memory events are the only thing that ever clears Siesta’s cache. That’s mostly fine given how Siesta runs in real apps in practice, but even on iOS I’d like to add the ability to limit the cache size — and with it disabled on OS X, the cache will just grow without bound. I filed #31 to fix this, but before this PR came in, it’s been low priority. Once I have 1.0 beta 7 out, I’ll get to work on implementing it.

Long story short: I’ll make sure that this PR and fix for #31 go in the same release.


I’m surprised that the typealias approach works as well as it does. I assumed that ResourceStatusOverlay would have to be totally iOS-specific. Have you sanity checked that your code does in fact work property on OS X? If so, fantastic and wow.

I’m on the fence about how the typealiases should be named. The Swift API guidelines encourage us to move away from the prefixes like BOS in favor of module namespacing. So…

  • Maybe drop the prefix altogether? An alias named Image is effectively named Siesta.Image for other modules. That’s not so bad.
  • Maybe an underscore to emphasize that it’s internal: _Image? But then people will be nervous about using an internal class.
  • Maybe UINSImage? NSUIImage? Clearer. But yuck.

Whatever name we choose will show up in docs and autocomplete, and I don’t want users to get confused by what they see.

Is there a common practice you’ve seen in other Swift frameworks that target both OS X and iOS?


Re Nocilla: I’ve been thinking about dropping it. It’s buggy and full of race conditions, and the maintainer still hasn’t accepted that ancient PR. If you have other HTTP mocking suggestions that work on both platforms, I’m all for it! That shouldn’t hold up this PR, but let me know if you have a preference.

In the meantime, if you submit a PR against my Nocilla PR for the OS X support, I can merge it.

);
name = "Test-only";
name = Frameworks;
Copy link
Member

Choose a reason for hiding this comment

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

Did you just delete the “Test-only” subgroup? That’s fine, I suppose, now that Alamofire is optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I deleted the Test-only subgroup. I really wanted to keep things as exactly as it was, but it took quite a few steps to make sure I had the right frameworks all named the same in the right (build) places. And this subgroup just got deleted. That's the only subgroup deletion I made I think.

Copy link
Member

Choose a reason for hiding this comment

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

I think that’s just fine. It was a minor style point; if it caused any trouble at all, it’s just not worth it.

Copy link
Member

@pcantrell pcantrell Jun 5, 2016

Choose a reason for hiding this comment

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

I have a fix for this that also cleans up some other code. Can you give me push permission for your Siesta fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! You should have received an invite by now.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Just realized I posted my comment on the wrong line note. The fix is for the Error.Cause extension. Now pushed.

@onekiloparsec
Copy link
Contributor Author

Thanks for your great response to the PR. I need to make some more tests on my OSX projects, but so far it works. As for the prefixes, I agree. I used "BOS" since that's the one I found in your code. But if you prefer a more streamlined-swifty way, we go for it! In my other Swift projects I also removed all the prefixes, but that's for types I own. UIKit classes continue to hold their prefix for instance. And since we have here typealiases...

As for Nocilla, I would agree to completely remove it. Actually, the fewer dependencies the better. I have some troubles running the tests right now, but I'll try to find another way.

I realise there is quite a bit of work left. Although I am enthusiastic to see this PR pushing things forward, it will require some more time.

@pcantrell
Copy link
Member

The BOS prefix only shows up on the Obj-C side of Siesta. Or should, anyway.

UIKit classes continue to hold their prefix for instance

There’s a swift-evolution proposal to remove the NS prefix from many of the Foundation classes, and I suspect others frameworks may go that direction.

I realise there is quite a bit of work left.

Yes, but you’ve done a tremendous amount, and things are already looking pretty good here.

@onekiloparsec
Copy link
Contributor Author

I have some troubles making the ResourceStatusOverlay work. And wondering... is this really the core of Siesta? It adds a lot of troubles (in addition of me not understanding how the xib is really hooked up).

But I'd love to keep the logic of it, with state changes. One just need to remove the UI part. At least, for OSX the whole coverParent stuff is not really useful anyway.

@pcantrell
Copy link
Member

Yes, I suspected it might be hard to get that code working on both platforms at once. Thanks for giving it a try.

I had loose plans to separate the UIKit stuff into a separate module — either within this repo or as a separate library altogether. In addition to the cross-platform reasons, it will also make things better for SwiftPM. I already have some sketches of splitting the purely logical state transition stuff in ResourceStatusOverlay apart from the UIKit stuff, so there could eventually be separate iOS and OS X UI helpers that share some core logic.

However, all of that is a big, messy change, and I don’t want this PR to snowball. How about this revised plan?

  • For this PR, just bracket all of ResourceStatusOverlay with #if os(iOS). No UI helpers on OS X for the time being.
  • This should remove the need for all of the cross-platform typealiases and extensions except for MemoryWarningNotification. Move the MemoryWarningNotification typealias into WeakCache.swift and delete the rest of Platforms.swift. (It will still be there in the history if we want to resurrect it in the future.)
  • At that point, this PR would be ready to merge.

Follow-ups would be:

  1. Fix More flexible Resource cache eviction policy #31
  2. Reorganize project/directory structure to platform-specific UI code from core
  3. Split state transition logic out of ResourceStatusOverlay
  4. Write OS X resource status UI helper

Of those, I think 1 and 2 should be done before releasing a beta with OS X support, but 3 and 4 could be done at leisure.

@onekiloparsec
Copy link
Contributor Author

I'm glad to basically agree with everything. I will push the small changes to merge the PR asap.

@onekiloparsec
Copy link
Contributor Author

onekiloparsec commented Jun 11, 2016

I made the changes, which means basically getting rid of all the OSX work I did at first. But that's life. :-) I deleted the OSX tests target as well, as it doesn't make real sense to keep all typealiases just to run the tests (I must say I haven't read much the details of the tests, just that UIViews are used).

I also had to keep the typealias for (NS/UI)Image, because it is used in the ImageResponseTransformer.

@pcantrell
Copy link
Member

I made the changes, which means basically getting rid of all the OSX work I did at first. But that's life. :-)

Hopefully some of that investigation you did does pay off in the future, though, when building OS X UI helpers.

I deleted the OSX tests target as well, as it doesn't make real sense to keep all typealiases just to run the tests (I must say I haven't read much the details of the tests, just that UIViews are used).

No, we should keep the OS X tests! I definitely don’t want to have an untested target in the project.

The only usages of UIView in the specs were as dummy objects (something that can’t be transformed by JSON, for example). You should be able to replace all of those with some arbitrary class from Foundation that wouldn’t normally show up in a response entity.

Feel free to revert 0ccfb2f & force push to fix that.

I also had to keep the typealias for (NS/UI)Image, because it is used in the ImageResponseTransformer.

Right, of course.

@onekiloparsec
Copy link
Contributor Author

Ok I will put osx tests back

@pcantrell
Copy link
Member

OK. I didn’t want to remove that commit from here because I don’t want to mess up your local git history — but once 0ccfb2f is gone, I can fix up the usages of UIView in the specs if you want.

We’re close!

@onekiloparsec
Copy link
Contributor Author

I'm glad I made an atomic commit on that matter. So I did a revert, and changed UIView classes for NSData in tests. On my side, I can run both iOS and OSX tests, and they all pass.

Yes, we're close!

@onekiloparsec
Copy link
Contributor Author

Hm, Travis says it fails. But I couldn't find the error.

@onekiloparsec
Copy link
Contributor Author

onekiloparsec commented Jun 12, 2016

Got it. Yesterday I renamed the iOS scheme without changing the .travis file. Bad idea. I reverted to the old scheme name.

@onekiloparsec
Copy link
Contributor Author

BTW, https://github.com/AliSoftware/OHHTTPStubs seems a good candidate to ditch out Nocilla.

@pcantrell
Copy link
Member

pcantrell commented Jun 12, 2016

I think we’re there! Given that feedback on the pipeline API has been slow and this has moved fast, I’m going to cut a release with this instead and move the pipeline stuff back to a subsequent beta.


Your scheme renaming was a good idea. I checked some other multi-platform projects, and they do the same. I renamed the targets too, and got the travis file updated. (Don’t look in there. It’s horrid.)


Found a race condition in one of the specs. Don’t know if it’s a timing difference on OS X, or if it allows more simultaneous connections per host by default and that's what caused it. Regardless, one spec was failing about 3% of the time on OS X. Now fixed.

I’m still seeing sporadic build failures from Travis … but I blame Travis itself. Its Xcode environment has all kinds of weird timeout issues. Failed builds almost always pass if I rerun them. It’s possible this might be an issue with Siesta and not Travis, but I never have these problems locally.

@pcantrell pcantrell merged commit 0aaf8ef into bustoutsolutions:master Jun 12, 2016
@pcantrell
Copy link
Member

And we’re there! Merci bien @onekiloparsec for getting this through!

@pcantrell pcantrell mentioned this pull request Jun 12, 2016
5 tasks
@onekiloparsec
Copy link
Contributor Author

Avec plaisir! If I have time, I'll keep an eye on the Nocilla replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants