mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-17 15:57:21 +03:00
language: fix: move interface files to a different (#1074)
* language: fix: move interface files to a different This fixes https://github.com/digital-asset/daml/issues/1009. We move the created interface files and hie files to a hidden directory ".interfaces" when creating a package. * removing the ifaceDir option and hardcode the dir
This commit is contained in:
parent
2d682f489e
commit
fac312dd40
@ -62,6 +62,7 @@ import Data.Time
|
||||
import Development.IDE.Types.SpanInfo
|
||||
import GHC.Generics (Generic)
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
|
||||
-- | 'CoreModule' together with some additional information required for the
|
||||
-- conversion to DAML-LF.
|
||||
@ -274,12 +275,14 @@ mkTcModuleResult (WriteInterface writeIface) tcm = do
|
||||
nc <- liftIO $ readIORef (hsc_NC session)
|
||||
(iface,_) <- liftIO $ mkIfaceTc session Nothing Sf_None details tcGblEnv
|
||||
liftIO $ when writeIface $ do
|
||||
writeIfaceFile (hsc_dflags session) (replaceExtension (file tcm) ".hi") iface
|
||||
let path = ".interfaces" </> file tcm
|
||||
createDirectoryIfMissing True (takeDirectory path)
|
||||
writeIfaceFile (hsc_dflags session) (replaceExtension path ".hi") iface
|
||||
-- For now, we write .hie files whenever we write .hi files which roughly corresponds to
|
||||
-- when we are building a package. It should be easily decoupable if that turns out to be
|
||||
-- useful.
|
||||
hieFile <- runHsc session $ mkHieFile (tcModSummary tcm) tcGblEnv (fromJust $ renamedSource tcm)
|
||||
writeHieFile (replaceExtension (file tcm) ".hie") hieFile
|
||||
writeHieFile (replaceExtension path ".hie") hieFile
|
||||
let mod_info = HomeModInfo iface details Nothing
|
||||
origNc = nsNames nc
|
||||
case lookupModuleEnv origNc (tcmModule tcm) of
|
||||
|
@ -91,6 +91,7 @@ def _daml_package_rule_impl(ctx):
|
||||
{main}
|
||||
|
||||
cp -a {pkg_root}/* {iface_dir}
|
||||
cp -a .interfaces/{pkg_root}/* {iface_dir}
|
||||
""".format(
|
||||
main = modules[ctx.attr.main],
|
||||
name = name,
|
||||
|
@ -9,6 +9,7 @@ module DA.Daml.GHC.Compiler.Options
|
||||
, getBaseDir
|
||||
, toCompileOpts
|
||||
, projectPackageDatabase
|
||||
, ifaceDir
|
||||
, basePackages
|
||||
) where
|
||||
|
||||
@ -43,9 +44,7 @@ data Options = Options
|
||||
, optMbPackageName :: Maybe String
|
||||
-- ^ compile in the context of the given package name and create interface files
|
||||
, optWriteInterface :: Bool
|
||||
-- ^ Whether we should write interface files during typechecking.
|
||||
-- Until the stdlib moves to a separate package, this should only be used
|
||||
-- with the bootstrap compiler since the stdlib files are mounted read-only.
|
||||
-- ^ Directory to write interface files to. Default is current working directory.
|
||||
, optHideAllPkgs :: Bool
|
||||
-- ^ hide all imported packages
|
||||
, optPackageImports :: [(String, [(String, String)])]
|
||||
@ -115,6 +114,9 @@ moduleImportPaths pm =
|
||||
projectPackageDatabase :: FilePath
|
||||
projectPackageDatabase = ".package-database"
|
||||
|
||||
ifaceDir :: FilePath
|
||||
ifaceDir = ".interfaces"
|
||||
|
||||
-- | Packages that we ship with the compiler.
|
||||
basePackages :: [String]
|
||||
basePackages = ["daml-prim", "daml-stdlib"]
|
||||
|
@ -17,6 +17,7 @@ import qualified Data.ByteString.Lazy.Char8 as BSC
|
||||
import System.FilePath
|
||||
import System.Directory
|
||||
import qualified Codec.Archive.Zip as Zip
|
||||
import DA.Daml.GHC.Compiler.Options
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
{- | Builds a dar file.
|
||||
@ -56,17 +57,23 @@ buildDar ::
|
||||
buildDar dalf modRoot dalfDependencies fileDependencies dataFiles name sdkVersion = do
|
||||
-- Take all source file dependencies and produced interface files. Only the new package command
|
||||
-- produces interface files per default, hence we filter for existent files.
|
||||
fileDeps <-
|
||||
ifaces <-
|
||||
filterM doesFileExist $
|
||||
concat [[dep, dep -<.> "hi", dep -<.> "hie"] | dep <- fileDependencies]
|
||||
concat [[ifaceDir </> dep -<.> "hi", ifaceDir </> dep -<.> "hie"] | dep <- fileDependencies]
|
||||
|
||||
-- Reads all module source files, and pairs paths (with changed prefix)
|
||||
-- with contents as BS. The path must be within the module root path, and
|
||||
-- is modified to have prefix <name> instead of the original root path.
|
||||
mbSrcFiles <- forM fileDeps $ \mPath -> do
|
||||
mbSrcFiles <- forM fileDependencies $ \mPath -> do
|
||||
contents <- BSL.readFile mPath
|
||||
let mbNewPath = (name </>) <$> stripPrefix (addTrailingPathSeparator modRoot) mPath
|
||||
return $ fmap (, contents) mbNewPath
|
||||
|
||||
mbIfaceFaceFiles <- forM ifaces $ \mPath -> do
|
||||
contents <- BSL.readFile mPath
|
||||
let mbNewPath = (name </>) <$> stripPrefix (addTrailingPathSeparator $ ifaceDir </> modRoot) mPath
|
||||
return $ fmap (, contents) mbNewPath
|
||||
|
||||
let dalfName = name <> ".dalf"
|
||||
let dependencies = [(T.unpack pkgName <> ".dalf", BSC.fromStrict bs)
|
||||
| (pkgName, bs) <- dalfDependencies]
|
||||
@ -76,6 +83,7 @@ buildDar dalf modRoot dalfDependencies fileDependencies dataFiles name sdkVersio
|
||||
let allFiles = ("META-INF/MANIFEST.MF", manifestHeader dalfName $ dalfName:map fst dependencies)
|
||||
: (dalfName, dalf)
|
||||
: catMaybes mbSrcFiles
|
||||
++ catMaybes mbIfaceFaceFiles
|
||||
++ dependencies
|
||||
++ dataFiles'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user