[sledge] Add support to ppx_trace enable via environment variable

Summary:
It seems to currently not be possible to make dune `preprocess`
stanzas vary across contexts, without essentially generating the dune
files. A consequence is that it is not possible to pass
context-dependent command line arguments to ppx rewriters. So add
support for an environment variable instead.

Reviewed By: jvillard

Differential Revision: D20322871

fbshipit-source-id: f3f3ea413
master
Josh Berdine 5 years ago committed by Facebook Github Bot
parent c47199e31c
commit 1798725632

@ -8,7 +8,9 @@
(** Extension point rewriter for debug trace logging (** Extension point rewriter for debug trace logging
This ppx rewriter declares a [--debug] command line option, to be passed This ppx rewriter declares a [--debug] command line option, to be passed
by the build system in debug but not optimized build modes. by the build system in debug but not optimized build modes. Setting the
[PPX_TRACE_ENABLED] environment variable to [1] or [true] has the same
effect as passing [--debug].
It rewrites [\[%Trace.info f\]] to a call It rewrites [\[%Trace.info f\]] to a call
[\[Trace.info mod_name fun_name f\]] where [mod_name] and [fun_name] are [\[Trace.info mod_name fun_name f\]] where [mod_name] and [fun_name] are
@ -42,7 +44,11 @@ open Ppxlib
open Ast_builder.Default open Ast_builder.Default
module Ast_mapper = Selected_ast.Ast.Ast_mapper module Ast_mapper = Selected_ast.Ast.Ast_mapper
let debug = ref false let debug =
ref
( match Sys.getenv_opt "PPX_TRACE_ENABLED" with
| Some ("1" | "true") -> true
| _ -> false )
;; ;;
Driver.add_arg "--debug" (Arg.Set debug) ~doc:"Enable debug tracing output" Driver.add_arg "--debug" (Arg.Set debug) ~doc:"Enable debug tracing output"

Loading…
Cancel
Save