From 457e4e7145abb897227ad5cca62ead6b41873983 Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Mon, 17 Jun 2019 12:02:06 -0700 Subject: [PATCH 1/3] Blacklist more cgo breaking warnings Change-Id: Iae834f2cc179220c9c3f71f4f39a8be6edb79dc5 --- go/private/context.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go/private/context.bzl b/go/private/context.bzl index 46ff54b8bb..33eecb5b0b 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -70,6 +70,8 @@ _GoContextData = provider() _COMPILER_OPTIONS_BLACKLIST = { "-fcolor-diagnostics": None, + "-fdiagnostics-color": None, + "-fmax-errors=20": None, "-Wall": None, # Symbols are needed by Go, so keep them From a2c8859be9769f00bcd9591f58d99812ca6b875d Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Mon, 17 Jun 2019 12:02:32 -0700 Subject: [PATCH 2/3] Remove unused variable warnings from _cgo_main.c compilation Change-Id: I78d0b0b96dcaa11783e76218e142878452aa6d1e --- go/private/rules/cgo.bzl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl index c4370909a3..abe91c3fc5 100644 --- a/go/private/rules/cgo.bzl +++ b/go/private/rules/cgo.bzl @@ -795,7 +795,10 @@ def setup_cgo_library_for_mode(name, srcs, cdeps, copts, cxxopts, cppopts, clink name = cgo_o_name, srcs = [select_main_c], deps = cdeps + cgo_o_deps, - copts = copts + cppopts, + copts = copts + cppopts + [ + # The generated thunks often contain unused variables. + "-Wno-unused-variable", + ], linkopts = clinkopts, visibility = ["//visibility:private"], **common_attrs From 2da4b47e143d4cbb10a6f5529b0afb62a87e16e7 Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Tue, 18 Jun 2019 14:33:29 -0700 Subject: [PATCH 3/3] Support arbitrary -fmax-errors= Not everyone uses a -fmax-errors=20. We can be more general. Change-Id: Ic8c50bb08f32fe468f775c49c94534fb73899bae --- go/private/context.bzl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/go/private/context.bzl b/go/private/context.bzl index 33eecb5b0b..e9ab9d56cc 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -69,9 +69,15 @@ GoContext = provider() _GoContextData = provider() _COMPILER_OPTIONS_BLACKLIST = { + # cgo parses the error messages from the compiler. It can't handle colors. + # Ignore both variants of the diagnostics color flag. "-fcolor-diagnostics": None, "-fdiagnostics-color": None, - "-fmax-errors=20": None, + + # cgo also wants to see all the errors when it is testing the compiler. + # fmax-errors limits that and causes build failures. + "-fmax-errors=": None, + "-Wall": None, # Symbols are needed by Go, so keep them @@ -88,8 +94,18 @@ _LINKER_OPTIONS_BLACKLIST = { "-Wl,--gc-sections": None, } +def _match_option(option, pattern): + if pattern.endswith("="): + return option.startswith(pattern) + else: + return option == pattern + def _filter_options(options, blacklist): - return [option for option in options if option not in blacklist] + return [ + option + for option in options + if not any([_match_option(option, pattern) for pattern in blacklist]) + ] def _child_name(go, path, ext, name): childname = mode_string(go.mode) + "/"