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

new-exec #4722

Merged
merged 37 commits into from
Sep 26, 2017
Merged

new-exec #4722

merged 37 commits into from
Sep 26, 2017

Conversation

fgaz
Copy link
Member

@fgaz fgaz commented Aug 24, 2017

Merged master with dmwit/master and finished new-exec.

  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • Basic tests.

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!)

dmwit and others added 30 commits February 24, 2017 15:10
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.
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...
(elaboratedPlanOriginal buildCtx)
buildStatus
programIsCompiler =
programId program `elem` ["ghc", "ghcjs", "ghci"]
Copy link
Member Author

@fgaz fgaz Aug 24, 2017

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

@23Skidoo
Copy link
Member

I'm on vacation in Norway right now, but I'll review this when I get back next week.

@cocreature
Copy link
Collaborator

FWIW, as a user I would like cabal new-exec to not rewrite commands and only set environment variables. Rewriting commands is bound to cause confusion and will always be really fragile, e.g., cabal new-exec -- ghc might work but cabal new-exec -- time ghc won’t. I can see a case for a way to execute ghc regardless of how the executable is called but I would prefer for that to be a separate cabal new-ghc command.

@fgaz
Copy link
Member Author

fgaz commented Aug 28, 2017

@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 new-ghc too, but new-exec is meant to be kinda compatible with old exec, and cabal -w "some-ghc" new-exec -- "some-ghc" will be completely equivalent to the hypotetical cabal -w "some-ghc" new-ghc.

Of course if there is enough support we can always split the command, it's only a few changes.

@cocreature
Copy link
Collaborator

@fgaz There will be an option to disable .ghc.environment.* files #4542 (which I am definitely going to use) so I don’t think you can rely on this ever going away.

@fgaz
Copy link
Member Author

fgaz commented Aug 28, 2017

@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"
Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@fgaz fgaz requested a review from 23Skidoo September 1, 2017 21:07
@23Skidoo
Copy link
Member

OSX failure seems to be spurious.

Copy link
Member

@23Skidoo 23Skidoo left a 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
Copy link
Member

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
Copy link
Member

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"
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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?

@fgaz
Copy link
Member Author

fgaz commented Sep 26, 2017

All done.
EDIT: oh wait, the docs

...except that git rerere failed me (or I failed it) and now we have three more commits that could have been fixupd. Can I merge anyway once ci passes?

@23Skidoo
Copy link
Member

There's a merge conflict.

@23Skidoo 23Skidoo merged commit 87a9dfa into haskell:master Sep 26, 2017
@23Skidoo
Copy link
Member

Merged, thanks!

@fgaz fgaz deleted the new-exec/1 branch July 9, 2018 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[nix-local-build] new-run, new-test, new-bench, new-exec
4 participants