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

Support optional include #712

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

giginet
Copy link
Collaborator

@giginet giginet commented Nov 8, 2019

Motivation

I want to add targets dynamically. including subspecs help me in the situation.
The included spec is automatically generated and if not exists ignore adding targets.

Description

I added optional option to Include.
This value indicates whether ignoring failure loading (e.g. the path does not exist).

include:
  - path: not_exist.yml
    optional: true
name: OptionalInclude
targets:
  IncludedTarget:
    type: application
    platform: iOS
    sources:
      - template

@giginet giginet requested a review from yonaskolb November 8, 2019 16:34
@giginet giginet self-assigned this Nov 8, 2019
$0.context("with optional include for non exist subspecs") {
$0.it("ignore subspecs") {
let path = fixturePath + "optional_include/optional_include.yml"
let project = try XCTUnwrap(loadSpec(path: path))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

XCTUnwrap will work only on Swift 5.1 or above.

Copy link
Owner

Choose a reason for hiding this comment

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

Can you use the new unwrap function from recently merged #714

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

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 addition 👏

$0.context("with optional include for non exist subspecs") {
$0.it("ignore subspecs") {
let path = fixturePath + "optional_include/optional_include.yml"
let project = try XCTUnwrap(loadSpec(path: path))
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use the new unwrap function from recently merged #714

Sources/ProjectSpec/SpecFile.swift Show resolved Hide resolved
return try SpecFile(include: include, basePath: basePath, relativePath: relativePath)
} catch {
if include.optional {
return nil
Copy link
Owner

@yonaskolb yonaskolb Nov 10, 2019

Choose a reason for hiding this comment

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

This would make an optional includes silently fail if there was a different error than simply a missing file, for example if one of the includes own includes was missing. Is that the intention? Maybe it's better to only return nil if the file is actually missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe it's better to only return nil if the file is actually missing

Do you mean optional should ignore throwing from try path.read() ?

let data: Data = try path.read()

@giginet
Copy link
Collaborator Author

giginet commented Nov 10, 2019

@yonaskolb Following your comments I implemented a new strategy to cause errors.
037d44b

However, prior implementation seems to be simpler...
How do you feel about?

do {
data = try path.read()
} catch {
if shouldIgnoreNotFound {
Copy link
Owner

Choose a reason for hiding this comment

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

I was thinking throwing a GenerationError.includeNotFound, which you can then catch at the top level, and it it's not optional then rethrow

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.

2 participants