Skip to content

Commit

Permalink
add support for --undefine foo to remove define (#11400)
Browse files Browse the repository at this point in the history
* add support for -D !foo to remove define

* use long syntax only
  • Loading branch information
kLabz authored Nov 21, 2023
1 parent 160a490 commit 5d676dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compiler/args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ let parse_args com =
| Some value -> Common.external_define_value com flag value
| None -> Common.external_define com flag;
),"<var[=value]>","define a conditional compilation flag");
("Compilation",["--undefine"],[],Arg.String (fun var ->
Common.external_undefine com var
),"","remove a conditional compilation flag");
("Debug",["-v";"--verbose"],[],Arg.Unit (fun () ->
com.verbose <- true
),"","turn on verbose mode");
Expand Down
3 changes: 3 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ let external_define_value ctx k v =
let external_define ctx k =
Define.raw_define ctx.defines (convert_and_validate k)

let external_undefine ctx k =
Define.raw_undefine ctx.defines (convert_and_validate k)

let defines_for_external ctx =
PMap.foldi (fun k v acc ->
let added_underscore = PMap.add k v acc in
Expand Down
4 changes: 4 additions & 0 deletions src/core/define.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ let define_value ctx k v =
let raw_define ctx k =
raw_define_value ctx k "1"

let raw_undefine ctx k =
ctx.values <- PMap.remove k ctx.values;
ctx.defines_signature <- None

let define ctx k =
raw_define_value ctx (get_define_key k) "1"

Expand Down

0 comments on commit 5d676dc

Please sign in to comment.