Skip to content

Commit

Permalink
[datalog] Move all DataLog functionality to new datalog library (#7641)
Browse files Browse the repository at this point in the history
Currently the major DataLog backend API (reading and writing) is split between wpiutil and glass. In the interest of allowing code that wants to use these APIs to not need to link to glass and declutter wpiutil, all of those APIs are moved to a new library named "datalog".

Signed-off-by: Jade Turner <spacey-sooty@proton.me>
Co-authored-by: Jade Turner <spacey-sooty@proton.me>
Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 20, 2025
1 parent ac1705a commit da47f06
Show file tree
Hide file tree
Showing 99 changed files with 778 additions and 330 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ set(WPIUNITS_DEP_REPLACE_IMPL "find_dependency(wpiunits)")
set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
add_subdirectory(wpiutil)

add_subdirectory(datalog)

if(WITH_NTCORE)
set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
set(WPINET_DEP_REPLACE "find_dependency(wpinet)")
Expand Down
29 changes: 29 additions & 0 deletions datalog/.styleguide
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cppHeaderFileInclude {
\.h$
}

cppSrcFileInclude {
\.cpp$
}

licenseUpdateExclude {
examples/printlog
}

modifiableFileExclude {
examples/printlog/datalog\.py$
}

repoRootNameOverride {
datalog
}

includeOtherLibs {
^fmt/
^gtest/
^wpi/(?!datalog)
}

includeProject {
^wpi/datalog/
}
106 changes: 106 additions & 0 deletions datalog/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_python//python:defs.bzl", "py_binary")
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")

cc_library(
name = "datalog.static",
srcs = glob(
["src/main/native/cpp/**"],
exclude = ["src/main/native/cpp/jni/**"],
),
hdrs = glob(["src/main/native/include/**"]),
includes = [
"src/main/native/cpp",
"src/main/native/include",
],
strip_include_prefix = "src/main/native/include",
visibility = ["//visibility:public"],
deps = [
"//wpiutil:wpiutil.static",
],
)

wpilib_jni_cc_library(
name = "datalogjni",
srcs = glob(["src/main/native/cpp/jni/**"]),
java_dep = ":datalog-java",
visibility = ["//visibility:public"],
deps = [
":datalog.static",
],
)

wpilib_jni_java_library(
name = "datalog-java",
srcs = glob(["src/main/java/**/*.java"]),
native_libs = [":datalogjni"],
visibility = ["//visibility:public"],
deps = [
"//wpiutil:wpiutil-java",
"@maven//:us_hebi_quickbuf_quickbuf_runtime",
],
)

py_binary(
name = "datalog",
srcs = ["examples/printlog/datalog.py"],
tags = ["manual"],
)

cc_binary(
name = "printlog",
srcs = ["examples/printlog/printlog.cpp"],
deps = [
":datalog.static",
"//wpiutil:wpiutil.static",
],
)

cc_binary(
name = "writelog",
srcs = ["examples/writelog/writelog.cpp"],
deps = [
":datalog.static",
"//wpiutil:wpiutil.static",
],
)

java_binary(
name = "printlog-java",
srcs = ["src/printlog/java/printlog/PrintLog.java"],
main_class = "printlog.PrintLog",
deps = [
":datalog-java",
],
)

cc_test(
name = "datalog-cpp-test",
size = "small",
srcs = glob([
"src/test/native/**/*.cpp",
"src/test/native/**/*.h",
]),
tags = [
"exclusive",
"no-asan",
"no-tsan",
],
deps = [
":datalog.static",
"//thirdparty/googletest:googletest.static",
"//wpiutil:wpiutil-testlib",
],
)

wpilib_java_junit5_test(
name = "datalog-java-test",
srcs = glob(["src/test/java/**/*.java"]),
tags = ["exclusive"],
deps = [
":datalog-java",
"//wpiutil:wpiutil-java",
],
)
108 changes: 108 additions & 0 deletions datalog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
project(datalog)

include(CompileWarnings)

file(GLOB datalog_native_src src/main/native/cpp/*.cpp)

file(GLOB datalog_jni_src src/main/native/cpp/jni/DataLogJNI.cpp)
list(REMOVE_ITEM datalog_native_src ${datalog_jni_src})

add_library(datalog ${datalog_native_src})
set_target_properties(datalog PROPERTIES DEBUG_POSTFIX "d")

target_compile_features(datalog PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(
datalog
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
)
target_compile_definitions(datalog PRIVATE -D_CRT_SECURE_NO_WARNINGS)
endif()
wpilib_target_warnings(datalog)

target_include_directories(
datalog
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
)

target_link_libraries(datalog PRIVATE wpiutil)

subdir_list(datalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
foreach(example ${datalog_examples})
file(GLOB datalog_example_src examples/${example}/*.cpp)
if(datalog_example_src)
add_executable(datalog_${example} ${datalog_example_src})
wpilib_target_warnings(datalog_${example})
target_link_libraries(datalog_${example} datalog wpiutil)
set_property(TARGET datalog_${example} PROPERTY FOLDER "examples")
endif()
endforeach()

# Java bindings
if(WITH_JAVA)
include(UseJava)

set(CMAKE_JNI_TARGET true)

file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar)

add_jar(
datalog_jar
${JAVA_SOURCES}
# INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR}
INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR}
OUTPUT_NAME datalog
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
GENERATE_NATIVE_HEADERS datalog_jni_headers
)
set_property(TARGET datalog_jar PROPERTY FOLDER "java")

install_jar(datalog_jar DESTINATION ${java_lib_dest})
install_jar_exports(TARGETS datalog_jar FILE datalog_jar.cmake DESTINATION share/datalog)

add_library(datalogjni ${datalog_jni_src})
wpilib_target_warnings(datalogjni)
target_link_libraries(datalogjni PUBLIC datalog wpiutil)

set_property(TARGET datalogjni PROPERTY FOLDER "libraries")

target_link_libraries(datalogjni PRIVATE datalog_jni_headers)
add_dependencies(datalogjni datalog_jar)

install(TARGETS datalogjni EXPORT datalogjni)
export(TARGETS datalogjni FILE datalogjni.cmake NAMESPACE datalogjni::)
endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
include(CreateSourceJar)
add_source_jar(
datalog_src_jar
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME datalog-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)
set_property(TARGET datalog_src_jar PROPERTY FOLDER "java")

install_jar(datalog_src_jar DESTINATION ${java_lib_dest})
endif()

install(TARGETS datalog EXPORT datalog)
export(TARGETS datalog FILE datalog.cmake NAMESPACE datalog::)

configure_file(datalog-config.cmake.in ${WPILIB_BINARY_DIR}/datalog-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/datalog-config.cmake DESTINATION share/datalog)
install(EXPORT datalog DESTINATION share/datalog)

if(WITH_TESTS)
file(GLOB_RECURSE datalog_testlib_src src/test/native/include/*.h)
add_library(datalog_testlib INTERFACE ${datalog_test_src})
target_include_directories(datalog_testlib INTERFACE src/test/native/include)

wpilib_add_test(datalog src/test/native/cpp)
target_link_libraries(datalog_test datalog googletest datalog_testlib wpiutil)
if(MSVC)
target_compile_options(datalog_test PRIVATE /utf-8)
endif()
endif()
32 changes: 32 additions & 0 deletions datalog/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ext {
useJava = true
useCpp = true
baseId = 'datalog'
groupId = 'edu.wpi.first.datalog'

nativeName = 'datalog'
devMain = 'edu.wpi.first.datalog.DevMain'
}

apply from: "${rootDir}/shared/jni/setupBuild.gradle"

nativeUtils.exportsConfigs {
datalog {
}
}

model {
components {
all {
it.sources.each {
it.exportedHeaders {
srcDirs 'src/main/native/include'
}
}
}
}
}

dependencies {
api project(":wpiutil")
}
5 changes: 5 additions & 0 deletions datalog/datalog-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@FILENAME_DEP_REPLACE@
include(${SELF_DIR}/wpiutil.cmake)
if(@WITH_JAVA@)
include(${SELF_DIR}/wpiutil_jar.cmake)
endif()
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include <fmt/chrono.h>
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <wpi/DenseMap.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/print.h>

#include "wpi/DataLogReader.h"
#include "wpi/DenseMap.h"
#include "wpi/MemoryBuffer.h"
#include "wpi/print.h"
#include "wpi/datalog/DataLogReader.h"

int main(int argc, const char** argv) {
if (argc != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include <utility>
#include <vector>

#include "wpi/DataLogBackgroundWriter.h"
#include "wpi/print.h"
#include <wpi/print.h>

#include "wpi/datalog/DataLogBackgroundWriter.h"

int main(int argc, char** argv) {
using std::chrono::duration_cast;
Expand Down
12 changes: 12 additions & 0 deletions datalog/src/dev/java/edu/wpi/first/datalog/DevMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.datalog;

public final class DevMain {
/** Main entry point. */
public static void main(String[] args) {}

private DevMain() {}
}
5 changes: 5 additions & 0 deletions datalog/src/dev/native/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 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.

int main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

/** Log boolean values. */
public class BooleanLogEntry extends DataLogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.util.protobuf.Protobuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

/**
* A data log background writer that periodically flushes the data log on a background thread. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

/** Log entry base class. */
public class DataLogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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.util.datalog;
package edu.wpi.first.datalog;

import java.util.Iterator;
import java.util.NoSuchElementException;
Expand Down
Loading

0 comments on commit da47f06

Please sign in to comment.