diff --git a/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs b/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs index 9128379c3f2b..0362f512524e 100644 --- a/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs +++ b/compiler/damlc/daml-opts/daml-opts-types/DA/Daml/Options/Types.hs @@ -34,6 +34,7 @@ import Control.Monad.Reader import DA.Bazel.Runfiles import qualified DA.Daml.LF.Ast as LF import DA.Pretty +import qualified DA.Service.Logger as Logger import Data.Maybe import qualified Data.Text as T import Development.IDE.GHC.Util (prettyPrint) @@ -71,8 +72,8 @@ data Options = Options -- ^ number of threads to use , optDamlLfVersion :: LF.Version -- ^ The target Daml-LF version - , optDebug :: Bool - -- ^ Whether to enable debugging output + , optLogLevel :: Logger.Priority + -- ^ Min log level that we display , optGhcCustomOpts :: [String] -- ^ custom options, parsed by GHC option parser, overriding DynFlags , optScenarioService :: EnableScenarioService @@ -186,7 +187,7 @@ defaultOptions mbVersion = , optShakeProfiling = Nothing , optThreads = 1 , optDamlLfVersion = fromMaybe LF.versionDefault mbVersion - , optDebug = False + , optLogLevel = Logger.Info , optGhcCustomOpts = [] , optScenarioService = EnableScenarioService True , optEnableScripts = EnableScripts False diff --git a/compiler/damlc/lib/DA/Cli/Damlc/Base.hs b/compiler/damlc/lib/DA/Cli/Damlc/Base.hs index 87a499e4761c..3b3db723548c 100644 --- a/compiler/damlc/lib/DA/Cli/Damlc/Base.hs +++ b/compiler/damlc/lib/DA/Cli/Damlc/Base.hs @@ -15,7 +15,4 @@ import qualified DA.Service.Logger as Logger import qualified DA.Service.Logger.Impl.IO as Logger.IO getLogger :: Options -> T.Text -> IO (Logger.Handle IO) -getLogger Options {optDebug} name = - if optDebug - then Logger.IO.newStderrLogger Logger.Debug name - else Logger.IO.newStderrLogger Logger.Info name +getLogger Options {optLogLevel} name = Logger.IO.newStderrLogger optLogLevel name diff --git a/compiler/damlc/lib/DA/Cli/Options.hs b/compiler/damlc/lib/DA/Cli/Options.hs index 81fcec5a295e..092fec2be36e 100644 --- a/compiler/damlc/lib/DA/Cli/Options.hs +++ b/compiler/damlc/lib/DA/Cli/Options.hs @@ -5,7 +5,7 @@ module DA.Cli.Options ( module DA.Cli.Options ) where -import Data.List.Extra (trim, splitOn) +import Data.List.Extra (lower, splitOn, trim) import Options.Applicative.Extended import Safe (lastMay) import Data.List @@ -16,6 +16,7 @@ import DA.Daml.LF.Ast.Util (splitUnitId) import qualified DA.Daml.LF.Ast.Version as LF import DA.Daml.Project.Consts import DA.Daml.Project.Types +import qualified DA.Service.Logger as Logger import qualified Module as GHC import qualified Text.ParserCombinators.ReadP as R @@ -238,8 +239,20 @@ dlintUsageOpt = fmap (fromMaybe DlintDisabled . lastMay) $ many (dlintEnabledOpt <|> dlintDisabledOpt) -optDebugLog :: Parser Bool -optDebugLog = switch $ help "Enable debug output" <> long "debug" +cliOptLogLevel :: Parser Logger.Priority +cliOptLogLevel = + flag' Logger.Debug (long "debug" <> help "Set log level to DEBUG") <|> + option readLogLevel (long "log-level" <> help "Set log level. Possible values are DEBUG, INFO, WARNING, ERROR" <> value Logger.Info) + where + readLogLevel = maybeReader $ \s -> case lower s of + -- we support telemetry log-level for debugging purposes. + "telemetry" -> Just Logger.Telemetry + "debug" -> Just Logger.Debug + "info" -> Just Logger.Info + "warning" -> Just Logger.Warning + "error" -> Just Logger.Error + _ -> Nothing + optPackageName :: Parser (Maybe GHC.UnitId) optPackageName = optional $ fmap GHC.stringToUnitId $ strOption $ @@ -266,7 +279,7 @@ optionsParser numProcessors enableScenarioService parsePkgName = do optShakeProfiling <- shakeProfilingOpt optThreads <- optShakeThreads optDamlLfVersion <- lfVersionOpt - optDebug <- optDebugLog + optLogLevel <- cliOptLogLevel optGhcCustomOpts <- optGhcCustomOptions let optScenarioService = enableScenarioService let optSkipScenarioValidation = SkipScenarioValidation False diff --git a/daml-script/daml/BUILD.bazel b/daml-script/daml/BUILD.bazel index c386787311ed..327de750f16c 100644 --- a/daml-script/daml/BUILD.bazel +++ b/daml-script/daml/BUILD.bazel @@ -35,6 +35,7 @@ EOF build_options = str([ "--ghc-option", "-Werror", + "--log-level=WARNING", ] + [ "--target", lf_version, diff --git a/rules_daml/daml.bzl b/rules_daml/daml.bzl index 93c01e4e4283..f0cbb7e5676d 100644 --- a/rules_daml/daml.bzl +++ b/rules_daml/daml.bzl @@ -24,8 +24,7 @@ def _daml_configure_impl(ctx): project_version = ctx.attr.project_version daml_yaml = ctx.outputs.daml_yaml target = ctx.attr.target - ghc_opts = ctx.attr.ghc_options - opts = ghc_opts + ["--target={}".format(target)] if target else ghc_opts + opts = ["--target={}".format(target)] if target else [] ctx.actions.write( output = daml_yaml, content = """ @@ -61,10 +60,6 @@ _daml_configure = rule( "target": attr.string( doc = "DAML-LF version to output.", ), - "ghc_options": attr.string_list( - doc = "Options passed to GHC.", - default = ["--ghc-option=-Werror"], - ), }, ) @@ -152,7 +147,7 @@ _daml_build = rule( ), "ghc_options": attr.string_list( doc = "Options passed to GHC.", - default = ["--ghc-option=-Werror"], + default = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"], ), "_damlc": _damlc, }, @@ -172,7 +167,7 @@ def _extract_main_dalf_impl(ctx): outputs = [output_dalf], progress_message = "Extract DALF from DAR (%s)" % project_name, command = """ -set -eoux pipefail +set -eou pipefail TMPDIR=$(mktemp -d) trap "rm -rf $TMPDIR" EXIT # While zipper has a -d option, it insists on it @@ -252,12 +247,15 @@ def _inspect_dar(base): _default_project_version = "1.0.0" +default_damlc_opts = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"] + def daml_compile( name, srcs, version = _default_project_version, target = None, project_name = None, + ghc_options = default_damlc_opts, **kwargs): "Build a DAML project, with a generated daml.yaml." if len(srcs) == 0: @@ -277,6 +275,7 @@ def daml_compile( srcs = srcs, dar_dict = {}, dar = name + ".dar", + ghc_options = ghc_options, **kwargs ) _inspect_dar( @@ -308,6 +307,7 @@ def daml_build_test( daml_subdir_basename = "daml", daml_yaml = None, dar_dict = {}, + ghc_options = default_damlc_opts, **kwargs): "Build a DAML project and validate the resulting .dar file." if not daml_yaml: @@ -319,6 +319,7 @@ def daml_build_test( srcs = srcs, dar_dict = dar_dict, dar = name + ".dar", + ghc_options = ghc_options, **kwargs ) _daml_validate_test( @@ -338,7 +339,7 @@ def daml_test( name = name, data = [damlc] + srcs + deps + data_deps, cmd = """\ -set -eoux pipefail +set -eou pipefail tmpdir=$$(mktemp -d) trap "rm -rf $$tmpdir" EXIT DAMLC=$$(canonicalize_rlocation $(rootpath {damlc})) diff --git a/triggers/daml/BUILD.bazel b/triggers/daml/BUILD.bazel index 6f8d084afe52..b5e5c63ff603 100644 --- a/triggers/daml/BUILD.bazel +++ b/triggers/daml/BUILD.bazel @@ -34,7 +34,7 @@ dependencies: - daml-script.dar build-options: {build_options} EOF - $(location //compiler/damlc) build --project-root $$TMP_DIR --ghc-option=-Werror \ + $(location //compiler/damlc) build --project-root $$TMP_DIR --ghc-option=-Werror --log-level=WARNING \ -o $$PWD/$@ rm -rf $$TMP_DIR """.format(