[bazel] Clean up bazel scripts (#7984)

This commit is contained in:
PJ Reiniger
2025-06-13 23:53:09 -04:00
committed by GitHub
parent 5dfc664b93
commit fbbc4bc53c
54 changed files with 1774 additions and 854 deletions

View File

@@ -5,13 +5,13 @@ def build_examples(halsim_deps = []):
for folder in EXAMPLE_FOLDERS:
cc_library(
name = folder + "-examples-headers",
hdrs = native.glob(["src/main/cpp/examples/" + folder + "/include/**/*.h"]),
hdrs = native.glob(["src/main/cpp/examples/" + folder + "/include/**/*.h"], allow_empty = True),
strip_include_prefix = "src/main/cpp/examples/" + folder + "/include",
tags = ["wpi-example"],
)
cc_binary(
name = folder + "-example",
srcs = native.glob(["src/main/cpp/examples/" + folder + "/cpp/**/*.cpp", "src/main/cpp/examples/" + folder + "/c/**/*.c"]),
srcs = native.glob(["src/main/cpp/examples/" + folder + "/cpp/**/*.cpp", "src/main/cpp/examples/" + folder + "/c/**/*.c"], allow_empty = True),
deps = [
"//wpilibNewCommands:wpilibNewCommands.static",
"//apriltag:apriltag.static",
@@ -40,7 +40,6 @@ def build_snippets():
cc_library(
name = folder + "-template",
srcs = native.glob(["src/main/cpp/snippets/" + folder + "/**/*.cpp"]),
hdrs = native.glob(["src/main/cpp/snippets/" + folder + "/**/*.h"]),
deps = [
"//wpilibNewCommands:wpilibNewCommands.static",
],
@@ -68,7 +67,7 @@ def build_tests():
cc_test(
name = folder + "-test",
size = "small",
srcs = native.glob([example_test_folder + "/**/*.cpp", example_src_folder + "/cpp/**/*.cpp", example_src_folder + "/c/**/*.c"]),
srcs = native.glob([example_test_folder + "/**/*.cpp", example_src_folder + "/cpp/**/*.cpp", example_src_folder + "/c/**/*.c"], allow_empty = True),
deps = [
"//wpilibNewCommands:wpilibNewCommands.static",
":{}-examples-headers".format(folder),

View File

@@ -91,5 +91,12 @@ TEMPLATES_FOLDERS = [
]
TESTS_FOLDERS = [
"ArmSimulation",
"DigitalCommunication",
"ElevatorSimulation",
"I2CCommunication",
"MecanumControllerCommand",
"PotentiometerPID",
"SwerveControllerCommand",
"UnitTest",
]

View File

@@ -164,7 +164,8 @@
],
"foldername": "PotentiometerPID",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "Elevator with exponential profiled PID",
@@ -257,7 +258,8 @@
],
"foldername": "I2CCommunication",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "Digital Communication Sample",
@@ -268,7 +270,8 @@
],
"foldername": "DigitalCommunication",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "HTTP Camera",
@@ -474,7 +477,8 @@
],
"foldername": "MecanumControllerCommand",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "SwerveControllerCommand",
@@ -491,7 +495,8 @@
],
"foldername": "SwerveControllerCommand",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "DriveDistanceOffboard",
@@ -615,7 +620,8 @@
],
"foldername": "ElevatorSimulation",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "Elevator Exponential Profile Simulation",
@@ -675,7 +681,8 @@
],
"foldername": "ArmSimulation",
"gradlebase": "cpp",
"commandversion": 2
"commandversion": 2,
"hasunittests": true
},
{
"name": "UnitTesting",

View File

@@ -1,64 +0,0 @@
// 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 <thread>
#include <frc/simulation/DriverStationSim.h>
#include <frc/simulation/SimHooks.h>
#include <gtest/gtest.h>
#include <units/time.h>
#include "Robot.h"
class MecanumControllerCommandTest : public testing::Test {
Robot m_robot;
std::optional<std::thread> m_thread;
bool joystickWarning;
public:
void SetUp() override {
frc::sim::PauseTiming();
joystickWarning = frc::DriverStation::IsJoystickConnectionWarningSilenced();
frc::DriverStation::SilenceJoystickConnectionWarning(true);
m_thread = std::thread([&] { m_robot.StartCompetition(); });
frc::sim::StepTiming(0.0_ms); // Wait for Notifiers
}
void TearDown() override {
m_robot.EndCompetition();
m_thread->join();
frc::sim::DriverStationSim::ResetData();
frc::DriverStation::SilenceJoystickConnectionWarning(joystickWarning);
}
};
TEST_F(MecanumControllerCommandTest, Match) {
// auto
frc::sim::DriverStationSim::SetAutonomous(true);
frc::sim::DriverStationSim::SetEnabled(true);
frc::sim::DriverStationSim::NotifyNewData();
frc::sim::StepTiming(15_s);
// brief disabled period- exact duration shouldn't matter
frc::sim::DriverStationSim::SetAutonomous(false);
frc::sim::DriverStationSim::SetEnabled(false);
frc::sim::DriverStationSim::NotifyNewData();
frc::sim::StepTiming(3_s);
// teleop
frc::sim::DriverStationSim::SetAutonomous(false);
frc::sim::DriverStationSim::SetEnabled(true);
frc::sim::DriverStationSim::NotifyNewData();
frc::sim::StepTiming(135_s);
// end of match
frc::sim::DriverStationSim::SetAutonomous(false);
frc::sim::DriverStationSim::SetEnabled(false);
frc::sim::DriverStationSim::NotifyNewData();
}

View File

@@ -1,16 +0,0 @@
// 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 <gtest/gtest.h>
#include <hal/HALBase.h>
/**
* Runs all unit tests.
*/
int main(int argc, char** argv) {
HAL_Initialize(500, 0);
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}