File 2893-diffable-Allow-passing-arbitrary-compiler-options-to.patch of Package erlang
From 6c6af2bb4c22d73b396b1dbcdd0ad1ec1b36bf21 Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej@sics.se>
Date: Mon, 20 Jul 2020 10:38:45 +0200
Subject: [PATCH 3/3] diffable: Allow passing arbitrary compiler options to the
compiler
This patch removes the hard-coding of supported compiler options from
diffable. Compiler options can now be given using the `--co <option>`
flag. The implementation of the `--deterministic` flag has been
implemented using the new framework.
---
scripts/diffable | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/scripts/diffable b/scripts/diffable
index 435c69006b..03faf471f7 100755
--- a/scripts/diffable
+++ b/scripts/diffable
@@ -7,7 +7,7 @@
-define(LONG_COMPILE_THRESHOLD, 10000).
main(Args0) ->
- DefOpts = #{format=>asm,no_compile=>false,legacy=>false,deterministic=>[]},
+ DefOpts = #{format=>asm,no_compile=>false,legacy=>false,copts=>[]},
{Args,Opts} = opts(Args0, DefOpts),
case Args of
[OutDir] ->
@@ -26,6 +26,8 @@ usage() ->
" --deterministic Compile with +deterministic (useful when\n"
" comparing output from different build trees using\n"
" --asm)\n"
+ " --co <option> Add <option> to the list of options given to the\n"
+ " compiler. See compile:file/2 for valid options.\n"
"\n"
"DESCRIPTION\n"
"\n"
@@ -79,8 +81,10 @@ opts(["--legacy-asm"|Args], Opts) ->
opts(Args, Opts#{format:=asm,legacy:=true});
opts(["--no-compile"|Args], Opts) ->
opts(Args, Opts#{format:=dis,no_compile:=true});
-opts(["--deterministic"|Args], Opts) ->
- opts(Args, Opts#{deterministic:=[deterministic]});
+opts(["--deterministic"|Args], #{copts:=Copts}=Opts) ->
+ opts(Args, Opts#{copts:=Copts++[deterministic]});
+opts(["--co",Opt|Args], #{copts:=Copts}=Opts) ->
+ opts(Args, Opts#{copts:=Copts++[list_to_atom(Opt)]});
opts(["--"++Opt|_], _Opts) ->
io:format("Unknown option: --~ts\n\n", [Opt]),
usage();
@@ -261,22 +265,22 @@ get_beams([]) -> [].
compile_to_asm_fun(#{outdir:=OutDir}=Opts) ->
fun(Spec) ->
Legacy = map_get(legacy, Opts),
- Deterministic = map_get(deterministic, Opts),
- compile_to_asm(Spec, OutDir, Legacy, Deterministic)
+ COpts = map_get(copts, Opts),
+ compile_to_asm(Spec, OutDir, Legacy, COpts)
end.
-compile_to_asm({Beam,elixir}, OutDir, _Legacy, _Deterministic) ->
+compile_to_asm({Beam,elixir}, OutDir, _Legacy, COpts) ->
Abst = get_abstract_from_beam(Beam),
Source = filename:rootname(Beam, ".beam"),
- Opts = [diffable,{outdir,OutDir},report_errors,{source,Source}],
+ Opts = [diffable,{outdir,OutDir},report_errors,{source,Source}]++COpts,
case compile:forms(Abst, Opts) of
{ok,_Mod,_Asm} ->
ok;
error ->
error
end;
-compile_to_asm({File,Opts0}, OutDir, Legacy, Deterministic) ->
- Opts = Deterministic ++ [diffable,{outdir,OutDir},report_errors|Opts0],
+compile_to_asm({File,Opts0}, OutDir, Legacy, COpts) ->
+ Opts = [diffable,{outdir,OutDir},report_errors|Opts0]++COpts,
case compile:file(File, Opts) of
{ok,_Mod} ->
case Legacy of
--
2.26.2