[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

@@ -1,9 +1,10 @@
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_python//python:defs.bzl", "py_binary")
load("//ntcore:generate_ntcore.bzl", "generate_ntcore")
load("//shared/bazel/rules:cc_rules.bzl", "third_party_cc_lib_helper", "wpilib_cc_library")
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test")
load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library")
@@ -28,7 +29,6 @@ py_binary(
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
deps = [requirement("jinja2")],
)
@@ -42,50 +42,40 @@ write_source_files(
visibility = ["//visibility:public"],
)
cc_library(
name = "generated_cc_headers",
hdrs = glob(["src/generated/main/native/include/**"]),
includes = ["src/generated/main/native/include"],
strip_include_prefix = "src/generated/main/native/include",
visibility = ["//ntcore:__subpackages__"],
)
filegroup(
name = "generated_cc_source",
srcs = glob(
["src/generated/main/native/cpp/**"],
exclude = ["src/generated/main/native/cpp/jni/**"],
),
visibility = ["//ntcore:__subpackages__"],
third_party_cc_lib_helper(
name = "generated_cc",
include_root = "src/generated/main/native/include",
src_excludes = ["src/generated/main/native/cpp/jni/**"],
src_root = "src/generated/main/native/cpp",
)
filegroup(
name = "generated_jni",
srcs = glob(["src/generated/main/native/cpp/jni/**"]),
visibility = ["//ntcore:__subpackages__"],
)
filegroup(
name = "generated_java",
srcs = glob(["src/generated/main/java/**/*.java"]),
visibility = ["//ntcore:__subpackages__"],
)
cc_library(
wpilib_cc_library(
name = "ntcore.static",
srcs = glob(
["src/main/native/cpp/**"],
exclude = ["src/main/native/cpp/jni/**"],
) + [":generated_cc_source"],
),
hdrs = glob(["src/main/native/include/**/*"]),
includes = [
"src/main/native/cpp",
"src/main/native/include",
],
strip_include_prefix = "src/main/native/include",
third_party_libraries = [
":generated_cc",
],
visibility = ["//visibility:public"],
deps = [
":generated_cc_headers",
"//datalog:datalog.static",
"//wpinet:wpinet.static",
"//wpiutil:wpiutil.static",

View File

@@ -1,49 +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.
import edu.wpi.first.wpilibj.networktables.*;
import edu.wpi.first.wpilibj.tables.*;
public class Client {
private static class MyLogger implements NetworkTablesJNI.LoggerFunction {
public void apply(int level, String file, int line, String msg) {
System.err.println(msg);
}
}
public static void main(String[] args) {
NetworkTablesJNI.setLogger(new MyLogger(), 0);
NetworkTable.setIPAddress("127.0.0.1");
NetworkTable.setPort(10000);
NetworkTable.setClientMode();
NetworkTable nt = NetworkTable.getTable("");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
try {
System.out.println("Got foo: " + nt.getNumber("foo"));
} catch (TableKeyNotDefinedException ex) {
}
nt.putBoolean("bar", false);
nt.setFlags("bar", NetworkTable.PERSISTENT);
nt.putBoolean("bar2", true);
nt.putBoolean("bar2", false);
nt.putBoolean("bar2", true);
nt.putString("str", "hello world");
double[] nums = new double[3];
nums[0] = 0.5;
nums[1] = 1.2;
nums[2] = 3.0;
nt.putNumberArray("numarray", nums);
String[] strs = new String[2];
strs[0] = "Hello";
strs[1] = "World";
nt.putStringArray("strarray", strs);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
}
}

View File

@@ -1,36 +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.
import edu.wpi.first.wpilibj.networktables.*;
import edu.wpi.first.wpilibj.tables.*;
public class Server {
private static class MyLogger implements NetworkTablesJNI.LoggerFunction {
public void apply(int level, String file, int line, String msg) {
System.err.println(msg);
}
}
public static void main(String[] args) {
NetworkTablesJNI.setLogger(new MyLogger(), 0);
NetworkTable.setIPAddress("127.0.0.1");
NetworkTable.setPort(10000);
NetworkTable.setServerMode();
NetworkTable nt = NetworkTable.getTable("");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
nt.putNumber("foo", 0.5);
nt.setFlags("foo", NetworkTable.PERSISTENT);
nt.putNumber("foo2", 0.5);
nt.putNumber("foo2", 0.7);
nt.putNumber("foo2", 0.6);
nt.putNumber("foo2", 0.5);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
}
}

View File

@@ -1,39 +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 <chrono>
#include <climits>
#include <cstdio>
#include <thread>
#include "ntcore.h"
int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartClient(inst, "127.0.0.1", 10000);
std::this_thread::sleep_for(std::chrono::seconds(2));
auto foo = nt::GetEntry(inst, "/foo");
auto foo_val = nt::GetEntryValue(foo);
if (foo_val && foo_val->IsDouble()) {
std::printf("Got foo: %g\n", foo_val->GetDouble());
}
auto bar = nt::GetEntry(inst, "/bar");
nt::SetEntryValue(bar, nt::Value::MakeBoolean(false));
nt::SetEntryFlags(bar, NT_PERSISTENT);
auto bar2 = nt::GetEntry(inst, "/bar2");
nt::SetEntryValue(bar2, nt::Value::MakeBoolean(true));
nt::SetEntryValue(bar2, nt::Value::MakeBoolean(false));
nt::SetEntryValue(bar2, nt::Value::MakeBoolean(true));
std::this_thread::sleep_for(std::chrono::seconds(10));
}

View File

@@ -1,35 +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 <chrono>
#include <climits>
#include <cstdio>
#include <thread>
#include "ntcore.h"
int main() {
auto inst = nt::GetDefaultInstance();
nt::AddLogger(
inst,
[](const nt::LogMessage& msg) {
std::fputs(msg.message.c_str(), stderr);
std::fputc('\n', stderr);
},
0, UINT_MAX);
nt::StartServer(inst, "persistent.ini", "", 10000);
std::this_thread::sleep_for(std::chrono::seconds(1));
auto foo = nt::GetEntry(inst, "/foo");
nt::SetEntryValue(foo, nt::Value::MakeDouble(0.5));
nt::SetEntryFlags(foo, NT_PERSISTENT);
auto foo2 = nt::GetEntry(inst, "/foo2");
nt::SetEntryValue(foo2, nt::Value::MakeDouble(0.5));
nt::SetEntryValue(foo2, nt::Value::MakeDouble(0.7));
nt::SetEntryValue(foo2, nt::Value::MakeDouble(0.6));
nt::SetEntryValue(foo2, nt::Value::MakeDouble(0.5));
std::this_thread::sleep_for(std::chrono::seconds(10));
}