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

Add support On Demand Resources #753

Merged
merged 12 commits into from
Jan 20, 2020

Conversation

sipao
Copy link
Contributor

@sipao sipao commented Jan 15, 2020

Resolves #750

sources:
  - path: example.mp4
    resourceTags: ["example", "movie"]

If the file exists directly under Foo and Foo is specified in the sources, need to use excluded.

sources:
  - path: Foo
    excludes:
      - "example.mp4"
  - path: Foo/example.mp4
    resourceTags: ["example", "movie"]

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you @sipao!
I left some very minor comments above.

Could you also add a couple of things:

In regards to the example in your comment, if you switch the order of the sources, you shouldn't need the excludes, as sources are processed in order, and if a previous source file has already been generated it will just use that cached version

Docs/ProjectSpec.md Outdated Show resolved Hide resolved
.map { target in
target.sources.map { $0.resourceTags }.flatMap { $0 }
}.flatMap { $0 }
))
Copy link
Owner

Choose a reason for hiding this comment

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

Let's sort them as well, so it's deterministic. If you add a sorted() on the end, then the Array initializer isn't needed either, as sorted returns an array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -85,6 +85,7 @@ class SourceGenerator {
let fileReference = fileReference ?? fileReferencesByPath[path.string.lowercased()]!
var settings: [String: Any] = [:]
var attributes: [String] = targetSource.attributes
let resourceTags: [String] = targetSource.resourceTags
Copy link
Owner

Choose a reason for hiding this comment

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

This resourceTags property is only used once, so let's just remove it and access targetSource.resourceTags inline down below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let projectAttributes: [String: Any] = ["LastUpgradeCheck": project.xcodeVersion]
.merged(project.attributes)
.merged(["knownAssetTags" : assetTags])
Copy link
Owner

Choose a reason for hiding this comment

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

Only add this if assetTags is not empty, otherwise we'll cause a diff in the project

Copy link
Owner

Choose a reason for hiding this comment

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

(This is why the tests are failing by the way)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -124,6 +125,10 @@ class SourceGenerator {
if !attributes.isEmpty {
settings["ATTRIBUTES"] = attributes
}

if !resourceTags.isEmpty {
settings["ASSET_TAGS"] = resourceTags
Copy link
Owner

Choose a reason for hiding this comment

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

Let's also only add these if chosenBuildPhase == .resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -192,6 +195,7 @@ extension TargetSource: JSONObjectConvertible {

createIntermediateGroups = jsonDictionary.json(atKeyPath: "createIntermediateGroups")
attributes = jsonDictionary.json(atKeyPath: "attributes") ?? []
resourceTags = jsonDictionary.json(atKeyPath: "resourceTags") ?? []
Copy link
Owner

Choose a reason for hiding this comment

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

You'll need to add a line in toJSONValue down below as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sipao
Copy link
Contributor Author

sipao commented Jan 16, 2020

Thanks for your review, @yonaskolb!

I fixed issues you reviewed.

@sipao sipao requested a review from yonaskolb January 20, 2020 08:59
Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

Great, thanks @sipao!

@yonaskolb yonaskolb merged commit 3a9131a into yonaskolb:master Jan 20, 2020
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.

Setting On-Demand-Resource Tags
2 participants