Skip to content

Commit

Permalink
language: additional (hidden) compiler options needed for migrate (di…
Browse files Browse the repository at this point in the history
…gital-asset#2123)

This adds two compiler options ifaceDir and isGenerated to the compiler
options. These will be needed to write generated interface files to the
right directory and treat generated source files special when generating
interface files.
  • Loading branch information
Robin Krom authored Jul 12, 2019
1 parent 77964ce commit 9a24c4a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module DA.Daml.Options.Types
, projectPackageDatabase
, ifaceDir
, distDir
, genDir
, basePackages
) where

Expand All @@ -34,7 +35,9 @@ data Options = Options
, optMbPackageName :: Maybe String
-- ^ compile in the context of the given package name and create interface files
, optWriteInterface :: Bool
-- ^ Directory to write interface files to. Default is current working directory.
-- ^ whether to write interface files or not.
, optIfaceDir :: Maybe FilePath
-- ^ alternative directory to write interface files to. Default is <current working dir>.daml/interfaces.
, optHideAllPkgs :: Bool
-- ^ hide all imported packages
, optPackageImports :: [(String, [(String, String)])]
Expand All @@ -55,6 +58,8 @@ data Options = Options
-- ^ Controls whether the scenario service server runs all checks
-- or only a subset of them. This is mostly used to run additional
-- checks on CI while keeping the IDE fast.
, optIsGenerated :: Bool
-- Whether we're compiling generated code. Then we allow internal imports.
} deriving Show

data ScenarioValidation
Expand All @@ -75,6 +80,9 @@ projectPackageDatabase = damlArtifactDir </> "package-database"
ifaceDir :: FilePath
ifaceDir = damlArtifactDir </> "interfaces"

genDir :: FilePath
genDir = damlArtifactDir </> "generated"

distDir :: FilePath
distDir = damlArtifactDir </> "dist"

Expand Down Expand Up @@ -110,6 +118,7 @@ defaultOptions mbVersion =
, optPackageDbs = []
, optMbPackageName = Nothing
, optWriteInterface = False
, optIfaceDir = Nothing
, optHideAllPkgs = False
, optPackageImports = []
, optShakeProfiling = Nothing
Expand All @@ -119,6 +128,7 @@ defaultOptions mbVersion =
, optGhcCustomOpts = []
, optScenarioService = EnableScenarioService True
, optScenarioValidation = ScenarioValidationFull
, optIsGenerated = False
}

getBaseDir :: IO FilePath
Expand Down
5 changes: 3 additions & 2 deletions compiler/damlc/daml-opts/daml-opts/DA/Daml/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module DA.Daml.Options(toCompileOpts) where
import Control.Monad
import qualified CmdLineParser as Cmd (warnMsg)
import Data.Bifunctor
import Data.Maybe
import Data.IORef
import Data.List
import DynFlags (parseDynamicFilePragma)
Expand All @@ -34,7 +35,7 @@ import qualified Development.IDE.Types.Options as HieCore
toCompileOpts :: Options -> HieCore.IdeOptions
toCompileOpts Options{..} =
HieCore.IdeOptions
{ optPreprocessor = damlPreprocessor optMbPackageName
{ optPreprocessor = if optIsGenerated then noPreprocessor else damlPreprocessor optMbPackageName
, optGhcSession = do
env <- liftIO $ runGhcFast $ do
setupDamlGHC optImportPath optMbPackageName optGhcCustomOpts
Expand All @@ -45,7 +46,7 @@ toCompileOpts Options{..} =
{ optLocateHieFile = locateInPkgDb "hie"
, optLocateSrcFile = locateInPkgDb "daml"
}
, optIfaceDir = HieCore.InterfaceDirectory (ifaceDir <$ guard optWriteInterface)
, optIfaceDir = HieCore.InterfaceDirectory (fromMaybe ifaceDir optIfaceDir <$ guard optWriteInterface)
, optExtensions = ["daml"]
, optThreads = optThreads
, optShakeProfiling = optShakeProfiling
Expand Down
5 changes: 5 additions & 0 deletions compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module DA.Daml.Preprocessor
( damlPreprocessor
, noPreprocessor
) where

import DA.Daml.Preprocessor.Records
Expand Down Expand Up @@ -41,6 +42,10 @@ damlPreprocessor mbPkgName x
| otherwise = (checkImports x ++ checkDataTypes x ++ checkModuleDefinition x, recordDotPreprocessor $ importDamlPreprocessor $ genericsPreprocessor mbPkgName x)
where name = fmap GHC.unLoc $ GHC.hsmodName $ GHC.unLoc x

-- | No preprocessing. Used for generated code.
noPreprocessor :: GHC.ParsedSource -> ([(GHC.SrcSpan, String)], GHC.ParsedSource)
noPreprocessor x = ([], x)


-- With RebindableSyntax any missing DAML import results in pretty much nothing
-- working (literals, if-then-else) so we inject an implicit import DAML for
Expand Down
2 changes: 2 additions & 0 deletions compiler/damlc/lib/DA/Cli/Damlc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ optionsParser numProcessors enableScenarioService parsePkgName = Options
<*> optPackageDir
<*> parsePkgName
<*> optWriteIface
<*> pure Nothing
<*> optHideAllPackages
<*> many optPackage
<*> optShakeProfiling
Expand All @@ -712,6 +713,7 @@ optionsParser numProcessors enableScenarioService parsePkgName = Options
<*> (concat <$> many optGhcCustomOptions)
<*> pure enableScenarioService
<*> pure (optScenarioValidation $ defaultOptions Nothing)
<*> pure False
where
optImportPath :: Parser [FilePath]
optImportPath =
Expand Down

0 comments on commit 9a24c4a

Please sign in to comment.