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

Check parent directories for Cakefiles #1687

Merged
merged 2 commits into from
Sep 12, 2011
Merged

Check parent directories for Cakefiles #1687

merged 2 commits into from
Sep 12, 2011

Conversation

fortes
Copy link
Contributor

@fortes fortes commented Sep 11, 2011

Might be controversial, but figured I'd put it out there. Rake will crawl look for a Rakefile in parent directories, unless you specify the -nosearch flag. Been a decade since I used Make, but I believe it does the same as well. Cake does not.

I'm a CS novice, so apologies for any non-idiomatic code. Happy to make revisions.

Was issue #1686

@TrevorBurnham
Copy link
Collaborator

+1 on the idea.

Minor nitpick: The way the patch is implemented, there's always a redundant exists call.

@fortes
Copy link
Contributor Author

fortes commented Sep 12, 2011

Refactored to avoid that extra call, let me know if there's anything else you need there.

@jashkenas
Copy link
Owner

I dig it -- thanks for the patch.

jashkenas added a commit that referenced this pull request Sep 12, 2011
Check parent directories for Cakefiles
@jashkenas jashkenas merged commit bd16726 into jashkenas:master Sep 12, 2011
@jashkenas
Copy link
Owner

One quick question. It seems correct, in order to not have to worry about relative paths getting screwed up ... but is it correct for the process to chdir to the Cakefile's directory?

Are there no use cases where you might want to run a cake task in the current subdirectory?

jashkenas added a commit that referenced this pull request Sep 12, 2011
@michaelficarra
Copy link
Collaborator

@jashkenas: I think we should have an invariant that the working directory of a Cakefile is its containing directory. It wouldn't be very fun to author Cakefiles without that invariant. So, to more directly answer your question: I think it's fine.

edit: after thinking about it more, I could go either way. It wouldn't be that big of a hassle to have to remember to reset your working directory at the top of a Cakefile if you're going to make assumptions about it.

@fortes
Copy link
Contributor Author

fortes commented Sep 12, 2011

That's a fair point, @jashkenas -- Rakefiles tend to use File.dirname(__FILE__) in order to keep everything sane in terms of paths.

We can recommend the equivalent code for Cakefiles:

process.chdir path.dirname __filename

Or we can use @michaelficarra's suggestion and keep a static working directory -- but then we may need to expose the original path.

@fortes
Copy link
Contributor Author

fortes commented Sep 12, 2011

FWIW, Rake exposes the directory from which the command is run as application.original_dir (source).

That may be the simplest model here for Cakefile authors.

jashkenas added a commit that referenced this pull request Sep 12, 2011
@jashkenas
Copy link
Owner

That should do the trick.

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

4 participants