From 17987256325318fa9111dc4ff8d9010cc6c10843 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Tue, 10 Mar 2020 02:21:56 -0700 Subject: [PATCH] [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 --- sledge/ppx_trace/ppx_trace.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sledge/ppx_trace/ppx_trace.ml b/sledge/ppx_trace/ppx_trace.ml index 295aad8fa..274b6058c 100644 --- a/sledge/ppx_trace/ppx_trace.ml +++ b/sledge/ppx_trace/ppx_trace.ml @@ -8,7 +8,9 @@ (** Extension point rewriter for debug trace logging 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 [\[Trace.info mod_name fun_name f\]] where [mod_name] and [fun_name] are @@ -42,7 +44,11 @@ open Ppxlib open Ast_builder.Default 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"