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 a library for looking up runfiles. #302

Merged
merged 2 commits into from
Jun 12, 2018
Merged

Add a library for looking up runfiles. #302

merged 2 commits into from
Jun 12, 2018

Conversation

judah
Copy link
Collaborator

@judah judah commented Jun 8, 2018

Relevant Bazel issue: bazelbuild/bazel#4460.

I followed the approach documented here:
https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub
Other than not bothing yet with RUNFILES_MANIFEST, which is only needed on
WINDOWS.

The functionality seemed general and simple enough to be worth upstreaming into rules_haskell itself; let me know what you think and/or if there's a better place to put this.

Relevant Bazel issue: bazelbuild/bazel#4460.

I followed the approach documented here:
https://docs.google.com/document/d/e/2PACX-1vSDIrFnFvEYhKsCMdGdD40wZRBX3m3aZ5HhVj4CtHPmiXKDCxioTUbYsDydjKtFDAzER5eg7OjJWs3V/pub
Other than not bothing yet with `RUNFILES_MANIFEST`, which is only needed on
WINDOWS.
@judah judah requested review from mboes and mrkkrp June 8, 2018 18:49
Copy link
Member

@mboes mboes left a comment

Choose a reason for hiding this comment

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

Nice! I think this indeed belongs in rules_haskell. I was about to write this myself.

We like using the handle pattern. Would you find it acceptable to use it here? This would mean:

  • Bazel.Runfiles module always imported qualified.
  • Runfiles renamed to Handle.
  • runfilesEnv -> env (though I'm not sure whether this one should be exported).
  • getRunfiles -> create, which would bring the library closer in line with the Runfiles design document you link to, which says languages should define a create() method.

--
-- Note that Bazel will set these automatically when it runs tests
-- (@bazel test@).
runfilesEnv :: Runfiles -> [(String, String)]
Copy link
Member

Choose a reason for hiding this comment

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

What's the use case for this function? Should users set RUNFILES_DIR when it's not set? It was my understanding that RUNFILES_DIR is set iff the target is a data dependency of another. I don't know about tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added clarification in the comment; it's for non-test binaries to set manually, since from my testing it's only set automatically in "bazel test".

@judah
Copy link
Collaborator Author

judah commented Jun 12, 2018

I switched the module to qualified names and renamed getRunfiles to create. (I'm wondering if create will be more confusing than helpful; because we're not in an OOP language, it sounds like it's actually constructing the symlink tree or something similar. But for now it seems fine.)

I avoided renaming the Runfiles type to Handle, though. My understanding is that the handle pattern is intended for stateful sequences of IO calls that wrap some form of "service". In contrast, a Runfiles is only ever read from disk once, and then remains a pure, immutable Haskell datatype (and all operations on it are pure). For example, there's no need for a close or withHandle function. So I feel it makes more sense to give it its own type name, like a regular Haskell type, rather than make it seem more stateful than it actually is. Let me know whether that sounds reasonable to you.

Copy link
Member

@mboes mboes left a comment

Choose a reason for hiding this comment

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

Agreed. But in that case, create for Runfiles could even be moved out of IO entirely, in which case we could have a plain rlocation with no Runfiles argument. Reasoning being: runfiles are both global and immutable.

In any case, I'm also fine with the current state of affairs.

@judah judah merged commit 7e3995f into master Jun 12, 2018
@judah judah deleted the runfiles-lib branch June 12, 2018 06:50
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.

3 participants