-
Notifications
You must be signed in to change notification settings - Fork 701
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
new-exec #4722
new-exec #4722
Conversation
Although we may not want to create GHC environment files in a standard location after every build, it is still useful to be able to build them in a custom place in special circumstances. So let's disable this feature at the call-sites where it doesn't work properly rather than inside the implementation of the feature.
This implements a bare-bones skeleton for cabal new-exec. The old cabal exec gave programs access to a sandbox's package database. By analogy, cabal new-exec should give programs access to the store's package database; however, this database will be cluttered with many non-project-related packages that may confuse issues. Therefore new-exec selects just the packages that are in the current project's dependency tree and makes them available to compiler tools. Currently only very new GHCs are supported, via the GHC_ENVIRONMENT mechanism for selecting a subset of some package databases. Eventually we should probably also modify the PATH so that dependencies' executables are available.
cabal new-exec should be allowed to run any executables available in the dependencies for the current project. This patch introduces that ability: we walk the installation plan, picking out a bin/ directory for each package, then including it in the PATH if there are any executables in that directory.
Previously, whichever version of compiler tools that were on the PATH would be used. Going through the ProgramDb should let us use the appropriate versions of these tools, instead.
Previously, cabal new-exec would modify the PATH by including each package's bin directory if it contained executables. This has some drawbacks: * Lots of filesystem probing * Can have false positives due to dynamic libraries * Mildly unpredictable The new plan is to add each package's bin directory if the package includes an executable stanza. This may include some directories that have no executables in them (e.g. if the executable is not yet built or is not in the install plan), but is more reproducible and requires less filesystem access.
Previously, new-exec would use the `build` directory when looking for executables built inplace. But these executables are actually in subdirectories of `build`, so the search would fail (potentially falling back to an executable in the user's PATH instead). Now we place one directory in the PATH for each executable in each inplace-build package in the install plan.
Based on new-test.
Still in progress. The support check doesn't work yet.
The global db (note: not the user db) is needed (it contains `base`).
Edge cases first, restrict do blocks...
...rather than in the command
(elaboratedPlanOriginal buildCtx) | ||
buildStatus | ||
programIsCompiler = | ||
programId program `elem` ["ghc", "ghcjs", "ghci"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we handle the compiler name rewriting?
(see pr description)
EDIT: this will change in the next push
I'm on vacation in Norway right now, but I'll review this when I get back next week. |
FWIW, as a user I would like |
@cocreature the rewriting only happens as a fallback when using older versions of ghc that don't support .ghc.environment files, and eventually (well, after the 5 or so years of support...) will disappear. Other compilers will probably need rewriting though (I'm changing that code to be more general). I agree that the naming is unfortunate, and I actually would prefer a Of course if there is enough support we can always split the command, it's only a few changes. |
@cocreature that flag only applies to the .ghc.env file that every new- command generates in the project root. new-exec uses a separate and temporary .ghc.env file which is always generated regardless of that flag. |
Alter the compiler flags only if the exe path matches the configured compiler's one. Ex. `cabal -w ghc-8.0 new-exec ghc-8.0 Main.hs` The flags depend on the compiler flavor. Only GHC and GHCJS are supported right now.
case compilerId compiler | ||
of CompilerId GHC _ -> argsEquivalentOfGhcEnvironmentFileGhc | ||
CompilerId GHCJS _ -> argsEquivalentOfGhcEnvironmentFileGhc | ||
CompilerId _ _ -> error "Only GHC and GHCJS are supported" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is error
appropriate? ImplInfo
does it like this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK.
matchCompilerPath elaboratedShared program = | ||
programPath program | ||
`elem` | ||
(programPath <$> configuredCompilers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should i canonicalize those paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure, probably not. Aren't the configured progs paths already absolute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. They seem absolute but maybe it's only the general case. I'll probably leave it like this and add a comment about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I think they should be absolute after the configure progs step.
OSX failure seems to be spurious. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this looks fine, nicely self-contained and ready to go in. Would be nice with a changelog note and a section in the user's guide, but that (and minor fixes I suggested) can be part of a separate PR.
elaboratedPlanOriginal | ||
elaboratedShared | ||
postBuildStatus | ||
_ <- writePlanGhcEnvironment (distProjectRootDirectory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can use void
here.
import qualified Data.Map as M | ||
|
||
execCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags) | ||
execCommand = installCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit hacky. installCommand
is not obviously related to new-build
and will be going away. Also we don't actually want to pull in everything from there. So I'd be more explicit and use commandOptions = commandOptions CmdBuild.buildCommand, ...
. I understand that CmdBuild.buildCommand
is giving a bad example, but we should fix it too.
case compilerId compiler | ||
of CompilerId GHC _ -> argsEquivalentOfGhcEnvironmentFileGhc | ||
CompilerId GHCJS _ -> argsEquivalentOfGhcEnvironmentFileGhc | ||
CompilerId _ _ -> error "Only GHC and GHCJS are supported" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK.
CompilerId GHCJS _ -> argsEquivalentOfGhcEnvironmentFileGhc | ||
CompilerId _ _ -> error "Only GHC and GHCJS are supported" | ||
|
||
-- remove this when we drop support for non-.ghc.env ghc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgotten TODO?
matchCompilerPath elaboratedShared program = | ||
programPath program | ||
`elem` | ||
(programPath <$> configuredCompilers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure, probably not. Aren't the configured progs paths already absolute?
All done. ...except that |
[ci skip]
[ci skip]
There's a merge conflict. |
Merged, thanks! |
Merged master with dmwit/master and finished new-exec.
I had some trouble with git. There are two mege commits where I should have rebased instead, and now it's kinda difficult to fix (see those new-bench commits? they are from the merge.), but I suppose I'll have to do it before merging in master?
Also there's the question of how to rewrite the ghc program name. As a temporary solution I just check if it's ``elem
["ghc", "ghcjs", "ghci"]
and use it as is.If there is no objection I'll change it to use the selected (`-w`) ghc version.
Fixes #3638 (finally!)