Skip to content

Store hie files #9019

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

Merged
merged 17 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import Distribution.Simple.Program.GHC
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import qualified Distribution.Simple.Program.Ld as Ld
import qualified Distribution.Simple.Program.Strip as Strip
import Distribution.Simple.Setup.Common (extraCompilationArtifacts)
import Distribution.Simple.Setup.Config
import Distribution.Simple.Setup.Repl
import Distribution.Simple.Utils
Expand Down Expand Up @@ -2478,7 +2479,7 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
whenShared $ copyModuleFiles "dyn_hi"

-- copy extra compilation artifacts that ghc plugins may produce
copyDirectoryIfExists "extra-compilation-artifacts"
copyDirectoryIfExists extraCompilationArtifacts

-- copy the built library files over:
whenHasCode $ do
Expand Down
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/Simple/GHC/ImplInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ data GhcImplInfo = GhcImplInfo
-- ^ use package-conf instead of package-db
, flagDebugInfo :: Bool
-- ^ -g flag supported
, flagHie :: Bool
-- ^ -hiedir flag supported
, supportsDebugLevels :: Bool
-- ^ supports numeric @-g@ levels
, supportsPkgEnvFiles :: Bool
Expand Down Expand Up @@ -93,6 +95,7 @@ ghcVersionImplInfo ver =
, flagProfLate = v >= [9, 4]
, flagPackageConf = v < [7, 5]
, flagDebugInfo = v >= [7, 10]
, flagHie = v >= [8, 8]
, supportsDebugLevels = v >= [8, 0]
, supportsPkgEnvFiles = v >= [8, 0, 1, 20160901] -- broken in 8.0.1, fixed in 8.0.2
, flagWarnMissingHomeModules = v >= [8, 2]
Expand All @@ -118,6 +121,7 @@ ghcjsVersionImplInfo _ghcjsver ghcver =
, flagProfLate = True
, flagPackageConf = False
, flagDebugInfo = False
, flagHie = ghcv >= [8, 8]
, supportsDebugLevels = ghcv >= [8, 0]
, supportsPkgEnvFiles = ghcv >= [8, 0, 2] -- TODO: check this works in ghcjs
, flagWarnMissingHomeModules = ghcv >= [8, 2]
Expand Down
5 changes: 4 additions & 1 deletion Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ import Distribution.Parsec (simpleParsec)
import Distribution.Pretty (prettyShow)
import Distribution.Simple.BuildPaths
import Distribution.Simple.Compiler
import Distribution.Simple.Flag (Flag, maybeToFlag, toFlag)
import Distribution.Simple.Flag (Flag (NoFlag), maybeToFlag, toFlag)
import Distribution.Simple.GHC.ImplInfo
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program
import Distribution.Simple.Program.GHC
import Distribution.Simple.Setup.Common (extraCompilationArtifacts)
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Types.ComponentLocalBuildInfo
Expand All @@ -78,6 +79,7 @@ import Distribution.Verbosity
import Distribution.Version (Version)
import Language.Haskell.Extension

import Data.Bool (bool)
import qualified Data.ByteString.Lazy.Char8 as BS
import qualified Data.Map as Map
import qualified Data.Set as Set
Expand Down Expand Up @@ -576,6 +578,7 @@ componentGhcOptions verbosity implInfo lbi bi clbi odir =
, ghcOptFfiIncludes = toNubListR $ includes bi
, ghcOptObjDir = toFlag odir
, ghcOptHiDir = toFlag odir
, ghcOptHieDir = bool NoFlag (toFlag $ odir </> extraCompilationArtifacts) $ flagHie implInfo
Copy link
Contributor

@bgamari bgamari Sep 9, 2023

Choose a reason for hiding this comment

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

It seems a bit unfortunate to be placing files directly in extra-compilation-artifacts. My hope when we agreed on this design was that users would instead place things in distinct subdirectories to avoid clutter and the potential for name conflicts. I wonder if it wouldn't be better to rather place these in odir </> extraCompilationArtifacts </> "hie" or similar.

Perhaps it's not too late to revisit this given that we haven't yet released?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems reasonable to me. I will get a PR going for that, probably on Monday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed by #9244

, ghcOptStubDir = toFlag odir
, ghcOptOutputDir = toFlag odir
, ghcOptOptimisation = toGhcOptimisation (withOptimization lbi)
Expand Down
2 changes: 2 additions & 0 deletions Cabal/src/Distribution/Simple/Program/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ data GhcOptions = GhcOptions
, ghcOptDynObjSuffix :: Flag String
-- ^ only in 'GhcStaticAndDynamic' mode
, ghcOptHiDir :: Flag FilePath
, ghcOptHieDir :: Flag FilePath
, ghcOptObjDir :: Flag FilePath
, ghcOptOutputDir :: Flag FilePath
, ghcOptStubDir :: Flag FilePath
Expand Down Expand Up @@ -716,6 +717,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
, concat [["-outputdir", dir] | dir <- flag ghcOptOutputDir]
, concat [["-odir", dir] | dir <- flag ghcOptObjDir]
, concat [["-hidir", dir] | dir <- flag ghcOptHiDir]
, concat [["-hiedir", dir] | dir <- flag ghcOptHieDir]
, concat [["-stubdir", dir] | dir <- flag ghcOptStubDir]
, -----------------------
-- Source search path
Expand Down
6 changes: 6 additions & 0 deletions Cabal/src/Distribution/Simple/Setup/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Distribution.Simple.Setup.Common
, splitArgs
, testOrBenchmarkHelpText
, defaultDistPref
, extraCompilationArtifacts
, optionDistPref
, Flag (..)
, toFlag
Expand Down Expand Up @@ -63,6 +64,11 @@ import Distribution.Verbosity
defaultDistPref :: FilePath
defaultDistPref = "dist"

-- | The name of the directory where optional compilation artifacts
-- go, such as ghc plugins and .hie files.
extraCompilationArtifacts :: FilePath
extraCompilationArtifacts = "extra-compilation-artifacts"

-- | Help text for @test@ and @bench@ commands.
testOrBenchmarkHelpText
:: String
Expand Down
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/HieLocal.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HieLocal where
hieLocal = "INSTALL ME"
15 changes: 15 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- hie-dependency-0.1.0.0 (lib) (requires build)
- hie-0.1.0.0 (lib) (first run)
Configuring library for hie-dependency-0.1.0.0...
Preprocessing library for hie-dependency-0.1.0.0...
Building library for hie-dependency-0.1.0.0...
Installing library in <PATH>
Configuring library for hie-0.1.0.0...
Preprocessing library for hie-0.1.0.0...
Building library for hie-0.1.0.0...
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: hie .
package hie-dependency
ghc-options: -fwrite-ide-info
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
skipUnlessGhcVersion ">= 8.8"
cabalG ["--store-dir=" ++ storeDir] "v2-build" ["hie"]
liftIO $ do
installedDependencyLibDir <- findDependencyInStore storeDir "hie-dependency"
shouldExist $ installedDependencyLibDir </> "lib" </> "extra-compilation-artifacts" </> "HieDependency.hie"
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/hie-local.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: hie-local
version: 0.1.0.0
license: BSD3
author: Elodie Lander
maintainer: [email protected]
build-type: Simple
cabal-version: >=1.10

library
exposed-modules: HieLocal
build-depends: base
default-language: Haskell2010
ghc-options: -fwrite-ide-info
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/hie/Hie.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Hie where
import HieDependency (hieDependency)
hie = hieDependency
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/hie/hie.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: hie
version: 0.1.0.0
license: BSD3
author: Elodie Lander
maintainer: [email protected]
build-type: Simple
cabal-version: >=1.10

library
exposed-modules: Hie
build-depends: base
, hie-dependency
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HieDependency where
hieDependency = "INSTALL ME"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: hie-dependency
version: 0.1.0.0
license: BSD3
author: Elodie Lander
maintainer: [email protected]
build-type: Simple
cabal-version: >=1.10

library
exposed-modules: HieDependency
build-depends: base
default-language: Haskell2010
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/setup.cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Setup configure
Configuring library for hie-local-0.1.0.0...
# Setup build
Preprocessing library for hie-local-0.1.0.0...
Building library for hie-local-0.1.0.0...
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for hie-local-0.1.0.0...
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Setup configure
Configuring library for hie-local-0.1.0.0...
# Setup build
Preprocessing library for hie-local-0.1.0.0...
Building library for hie-local-0.1.0.0...
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for hie-local-0.1.0.0...
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CopyHie/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = setupAndCabalTest $ withPackageDb $ do
skipUnlessGhcVersion ">= 8.8"
setup_install ["hie-local"]
env <- getTestEnv
shouldExist $ testLibInstallDir env </> "hie-local-0.1.0.0" </> "extra-compilation-artifacts" </> "HieLocal.hie"
Loading