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

Fix run command environment #9341

Closed
wants to merge 1 commit into from
Closed

Conversation

xsebek
Copy link
Contributor

@xsebek xsebek commented Oct 15, 2023

QA Notes

Calling cabal run should run the executable with dependencies on PATH.

Run a test that uses the built executable (e.g. fourmolu or HLS) that it depends on via build-tool-depends.
For example in the case of func-test in HLS, the following invocations should now all pass:

cabal run func-test -- -p indefinite
cabal test func-test --test-options="-p indefinite"
cabal exec $(cabal list-bin func-test) -- -p indefinite

Copy link
Collaborator

@geekosaur geekosaur left a comment

Choose a reason for hiding this comment

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

A test and a changelog.d entry would be nice.

cabal-install/src/Distribution/Client/CmdRun.hs Outdated Show resolved Hide resolved
@xsebek
Copy link
Contributor Author

xsebek commented Oct 15, 2023

@geekosaur this is still a Draft PR and I am aware there will be more steps to get this merged. 🙂


More importantly this does not work yet. Printing out the added environment shows just:

[("GHC_ENVIRONMENT",Just "/Users/xsebek/Git/haskell-language-server/dist-newstyle/tmp/environment.-20638/.ghc.environment.aarch64-darwin-9.2.8")]

The file does not exist, so I assume it's creation was skipped in run.

I would be grateful for any tips.

@gbaz
Copy link
Collaborator

gbaz commented Oct 16, 2023

I think this PR is confused. env files are ghc package environment env files.

The ticket seems to be about just setting the PATH shell environment variable -- a totally different usage of the name "environment".

The issue (I think) is that the test action is invoked via the setup wrapper, which sets that shell environment stuff automatically:

(that in turn uses withEnv to set the path).

The run action is invoked directly, so doesn't have that logic, which will need to be shared/replicated. (This is because there's a runghc Setup.hs test path but no such thing for run which doesn't exist for the Cabal library but only the `cabal-install executable).

@xsebek
Copy link
Contributor Author

xsebek commented Oct 16, 2023

@gbaz I overlooked where exec modifies PATH, it's here:

extraPaths <- pathAdditions verbosity baseCtx buildCtx

@gbaz
Copy link
Collaborator

gbaz commented Oct 16, 2023

Hrm... porting that from exec to run could likely work!

@xsebek xsebek force-pushed the fix/run-env branch 2 times, most recently from f45c16f to 8ac9633 Compare October 21, 2023 20:39
@xsebek xsebek marked this pull request as ready for review October 21, 2023 20:54
@xsebek
Copy link
Contributor Author

xsebek commented Oct 21, 2023

@gbaz please take a look now. 🙂

Not sure if there is a good place for pathAdditions/binDirectories, maybe the latter should go to Distribution.Client.ProjectPlanning.Types? Looking at it, there is elabExeDependencyPaths already... 🤔

Similarly to CmdExec and CmdTest, get paths to all dependency binaries
and add those to PATH. Unlike CmdExec, add just the explicitly required
paths.
@xsebek
Copy link
Contributor Author

xsebek commented Oct 22, 2023

I switched to using the existing elabExeDependencyPaths as it adds just what was explicitly required to PATH.

@gbaz
Copy link
Collaborator

gbaz commented Oct 23, 2023

Looks good, we should probably give it a user acceptance test at least.

@gbaz gbaz added the attention: needs-manual-qa PR is destined for manual QA label Oct 23, 2023
@xsebek
Copy link
Contributor Author

xsebek commented Oct 26, 2023

@gbaz should I prepare something for the test or are the notes enough? 🙂

@mpickering
Copy link
Collaborator

Can you please add a test?

@xsebek
Copy link
Contributor Author

xsebek commented Nov 3, 2023

@mpickering sure, I will get to it next week and see if there is a similar test that I could modify. 🙂

@xsebek
Copy link
Contributor Author

xsebek commented Nov 11, 2023

@mpickering as far as I can see, the only integration test that actually runs any Cmd.* action is testHaddockProjectDependencies. (I searched for Cmd\S*\.\S*Action in test directory.) Am I missing something?

Reading the test README leaves me rather confused, as there are no shell scripts that run commands there.
EDIT: I originally linked to the commit where the README was last modified, so there were shell scripts 7 years ago.

Otherwise, I guess I could write an integration test for elabExeDependencyPaths, to see that it really gives the run command the paths to executable directories we would expect.

There are "golden tests" in unit tests that check the cabal files in cabal-install/tests/fixtures/init/golden/exe which do contain build-tool-depends, but I am not sure if they test elabExeDependencyPaths. (I have no idea how much mkStanza [mkExeStanza ...] tests.)

If there is some up-to-date guidance on how to write new tests in the repo, please point me to it. 🙂

@mpickering
Copy link
Collaborator

@xsebek You should write a test in cabal-testsuite/PackageTests which directly ensures that running the sequence of commands in the ticket description works.

I can write this test for you if you would like me to.

@ulysses4ever
Copy link
Collaborator

@xsebek hey! Any news on this? The last bit remaining is a test. And Matt suggested he could do it for you if you’re having trouble. What do you think?

@jasagredo
Copy link
Collaborator

I could absorb this PR into #9527. Thoughts? @ulysses4ever

@ulysses4ever
Copy link
Collaborator

@jasagredo I'm good with absorbing!

@jasagredo
Copy link
Collaborator

Closing as it was absorbed by #9527

@jasagredo jasagredo closed this Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-manual-qa PR is destined for manual QA
Projects
Status: Testing Approved
Development

Successfully merging this pull request may close these issues.

cabal test sees the executable, but cabal run does not.
6 participants