From f9a0d908e655ab9302380a096d54c979342d4b5b Mon Sep 17 00:00:00 2001 From: Roland McGrath <mcgrathr@google.com> Date: Mon, 13 May 2019 23:45:25 +0000 Subject: [PATCH] [build] Force a fidl_library() with .test.fidl sources to be testonly FIDL source files must be named `*.fidl` and if source files are named `*.test.fidl` then the library using it can only be used in test code. So the fidl_library() template automatically sets `testonly=true` if its sources list include any `*.test.fidl`. It's not allowed to override this with explicit `testonly=false`. Change-Id: I7bb79327be678efbfd293b9fa2baaad55832c9df --- zircon/public/gn/fidl.gni | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/zircon/public/gn/fidl.gni b/zircon/public/gn/fidl.gni index b74543a7510..3d466c219e5 100644 --- a/zircon/public/gn/fidl.gni +++ b/zircon/public/gn/fidl.gni @@ -147,6 +147,18 @@ template("fidl_library") { assert(defined(invoker.sources), "fidl_library(\"$target_name\") must set `sources`") + foreach(file, invoker.sources) { + assert(get_path_info(file, "extension") == "fidl", + "fidl_library() sources should be `.fidl` files, not $file") + file = get_path_info(file, "name") + if (get_path_info(file, "extension") == "test") { + assert(!defined(invoker.testonly) || invoker.testonly, + "fidl_library(\"$target_name\") is implicitly testonly since " + + " it has `.test.fidl` sources; cannot use testonly=false!") + invoker.testonly = true + } + } + fidl_target = target_name # TODO(mcgrathr): temporary until everything is renamed with . names -- GitLab