[PATCH] D56219: [gn build] Add build files for LLVM unittests with a custom main() function

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 5 18:47:20 PST 2019


phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/utils/gn/secondary/llvm/utils/unittest/unittest.gni:49
+    }
+    if (has_custom_main) {
+      deps += [ "//llvm/utils/unittest:gtest" ]
----------------
thakis wrote:
> I tried doing `if (defined(invoker.has_custom_main) && invoker.has_custom_main)` but then GN claimed:
> 
> ```
> FAILED: build.ninja 
> ../../../gn/out/gn --root=../.. -q --dotfile=../../llvm/utils/gn/.gn gen .
> ERROR at //llvm/unittests/CodeGen/GlobalISel/BUILD.gn:19:21: Assignment had no effect.
>   has_custom_main = true
>                     ^---
> You set the variable "has_custom_main" here and it was unused before it went
> out of scope.
> ```
The way this is typically done is:
```
has_custom_main = false # default value
forward_variables_from(invoker, "*") # this is going to override the default value if set
```
That way you don't need the extra condition on lines 46-48.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56219/new/

https://reviews.llvm.org/D56219





More information about the llvm-commits mailing list