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

Add a --log-level flag to damlc #11514

Merged
merged 1 commit into from
Nov 3, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions compiler/damlc/lib/DA/Cli/Damlc/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 17 additions & 4 deletions compiler/damlc/lib/DA/Cli/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 $
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions daml-script/daml/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ EOF
build_options = str([
"--ghc-option",
"-Werror",
"--log-level=WARNING",
] + [
"--target",
lf_version,
Expand Down
19 changes: 10 additions & 9 deletions rules_daml/daml.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -61,10 +60,6 @@ _daml_configure = rule(
"target": attr.string(
doc = "DAML-LF version to output.",
),
"ghc_options": attr.string_list(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we set this twice once in _daml_build and once in daml_configure which broke passing --log-level since the flag is only accepted once (as all other flags).

doc = "Options passed to GHC.",
default = ["--ghc-option=-Werror"],
),
},
)

Expand Down Expand Up @@ -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,
},
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -277,6 +275,7 @@ def daml_compile(
srcs = srcs,
dar_dict = {},
dar = name + ".dar",
ghc_options = ghc_options,
**kwargs
)
_inspect_dar(
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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}))
Expand Down
2 changes: 1 addition & 1 deletion triggers/daml/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down