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

Unable to reference files above the project root using ../ in the paths #380

Closed
csykes opened this issue Jul 26, 2017 · 15 comments
Closed
Labels

Comments

@csykes
Copy link

csykes commented Jul 26, 2017

Context

We've got an Xcode project that consists of multiple sub-projects + some common code base that sits at the root level of the meta-projects. We open the MetaProject.workspace file in Xcode and then select the sub-project's scheme to run/build. Sourcery ends up running from one of the child projects and reference files above it in the directory path. Prior to 0.6.0 we could just use ../ in the sources or templates path to reference those locations but that no longer works.

MetaProject
│   MetaProject.xcworkspace
└───SourceryTemplates
└───CommonCode
└───MySubProject
│   │   MySubProject.xcworkspace
│   └───GeneratedStubs
└───AnotherSubProject
│   │   AnotherSubProject.xcworkspace
│   └───GeneratedStubs

Environment

Xcode 8.3.3
Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)

Issue

After updating to 0.6.1 or 0.7.x we can no longer reference files above the root as the ../ appear to be ignored. We've tried this using both the YAML definition file and Bash shell commands with no luck.

YAML definition

sources:
  - MySubProject
  - ../CommonCode
templates:
  - ../SourceryTemplates/
output:
  MySubProject/GeneratedStubs

args:
  app: MySubProject
  imports: 
    - PromiseKit
    - CoreLocation

Bash shell definition

"$PODS_ROOT/Sourcery/bin/sourcery" --sources "$SRCROOT/../CommonCode" --templates "$SRCROOT/../SourceryTemplates/" --output "$SRCROOT/MySubProject/GeneratedStubs" --args app=MyProject,imports=PromiseKit,imports=CoreLocation
"$PODS_ROOT/Sourcery/bin/sourcery" --sources "$SRCROOT/MySubProject" --templates "$SRCROOT/../SourceryTemplates/" --output "$SRCROOT/MySubProject/GeneratedStubs" --args app=MyProject,imports=PromiseKit,imports=CoreLocation

Results

We see the following failure in Xcode when we try to run the MySubProject

error: '/Users/MrC/Documents/dev/MetaProject/MySubProject/CommonCode' does not exist or is not readable.
error: '/Users/MrC/Documents/dev/MetaProject/MySubProject/SourceryTemplates' does not exist or is not readable.
@Antondomashnev
Copy link
Collaborator

@csykes thanks for reporting it, we'll take a look into the issue soon 😄

@macduy
Copy link

macduy commented Jul 28, 2017

We have a similar set up and we cannot use configuration files for the same reason :) We currently use horrible bash scripts which we'd love to move away from!

@ilyapuchka
Copy link
Collaborator

with 0.6.1 (probably it should have been 0.7) paths in the yaml file are relative to the location of this file (before they were relative to the current path from which sourcery is called). can you confirm that yaml file is in a proper location @csykes @macduy ?

@macduy
Copy link

macduy commented Jul 28, 2017

Yep. I looked at the Xcode build errors and

templates:
 - ../templates/

and

templates:
 - templates/

would resolve to the same directory

@ilyapuchka
Copy link
Collaborator

will it be the same with ./../templates? I'll look into this issue on a weekend if this does not resolve it.

@macduy
Copy link

macduy commented Jul 28, 2017

Yep tried that too and it's the same problem

@ilyapuchka
Copy link
Collaborator

@csykes @macduy if you can add a PR with failing test it would help. I tried to reproduce this issue, but these tests pass:

it("sources include path out of current path using ../") {
    let config = ["sources": ["../otherPath"]]
    let source = Configuration(dict: config, relativePath: relativePath).source
    let expected = Source.sources(Paths(include: [relativePath.parent() + "otherPath"]))
    expect(source).to(equal(expected))
}

it("templates include path out of current path using ../") {
    let config = ["templates": ["../otherPath"]]
    let templates = Configuration(dict: config, relativePath: relativePath).templates
    let expected = Paths(include: [relativePath.parent() + "otherPath"])
    expect(templates).to(equal(expected))
}

@csykes
Copy link
Author

csykes commented Aug 3, 2017

Haven't had a chance to build up a PR with failing tests but we've found that adding an additional $SRC_ROOT/../ into the configuration file it eventually finds the correct file/directory. So we've got a workaround now...

Working .sourcery.yaml

sources:
  - MySubProject
  - $SRC_ROOT/../../../CommonCode
templates:
  - $SRC_ROOT/../../../SourceryTemplates/
output:
  MySubProject/GeneratedStubs

args:
  app: MySubProject
  imports: 
    - PromiseKit
    - CoreLocation

Given that we fetch the latest version of Sourcery from CocoaPods, the commands are run from that binary location. So I suspect that might have something to do with the issue.

Xcode Build Phase Shell Command:

"$PODS_ROOT/Sourcery/bin/sourcery"

Environment definitions:

    export PODS_ROOT=/Users/MrC/Documents/dev/MetaProject/MySubProject/_iOS/../../Pods
    export SRCROOT=/Users/MrC/Documents/dev/MetaProject/MySubProject/_iOS

@ilyapuchka
Copy link
Collaborator

it works because SRCROOT is an absolute path in this case

@csykes
Copy link
Author

csykes commented Aug 3, 2017

Forgot to highlight that even though its using an absolute path now it still requires one extra ../ to make it find the correct directory location.

I would have expected it to only need ../../ to move up the two directory levels to find the Templates or CommonCode from the SRC_PATH.

@Antondomashnev
Copy link
Collaborator

Hi @csykes @macduy I've been trying to debug the issue and I was able to reproduce it. After debugging further I found two things:

  1. It seems to be a bug in PathKit framework that we use in Sourcery with combining two relative path. I've reported it already. It's related to the initial question from @csykes
  2. I've found the weird behaviour - most likely also related to PathKit. $SRCROOT/../CommonCode doesn't work although if I type the actual value of $SRCROOT it works - /Users/antondomashnev/Work/MetaProject/MySubProject/../CommonCode.

For now I think your workaround is the best option until we come up with the resolution for the 1 point.

@csykes
Copy link
Author

csykes commented Aug 7, 2017

Thanks for the update!

With the work around, our app is using the latest Sourcery version now so I've got no issues waiting this out.

@Antondomashnev
Copy link
Collaborator

@ilyapuchka I think it makes sense to mention this limitation somewhere in the documentation for config file, what do you think?

@ilyapuchka
Copy link
Collaborator

I think we should have some kind of FAQ with answers to common questions, then we can put it there.

@Sajjon
Copy link

Sajjon commented Oct 31, 2017

I too have problems relating to not being able to use paths in parents folder in my Config file. Any update?

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

No branches or pull requests

5 participants