Skip to content

Commit

Permalink
add support for --undefine foo to remove define (HaxeFoundation#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 and 0b1kn00b committed Jan 25, 2024
1 parent 934734e commit 1b10334
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
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
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
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 1b10334

Please sign in to comment.