Skip to content

Commit

Permalink
Xcode10 support (mac-cain13#468)
Browse files Browse the repository at this point in the history
* Output file instead of dir & remove options for env vars

* Touch last run file first thing at every run

* Validate input/output files given to R.swift

* Fix PR comments on xcode 10 support

* Improvements in Xcode 10 support

- Better exit code
- Link to migration doc in error

* Fix upgrade instructions

* Fix image link in migration doc

* Update dependencies
  • Loading branch information
mac-cain13 authored Dec 11, 2018
1 parent aca3429 commit 3d8fba6
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 109 deletions.
Binary file added Documentation/Images/BuildPhaseExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions Documentation/Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Pointers for migration between major versions.

## Upgrading to 5.0

- In the Build Phase you must perform some changes, [see an example screenshot](Images/BuildPhaseExample.png):
* Change the script to give the explicit output file, for example: `"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"`
* Add `$TEMP_DIR/rswift-lastrun` to the "Input Files" of the Build Phase
* Add `$SRCROOT/R.generated.swift` to the "Output Files" of the Build Phase
- Make sure you use Xcode 10 since we've adjusted to the SDK changes
- At the moment we are compatible with both Swift 4 and 4.2, this is more an accident then a feature, beware that we might drop Swift 4 support anytime.

## Upgrading to 4.0

- Make sure you use Swift 4 / Xcode 9 since we've adjusted to the syntax and SDK changes.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/QandA.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are many nice R.swift alternatives like [SwiftGen](https://github.com/AliS

## What are the requirements to run R.swift?

R.swift works with iOS 8 and tvOS 9 and higher, your development machine should be on OS X 10.11 with Xcode 7 or higher.
R.swift works with Xcode 10 for apps targetting iOS 8 and tvOS 9 and higher.

## How to use methods with a `Void` argument?

Expand Down
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "e34d5687e1e9d865e3527dd58bc2f7464ef6d936",
"version": "0.8.0"
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
}
},
{
"package": "XcodeEdit",
"repositoryURL": "https://github.com/tomlokhorst/XcodeEdit",
"state": {
"branch": null,
"revision": "5c73385537c8546816f0b5c04bb4060e40711046",
"version": "2.4.1"
"revision": "1055ca180cbea0405b2b98707e79872772b7fe7b",
"version": "2.5.0"
}
}
]
Expand Down
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:4.2
import PackageDescription

let package = Package(
Expand All @@ -17,6 +17,5 @@ let package = Package(
dependencies: ["Commander", "XcodeEdit"]
),
.testTarget(name: "RswiftCoreTests", dependencies: ["RswiftCore"]),
],
swiftLanguageVersions: [4]
]
)
40 changes: 10 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@

_Get strong typed, autocompleted resources like images, fonts and segues in Swift projects_

---

### ⚠️ R.swift and Xcode 10 / Swift 4.2
The currently latest release of R.swift (5.0.0.alpha.2) supports Swift 4.2, but with a couple of known issues:

When using the new build system and using R.swift as a build step:
- The initial compile will fail if no output file is configured
- However, when setting an output file, subsequent incremental build won't run the R.swift build step

Current known work-arounds for these issues:
1. Use the Legacy Build System
2. Don't configure an output file, but compile twice (difficult on a CI)
3. Configure an output file, but always do a clean build when an asset has been added (difficult to remember when developing)
4. Commit the R.generated.swift file to source control, so the CI has the lastest version from development

We're working on finding a better solution to these issues, see also: https://github.com/mac-cain13/R.swift/issues/456

---

## Why use this?

It makes your code that uses resources:
Expand Down Expand Up @@ -107,22 +88,18 @@ Runtime validation with [`R.validate()`](Documentation/Examples.md#runtime-valid

_Note on Carthage: R.swift is a tool used in a build step, it is not a dynamic library. Therefore [it is not possible](https://github.com/mac-cain13/R.swift/issues/42) to install it with Carthage._

> ### ⚠️ Change between R.swift 3 and R.swift 4
> Be aware:
> For R.swift 3.x and below, the `rswift` executable should be called with only one argument: `rswift $SRCROOT`
> For R.swift 4, the `rswift` executable should be called with two arguments: `rswift generate $SRCROOT`
### CocoaPods (recommended)

_There is also a [short video](https://vimeo.com/122888912) of this instruction._

1. Add `pod 'R.swift'` to your [Podfile](http://cocoapods.org/#get_started) and run `pod install`
2. In Xcode: Click on your project in the file list, choose your target under `TARGETS`, click the `Build Phases` tab and add a `New Run Script Phase` by clicking the little plus icon in the top left
3. Drag the new `Run Script` phase **above** the `Compile Sources` phase and **below** `Check Pods Manifest.lock`, expand it and paste the following script:
```
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT"
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"
```
4. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`
4. Add `$TEMP_DIR/rswift-lastrun` to the "Input Files" and `$SRCROOT/R.generated.swift` to the "Output Files" of the Build Phase
5. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`

_Screenshot of the Build Phase can be found [here](Documentation/Images/BuildPhaseExample.png)_

_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.

Expand All @@ -133,9 +110,12 @@ _Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent
2. In Xcode: Click on your project in the file list, choose your target under `TARGETS`, click the `Build Phases` tab and add a `New Run Script Phase` by clicking the little plus icon in the top left
3. Drag the new `Run Script` phase **above** the `Compile Sources` phase, expand it and paste the following script:
```
"$SRCROOT/rswift" generate "$SRCROOT"
"$SRCROOT/rswift" generate "$SRCROOT/R.generated.swift"
```
4. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`
4. Add `$TEMP_DIR/rswift-lastrun` to the "Input Files" and `$SRCROOT/R.generated.swift` to the "Output Files" of the Build Phase
5. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`

_Screenshot of the Build Phase can be found [here](Documentation/Images/BuildPhaseExample.png)_

_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.

Expand Down
12 changes: 12 additions & 0 deletions Sources/RswiftCore/CallInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public struct CallInformation {
let bundleIdentifier: String
let productModuleName: String

let scriptInputFiles: [String]
let scriptOutputFiles: [String]
let lastRunURL: URL

private let buildProductsDirURL: URL
private let developerDirURL: URL
private let sourceRootURL: URL
Expand All @@ -40,6 +44,10 @@ public struct CallInformation {
bundleIdentifier: String,
productModuleName: String,

scriptInputFiles: [String],
scriptOutputFiles: [String],
lastRunURL: URL,

buildProductsDirURL: URL,
developerDirURL: URL,
sourceRootURL: URL,
Expand All @@ -57,6 +65,10 @@ public struct CallInformation {
self.bundleIdentifier = bundleIdentifier
self.productModuleName = productModuleName

self.scriptInputFiles = scriptInputFiles
self.scriptOutputFiles = scriptOutputFiles
self.lastRunURL = lastRunURL

self.buildProductsDirURL = buildProductsDirURL
self.developerDirURL = developerDirURL
self.sourceRootURL = sourceRootURL
Expand Down
17 changes: 16 additions & 1 deletion Sources/RswiftCore/RswiftCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ import XcodeEdit
public struct RswiftCore {

static public func run(_ callInformation: CallInformation) throws {
guard callInformation.scriptInputFiles.contains(callInformation.lastRunURL.path) else {
fail("Missing '$(TEMP_DIR)/\(callInformation.lastRunURL.lastPathComponent)' from Input Files. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}

guard callInformation.outputURL.pathExtension == "swift" else {
fail("Output path must be a specific Swift file, folders are not allowed anymore. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}

guard callInformation.scriptOutputFiles.contains(callInformation.outputURL.path) else {
fail("Build phase output files do not contain '\(callInformation.outputURL.path)'. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}

do {
let xcodeproj = try Xcodeproj(url: callInformation.xcodeprojURL)
let ignoreFile = (try? IgnoreFile(ignoreFileURL: callInformation.rswiftIgnoreURL)) ?? IgnoreFile()
Expand Down Expand Up @@ -80,7 +95,7 @@ public struct RswiftCore {
fail("File extension '\(String(describing: givenExtension))' is not one of the supported extensions: \(joinedSupportedExtensions)")
}

exit(3)
exit(EXIT_FAILURE)
}
}
}
2 changes: 1 addition & 1 deletion Sources/RswiftCore/Util/ErrorOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import Foundation

func warn(_ warning: String) {
public func warn(_ warning: String) {
print("warning: [R.swift] \(warning)")
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/rswift/Rswift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import Foundation

struct Rswift {
static let version = "5.0.0.alpha.3"
static let resourceFileName = "R.generated.swift"
static let lastRunFile = "rswift-lastrun"
}
Loading

0 comments on commit 3d8fba6

Please sign in to comment.