Fix internal deprecation warnings (#4257)

This allows us to error out on deprecation warnings for thirdparty
libraries and standard library features.

Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
Tyler Veness
2022-05-24 13:56:48 -07:00
committed by GitHub
parent b193b318c1
commit d651a1fcec
32 changed files with 165 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
macro(wpilib_target_warnings target)
if(NOT MSVC)
target_compile_options(${target} PRIVATE -Wall -pedantic -Wextra -Werror -Wno-unused-parameter -Wno-error=deprecated-declarations ${WPILIB_TARGET_WARNINGS})
target_compile_options(${target} PRIVATE -Wall -pedantic -Wextra -Werror -Wno-unused-parameter ${WPILIB_TARGET_WARNINGS})
else()
target_compile_options(${target} PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /wd4996 /WX ${WPILIB_TARGET_WARNINGS})
target_compile_options(${target} PRIVATE /wd4146 /wd4244 /wd4251 /wd4267 /WX /D_CRT_SECURE_NO_WARNINGS ${WPILIB_TARGET_WARNINGS})
endif()
endmacro()

View File

@@ -84,11 +84,6 @@ model {
}
}
}
binary.tasks.withType(CppCompile) {
cppCompiler.args "-Wno-missing-field-initializers"
cppCompiler.args "-Wno-unused-variable"
cppCompiler.args "-Wno-error=deprecated-declarations"
}
project(':hal').addHalDependency(binary, 'shared')
project(':hal').addHalJniDependency(binary)
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'

View File

@@ -194,6 +194,7 @@ struct RelayHandle {
do { \
ASSERT_EQ(status, HAL_USE_LAST_ERROR); \
const char* lastErrorMessageInMacro = HAL_GetLastError(&status); \
static_cast<void>(lastErrorMessageInMacro); \
ASSERT_EQ(status, x); \
} while (0)

View File

@@ -101,7 +101,9 @@ tasks.withType(JavaCompile).configureEach {
'--release',
'11',
'-encoding',
'UTF8'
'UTF8',
"-Werror",
"-Xlint:deprecation,removal",
]
}

View File

@@ -1,7 +1,7 @@
From 51c4e5107060a5decf24b642666eea1874ca8a04 Mon Sep 17 00:00:00 2001
From 776fc617c56fdce3bc218e649a9bbfbdb6d4c8f9 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:01:25 -0400
Subject: [PATCH 1/7] Fix missing casts
Subject: [PATCH 1/8] Fix missing casts
---
include/uv/unix.h | 2 +-

View File

@@ -1,7 +1,7 @@
From f6b4cd53205fabd10ed0e2b275f3882aa0017061 Mon Sep 17 00:00:00 2001
From 7727474439a3a3dc2b74c9c7ae4b1c36a11fdce2 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:09:43 -0400
Subject: [PATCH 2/7] Fix warnings
Subject: [PATCH 2/8] Fix warnings
---
include/uv/win.h | 5 +++

View File

@@ -1,7 +1,7 @@
From 20120ec8cb9310e243a71fe5bf9bee37eac7614b Mon Sep 17 00:00:00 2001
From e9c7588e574cbf1fe99c0de7f9fcbb2910f03dd8 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:19:14 -0400
Subject: [PATCH 3/7] Preprocessor cleanup
Subject: [PATCH 3/8] Preprocessor cleanup
---
include/uv.h | 18 +-----------------

View File

@@ -1,7 +1,7 @@
From 644521f5d44152e0196cb630864d37ba79c8a39e Mon Sep 17 00:00:00 2001
From 1a02de906b6182af54eeafff465d51364c0bbcc4 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:24:47 -0400
Subject: [PATCH 4/7] Cleanup problematic language
Subject: [PATCH 4/8] Cleanup problematic language
---
src/unix/tty.c | 21 +++++++++++----------

View File

@@ -1,7 +1,7 @@
From 6ad2de945c69a58fbe092f549d5a6c7c02952cef Mon Sep 17 00:00:00 2001
From ec156359c45abbd0a0547d442788477d8fb57fa0 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:26:03 -0400
Subject: [PATCH 5/7] Use roborio time
Subject: [PATCH 5/8] Use roborio time
---
src/unix/linux-core.c | 8 ++++++++

View File

@@ -1,7 +1,7 @@
From 6399ee267f6cc4cafda478b277c8888ee0b08632 Mon Sep 17 00:00:00 2001
From 1131c424a6f54e3904eed0e2efb138ce4cce9c84 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Tue, 26 Apr 2022 15:28:52 -0400
Subject: [PATCH 6/7] Style / comments cleanup
Subject: [PATCH 6/8] Style / comments cleanup
---
src/fs-poll.c | 1 +

View File

@@ -1,7 +1,7 @@
From aa760b0bb41c8052f47f9d49eb100340c1c76634 Mon Sep 17 00:00:00 2001
From 82d952b117b770bbefebd5308416ab767eb58234 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Tue, 17 May 2022 21:36:57 -0700
Subject: [PATCH 7/7] Squelch GCC 12.1 warnings
Subject: [PATCH 7/8] Squelch GCC 12.1 warnings
---
src/unix/stream.c | 9 +++++++++

View File

@@ -0,0 +1,25 @@
From ff18404849ca7560c452f8a600982211de57aa5a Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Sat, 21 May 2022 22:58:06 -0700
Subject: [PATCH 8/8] Fix Win32 warning suppression pragma
---
src/win/util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/win/util.c b/src/win/util.c
index 7a5dd2ef..d9888aec 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -1750,7 +1750,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
} else {
/* Silence GetVersionEx() deprecation warning. */
#ifdef _MSC_VER
- #pragma warning(suppress : 4996)
+ #pragma warning(disable : 4996)
#endif
if (GetVersionExW(&os_info) == 0) {
r = uv_translate_sys_error(GetLastError());
--
2.36.1

View File

@@ -22,6 +22,7 @@ def main():
os.path.join(prefix, "0005-Use-roborio-time.patch"),
os.path.join(prefix, "0006-Style-comments-cleanup.patch"),
os.path.join(prefix, "0007-Squelch-GCC-12.1-warnings.patch"),
os.path.join(prefix, "0008-Fix-Win32-warning-suppression-pragma.patch"),
])
# Delete old install

View File

@@ -254,6 +254,7 @@ public interface Command {
* @return the decorated command
* @deprecated use {@link #endlessly()} instead.
*/
@SuppressWarnings("removal") // PerpetualCommand
@Deprecated(forRemoval = true, since = "2023")
default PerpetualCommand perpetually() {
return new PerpetualCommand(this);

View File

@@ -56,6 +56,7 @@ public class PerpetualCommand extends CommandBase {
return m_command.runsWhenDisabled();
}
@SuppressWarnings("removal") // Command.perpetually()
@Override
public PerpetualCommand perpetually() {
return this;

View File

@@ -87,7 +87,9 @@ SequentialCommandGroup Command::AndThen(
}
PerpetualCommand Command::Perpetually() && {
WPI_IGNORE_DEPRECATED
return PerpetualCommand(std::move(*this).TransferOwnership());
WPI_UNIGNORE_DEPRECATED
}
EndlessCommand Command::Endlessly() && {

View File

@@ -31,8 +31,7 @@ namespace frc2 {
*
* @deprecated replace with EndlessCommand
*/
class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
: public CommandHelper<CommandBase, PerpetualCommand> {
class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
public:
/**
* Creates a new PerpetualCommand. Will run another command in perpetuity,
@@ -41,8 +40,10 @@ class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
*
* @param command the command to run perpetually
*/
WPI_DEPRECATED("Replace with EndlessCommand")
explicit PerpetualCommand(std::unique_ptr<Command>&& command);
WPI_IGNORE_DEPRECATED
/**
* Creates a new PerpetualCommand. Will run another command in perpetuity,
* ignoring that command's end conditions, unless this command itself is
@@ -52,9 +53,11 @@ class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
*/
template <class T, typename = std::enable_if_t<std::is_base_of_v<
Command, std::remove_reference_t<T>>>>
WPI_DEPRECATED("Replace with EndlessCommand")
explicit PerpetualCommand(T&& command)
: PerpetualCommand(std::make_unique<std::remove_reference_t<T>>(
std::forward<T>(command))) {}
WPI_UNIGNORE_DEPRECATED
PerpetualCommand(PerpetualCommand&& other) = default;

View File

@@ -168,6 +168,7 @@ class CommandDecoratorTest extends CommandTestBase {
}
}
@SuppressWarnings("removal") // Command.perpetually()
@Test
void perpetuallyTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
@@ -184,6 +185,22 @@ class CommandDecoratorTest extends CommandTestBase {
}
}
@Test
void endlesslyTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Command command = new InstantCommand();
Command perpetual = command.endlessly();
scheduler.schedule(perpetual);
scheduler.run();
scheduler.run();
scheduler.run();
assertTrue(scheduler.isScheduled(perpetual));
}
}
@Test
void unlessTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {

View File

@@ -0,0 +1,23 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class EndlessCommandTest extends CommandTestBase {
@Test
void endlessCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
EndlessCommand command = new EndlessCommand(new InstantCommand());
scheduler.schedule(command);
scheduler.run();
assertTrue(scheduler.isScheduled(command));
}
}
}

View File

@@ -137,8 +137,8 @@ class ParallelRaceGroupTest extends CommandTestBase {
Command command1 = command1Holder.getMock();
MockCommandHolder command2Holder = new MockCommandHolder(true, system2);
Command command2 = command2Holder.getMock();
MockCommandHolder perpetualCommandHolder = new MockCommandHolder(true);
Command command3 = new PerpetualCommand(perpetualCommandHolder.getMock());
MockCommandHolder endlessCommandHolder = new MockCommandHolder(true);
Command command3 = new EndlessCommand(endlessCommandHolder.getMock());
Command group1 = new SequentialCommandGroup(command1, command2);
assertNotNull(group1);

View File

@@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class PerpetualCommandTest extends CommandTestBase {
@SuppressWarnings("removal") // PerpetualCommand
@Test
void perpetualCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {

View File

@@ -36,7 +36,7 @@ class ScheduleCommandTest extends CommandTestBase {
new SequentialCommandGroup(new InstantCommand(), scheduleCommand);
scheduler.schedule(group);
scheduler.schedule(new InstantCommand().perpetually());
scheduler.schedule(new InstantCommand().endlessly());
scheduler.run();
assertDoesNotThrow(scheduler::run);
}

View File

@@ -6,6 +6,7 @@
#include "CommandTestBase.h"
#include "frc2/command/ConditionalCommand.h"
#include "frc2/command/EndlessCommand.h"
#include "frc2/command/InstantCommand.h"
#include "frc2/command/ParallelRaceGroup.h"
#include "frc2/command/PerpetualCommand.h"
@@ -93,7 +94,22 @@ TEST_F(CommandDecoratorTest, AndThen) {
TEST_F(CommandDecoratorTest, Perpetually) {
CommandScheduler scheduler = GetScheduler();
WPI_IGNORE_DEPRECATED
auto command = InstantCommand([] {}, {}).Perpetually();
WPI_UNIGNORE_DEPRECATED
scheduler.Schedule(&command);
scheduler.Run();
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
}
TEST_F(CommandDecoratorTest, Endlessly) {
CommandScheduler scheduler = GetScheduler();
auto command = InstantCommand([] {}, {}).Endlessly();
scheduler.Schedule(&command);

View File

@@ -0,0 +1,23 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/EndlessCommand.h"
#include "frc2/command/InstantCommand.h"
using namespace frc2;
class EndlessCommandTest : public CommandTestBase {};
TEST_F(EndlessCommandTest, EndlessCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
bool check = false;
EndlessCommand command{InstantCommand([&check] { check = true; }, {})};
scheduler.Schedule(&command);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
EXPECT_TRUE(check);
}

View File

@@ -14,7 +14,9 @@ TEST_F(PerpetualCommandTest, PerpetualCommandSchedule) {
bool check = false;
WPI_IGNORE_DEPRECATED
PerpetualCommand command{InstantCommand([&check] { check = true; }, {})};
WPI_UNIGNORE_DEPRECATED
scheduler.Schedule(&command);
scheduler.Run();

View File

@@ -47,11 +47,6 @@ if (WITH_TESTS)
wpilib_add_test(wpilibc src/test/native/cpp)
target_include_directories(wpilibc_test PRIVATE src/test/native/include)
target_link_libraries(wpilibc_test wpilibc gmock_main)
if (NOT MSVC)
target_compile_options(wpilibc_test PRIVATE -Wno-error)
else()
target_compile_options(wpilibc_test PRIVATE /WX-)
endif()
if (NOT WITH_CSCORE)
target_compile_definitions(wpilibc_test PRIVATE DYNAMIC_CAMERA_SERVER)
# Add just the camera server include directory

View File

@@ -91,7 +91,9 @@ TEST(EncoderSimTest, Period) {
auto cb = sim.RegisterPeriodCallback(callback.GetCallback(), false);
sim.SetPeriod(123.456);
EXPECT_EQ(123.456, sim.GetPeriod());
WPI_IGNORE_DEPRECATED
EXPECT_EQ(123.456, encoder.GetPeriod().value());
WPI_UNIGNORE_DEPRECATED
EXPECT_EQ(kDefaultDistancePerPulse / 123.456, encoder.GetRate());
EXPECT_TRUE(callback.WasTriggered());
@@ -110,7 +112,9 @@ TEST(EncoderSimTest, SetMaxPeriod) {
DoubleCallback callback;
auto cb = sim.RegisterMaxPeriodCallback(callback.GetCallback(), false);
WPI_IGNORE_DEPRECATED
encoder.SetMaxPeriod(units::second_t{123.456});
WPI_UNIGNORE_DEPRECATED
EXPECT_EQ(123.456, sim.GetMaxPeriod());
EXPECT_TRUE(callback.WasTriggered());

View File

@@ -34,11 +34,6 @@ templatesTree.list(new FilenameFilter() {
templatesMap.put(it, [])
}
nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.roborio).configure {
cppCompiler.args.remove('-Wno-error=deprecated-declarations')
cppCompiler.args.add('-Werror=deprecated-declarations')
}
nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.windowsx64).configure {
linker.args.remove('/DEBUG:FULL')
cppCompiler.debugArgs.remove('/Zi')
@@ -149,13 +144,6 @@ model {
lib project: ':cameraserver', library: 'cameraserver', linkage: 'shared'
lib project: ':wpinet', library: 'wpinet', linkage: 'shared'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
binary.tasks.withType(CppCompile) {
if (!(binary.toolChain in VisualCpp)) {
cppCompiler.args "-Wno-error=deprecated-declarations"
} else {
cppCompiler.args "/wd4996"
}
}
if (binary.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
nativeUtils.useRequiredLibrary(binary, 'ni_link_libraries', 'ni_runtime_libraries')
}

View File

@@ -39,11 +39,6 @@ model {
}
}
}
binary.tasks.withType(CppCompile) {
cppCompiler.args "-Wno-missing-field-initializers"
cppCompiler.args "-Wno-unused-variable"
cppCompiler.args "-Wno-error=deprecated-declarations"
}
lib project: ':wpilibc', library: 'wpilibc', linkage: 'shared'
lib project: ':wpimath', library: 'wpimath', linkage: 'shared'
lib project: ':ntcore', library: 'ntcore', linkage: 'shared'

View File

@@ -69,6 +69,7 @@ class EncoderSimTest {
}
}
@SuppressWarnings("deprecation") // Encoder.getPeriod()
@Test
void testPeriod() {
HAL.initialize(500, 0);

View File

@@ -1750,7 +1750,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
} else {
/* Silence GetVersionEx() deprecation warning. */
#ifdef _MSC_VER
#pragma warning(suppress : 4996)
#pragma warning(disable : 4996)
#endif
if (GetVersionExW(&os_info) == 0) {
r = uv_translate_sys_error(GetLastError());

View File

@@ -9,4 +9,23 @@
#define WPI_DEPRECATED(msg) [[deprecated(msg)]]
#endif
#ifndef WPI_IGNORE_DEPRECATED
#ifdef __GNUC__
#define WPI_IGNORE_DEPRECATED \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#elif defined(_WIN32)
#define WPI_IGNORE_DEPRECATED _Pragma("warning(disable : 4996)")
#endif
#endif
#ifndef WPI_UNIGNORE_DEPRECATED
#ifdef __GNUC__
#define WPI_UNIGNORE_DEPRECATED _Pragma("GCC diagnostic pop")
#elif defined(_WIN32)
#define WPI_UNIGNORE_DEPRECATED _Pragma("warning(default : 4996)")
#endif
#endif
#endif // WPIUTIL_WPI_DEPRECATED_H_