Skip to content

Commit b276420

Browse files
committed
[ObjC] Issue stderr warnings for deprecated generation options.
This should get use feedback so we know if usage, the intent is to be able to remove the different generation code in the future if folks don't need these. PiperOrigin-RevId: 666318474
1 parent 13f850d commit b276420

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/google/protobuf/compiler/objectivec/generator.cc

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstddef>
1111
#include <cstdlib>
1212
#include <fstream>
13+
#include <iostream>
1314
#include <memory>
1415
#include <string>
1516
#include <utility>
@@ -18,6 +19,7 @@
1819
#include "absl/container/flat_hash_set.h"
1920
#include "absl/memory/memory.h"
2021
#include "absl/strings/ascii.h"
22+
#include "absl/strings/match.h"
2123
#include "absl/strings/str_cat.h"
2224
#include "absl/strings/str_split.h"
2325
#include "absl/strings/string_view.h"
@@ -314,6 +316,57 @@ bool ObjectiveCGenerator::GenerateAll(
314316

315317
// -----------------------------------------------------------------
316318

319+
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
320+
// error cases, so it seems to be ok to use as a back door for warnings.
321+
322+
// This is a way to turn off these warnings, the intent is that if you find
323+
// this then you also did as asked and filed an issue so the need for the
324+
// generation option is known. But it allows you to keep your builds quiet
325+
// after opening the issue. The value of the environment variable should be
326+
// a comma separated list of the names of the options to suppress their usage
327+
// warning.
328+
char* options_warnings_suppressions_cstr =
329+
getenv("GPB_OBJC_SUPPRESS_DEPRECATED_OPTIONS_WARNINGS");
330+
const absl::string_view options_warnings_suppressions =
331+
options_warnings_suppressions_cstr != nullptr
332+
? options_warnings_suppressions_cstr
333+
: "";
334+
if (generation_options.headers_use_forward_declarations &&
335+
!absl::StrContains(options_warnings_suppressions,
336+
"headers_use_forward_declarations")) {
337+
std::cerr << "WARNING: headers_use_forward_declarations is enabled, this "
338+
"is deprecated and will be removed in the future. If you have "
339+
"a need for enabling it please file an issue at "
340+
"https://github.com/protocolbuffers/protobuf/issues with "
341+
"your use case."
342+
<< std::endl;
343+
std::cerr.flush();
344+
}
345+
if (!generation_options.generate_minimal_imports &&
346+
!absl::StrContains(options_warnings_suppressions,
347+
"generate_minimal_imports")) {
348+
std::cerr << "WARNING: generate_minimal_imports is disabled, this is "
349+
"deprecated and will be removed in the future. If you have a "
350+
"need for disabling it please file an issue at "
351+
"https://github.com/protocolbuffers/protobuf/issues with "
352+
"your use case."
353+
<< std::endl;
354+
std::cerr.flush();
355+
}
356+
if (!generation_options.strip_custom_options &&
357+
!absl::StrContains(options_warnings_suppressions,
358+
"strip_custom_options")) {
359+
std::cerr << "WARNING: strip_custom_options is disabled, this is deprecated"
360+
"and will be removed in the future. If you have a need for "
361+
"disabling it please file an issue at "
362+
"https://github.com/protocolbuffers/protobuf/issues with "
363+
"your use case."
364+
<< std::endl;
365+
std::cerr.flush();
366+
}
367+
368+
// -----------------------------------------------------------------
369+
317370
// These are not official generation options and could be removed/changed in
318371
// the future and doing that won't count as a breaking change.
319372
bool headers_only = getenv("GPB_OBJC_HEADERS_ONLY") != nullptr;
@@ -417,7 +470,7 @@ bool ObjectiveCGenerator::GenerateAll(
417470
}
418471
}
419472
} // if (!headers_only && skip_impls.count(file->name()) == 0)
420-
} // for(file : files)
473+
} // for(file : files)
421474

422475
return true;
423476
}

0 commit comments

Comments
 (0)