Clean up build (#1572)

Fixes #1564. Also copies vendordep JSONs to the examples as advised by
Thad. Removes unused shared/javacpp/setupBuild.gradle. Also removes
unnecessary `chmod +x gradlew` from CI workflows.
This commit is contained in:
Gold856
2024-11-16 21:30:34 -05:00
committed by GitHub
parent 097e641789
commit eff95c09f1
19 changed files with 88 additions and 248 deletions

View File

@@ -68,23 +68,14 @@ jobs:
- name: Install RoboRIO Toolchain
run: ./gradlew installRoboRioToolchain
# Need to publish to maven local first, so that C++ sim can pick it up
# Still haven't figured out how to make the vendordep file be copied before trying to build examples
- name: Publish photonlib to maven local
run: |
chmod +x gradlew
./gradlew photon-targeting:publishtomavenlocal photon-lib:publishtomavenlocal -x check
run: ./gradlew photon-targeting:publishtomavenlocal photon-lib:publishtomavenlocal -x check
- name: Build Java examples
working-directory: photonlib-java-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build
run: ./gradlew build
- name: Build C++ examples
working-directory: photonlib-cpp-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build
run: ./gradlew build
build-gradle:
name: "Gradle Build"
runs-on: ubuntu-22.04
@@ -104,9 +95,7 @@ jobs:
- name: Install mrcal deps
run: sudo apt-get update && sudo apt-get install -y libcholmod3 liblapack3 libsuitesparseconfig5
- name: Gradle Build
run: |
chmod +x gradlew
./gradlew photon-targeting:build photon-core:build photon-server:build -x check
run: ./gradlew photon-targeting:build photon-core:build photon-server:build -x check
- name: Gradle Tests
run: ./gradlew testHeadless -i --stacktrace
- name: Gradle Coverage
@@ -165,7 +154,6 @@ jobs:
# Generate the JSON and give it the ""standard""" name maven gives it
- run: |
chmod +x gradlew
./gradlew photon-lib:generateVendorJson
export VERSION=$(git describe --tags --match=v*)
mv photon-lib/build/generated/vendordeps/photonlib.json photon-lib/build/generated/vendordeps/photonlib-$(git describe --tags --match=v*).json
@@ -205,9 +193,7 @@ jobs:
distribution: temurin
architecture: ${{ matrix.architecture }}
- run: git fetch --tags --force
- run: |
chmod +x gradlew
./gradlew photon-targeting:build photon-lib:build -i
- run: ./gradlew photon-targeting:build photon-lib:build -i
name: Build with Gradle
- run: ./gradlew photon-lib:publish photon-targeting:publish
name: Publish
@@ -248,13 +234,9 @@ jobs:
git config --global --add safe.directory /__w/photonvision/photonvision
- name: Build PhotonLib
# We don't need to run tests, since we specify only non-native platforms
run: |
chmod +x gradlew
./gradlew photon-targeting:build photon-lib:build ${{ matrix.build-options }} -i -x test
run: ./gradlew photon-targeting:build photon-lib:build ${{ matrix.build-options }} -i -x test
- name: Publish
run: |
chmod +x gradlew
./gradlew photon-lib:publish photon-targeting:publish ${{ matrix.build-options }}
run: ./gradlew photon-lib:publish photon-targeting:publish ${{ matrix.build-options }}
env:
ARTIFACTORY_API_KEY: ${{ secrets.ARTIFACTORY_API_KEY }}
if: github.event_name == 'push' && github.repository_owner == 'photonvision'
@@ -350,13 +332,9 @@ jobs:
with:
name: built-docs
path: photon-server/src/main/resources/web/docs
- run: |
chmod +x gradlew
./gradlew photon-targeting:jar photon-server:shadowJar -PArchOverride=${{ matrix.arch-override }}
- run: ./gradlew photon-targeting:jar photon-server:shadowJar -PArchOverride=${{ matrix.arch-override }}
if: ${{ (matrix.arch-override != 'none') }}
- run: |
chmod +x gradlew
./gradlew photon-server:shadowJar
- run: ./gradlew photon-server:shadowJar
if: ${{ (matrix.arch-override == 'none') }}
- uses: actions/upload-artifact@v4
with:

View File

@@ -61,9 +61,7 @@ jobs:
with:
java-version: 17
distribution: temurin
- run: |
chmod +x gradlew
./gradlew spotlessCheck
- run: ./gradlew spotlessCheck
name: Run spotless
client-lint-format:

22
.gitignore vendored
View File

@@ -131,27 +131,12 @@ New client/photon-client/*
*.jfr
.DS_Store
# *.iml
photon-server/build
photon-server/photon-vision
photon-server/src/main/resources/web
photon-server/src/main/java/org/photonvision/PhotonVersion.java
photon-server/src/main/generated/native/include/org_photonvision_raspi_PicamJNI.h
*.bin
.gradle
.gradle/*
photonvision_config
build/spotlessJava
build/*
build
photon-lib/src/main/java/org/photonvision/PhotonVersion.java
photon-lib/bin/main/images/*
/photonlib-java-examples/bin/
photon-lib/src/generate/native/include/PhotonVersion.h
.gitattributes
lib/*
photon-server/lib/libapriltag.so
photon-server/bin/main/nativelibraries/apriltag/*
photon-server/src/main/resources/nativelibraries/apriltag/*
bin*/
build*/
photonlib-java-examples/*/vendordeps/*
photonlib-cpp-examples/*/vendordeps/*
@@ -162,9 +147,6 @@ photonlib-cpp-examples/*/networktables.json.bck
photonlib-java-examples/*/networktables.json.bck
*.sqlite
photon-server/src/main/resources/web/index.html
photon-lib/src/generate/native/cpp/PhotonVersion.cpp
venv
.venv/*
.venv

View File

@@ -67,7 +67,7 @@ spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**', "photon-core\\src\\main\\java\\org\\photonvision\\PhotonVersion.java", "photon-lib\\src\\main\\java\\org\\photonvision\\PhotonVersion.java", "**/src/generated/**"
exclude '**/build/**', '**/build-*/**', '**/src/generated/**'
}
toggleOffOn()
googleJavaFormat()

View File

@@ -139,25 +139,7 @@ The `deploy` command is tested against Raspberry Pi coprocessors. Other similar
### Using PhotonLib Builds
The build process includes the following task:
```{eval-rst}
.. tab-set::
.. tab-item:: Linux
``./gradlew generateVendorJson``
.. tab-item:: macOS
``./gradlew generateVendorJson``
.. tab-item:: Windows (cmd)
``gradlew generateVendorJson``
```
This generates a vendordep JSON of your local build at `photon-lib/build/generated/vendordeps/photonlib.json`.
The build process automatically generates a vendordep JSON of your local build at `photon-lib/build/generated/vendordeps/photonlib.json`.
The photonlib source can be published to your local maven repository after building:
@@ -247,17 +229,15 @@ You can run one of the many built in examples straight from the command line, to
#### Running C++/Java
PhotonLib must first be published to your local maven repository, then the copy PhotonLib task will copy the generated vendordep json file into each example. After that, the simulateJava/simulateNative task can be used like a normal robot project. Robot simulation with attached debugger is technically possible by using simulateExternalJava and modifying the launch script it exports, though not yet supported.
PhotonLib must first be published to your local maven repository. This will also copy the generated vendordep json file into each example. After that, the simulateJava/simulateNative task can be used like a normal robot project. Robot simulation with attached debugger is technically possible by using simulateExternalJava and modifying the launch script it exports, though not yet supported.
```
~/photonvision$ ./gradlew publishToMavenLocal
~/photonvision$ cd photonlib-java-examples
~/photonvision/photonlib-java-examples$ ./gradlew copyPhotonlib
~/photonvision/photonlib-java-examples$ ./gradlew <example-name>:simulateJava
~/photonvision$ cd photonlib-cpp-examples
~/photonvision/photonlib-cpp-examples$ ./gradlew copyPhotonlib
~/photonvision/photonlib-cpp-examples$ ./gradlew <example-name>:simulateNative
```

View File

@@ -11,5 +11,3 @@ photonvision/*
photonvision_config/*
photon-server/lib/*
photon-server/package-lock.json
src/main/java/org/photonvision/PhotonVersion.java

View File

@@ -65,9 +65,13 @@ dependencies {
}
task writeCurrentVersion {
def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in")
writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "main", "java", "org", "photonvision", "PhotonVersion.java"),
versionString)
doLast {
def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in")
writePhotonVersionFile(versionFileIn, Path.of("$buildDir", "generated", "java", "org", "photonvision", "PhotonVersion.java"),
versionString)
}
}
// https://github.com/wpilibsuite/allwpilib/blob/main/wpilibj/build.gradle#L52
sourceSets.main.java.srcDir "${buildDir}/generated/java/"
build.dependsOn writeCurrentVersion
compileJava.dependsOn writeCurrentVersion

View File

@@ -33,7 +33,7 @@ model {
sources {
cpp {
source {
srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp", "src/generate/native/cpp"
srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp", "$buildDir/generated/native/cpp"
include '**/*.cpp', '**/*.cc'
}
exportedHeaders {
@@ -161,14 +161,12 @@ task generateVendorJson() {
def read = photonlibFileInput.text
.replace('${photon_version}', pubVersion)
.replace('${frc_year}', frcYear)
.replace('${wpilib_version}', wpilibVersion)
photonlibFileOutput.text = read
outputs.upToDateWhen { false }
}
build.mustRunAfter generateVendorJson
publish.mustRunAfter generateVendorJson
build.dependsOn generateVendorJson
task publishVendorJsonToLocalOutputs(type: Copy) {
from photonlibFileOutput
@@ -182,17 +180,69 @@ task publishVendorJsonToLocalOutputs(type: Copy) {
publish.dependsOn it
}
task writeCurrentVersion {
def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in")
writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "main", "java", "org", "photonvision", "PhotonVersion.java"),
versionString)
versionFileIn = file("${rootDir}/shared/PhotonVersion.cpp.in")
writePhotonVersionFile(versionFileIn, Path.of("$projectDir", "src", "generate", "native", "cpp", "PhotonVersion.cpp"),
versionString)
task copyVendorJsonToExamples {
outputs.upToDateWhen { false }
jar.finalizedBy it
}
build.mustRunAfter writeCurrentVersion
cppHeadersZip.dependsOn writeCurrentVersion
[
"photonlib-cpp-examples",
"photonlib-java-examples"
].each { exampleFolder ->
file("${rootDir}/${exampleFolder}")
.listFiles()
.findAll {
return (it.isDirectory()
&& !it.isHidden()
&& !it.name.startsWith(".")
&& it.toPath().resolve("build.gradle").toFile().exists())
}
.collect { it.name }
.each { exampleVendordepFolder ->
task "copyVendorJsonTo${exampleFolder}-${exampleVendordepFolder}"(type: Copy) {
from photonlibFileOutput
into "${rootDir}/${exampleFolder}/${exampleVendordepFolder}/vendordeps/"
outputs.upToDateWhen { false }
copyVendorJsonToExamples.dependsOn it
}
}
}
clean {
[
"photonlib-cpp-examples",
"photonlib-java-examples"
].each { exampleFolder ->
file("${rootDir}/${exampleFolder}")
.listFiles()
.findAll {
return (it.isDirectory()
&& !it.isHidden()
&& !it.name.startsWith(".")
&& it.toPath().resolve("build.gradle").toFile().exists())
}
.collect { it.name }
.each { exampleVendordepFolder ->
delete "${rootDir}/${exampleFolder}/${exampleVendordepFolder}/vendordeps/"
}
}
}
task writeCurrentVersion {
doLast {
def versionFileIn = file("${rootDir}/shared/PhotonVersion.java.in")
writePhotonVersionFile(versionFileIn, Path.of("$buildDir", "generated", "java", "org", "photonvision", "PhotonVersion.java"),
versionString)
versionFileIn = file("${rootDir}/shared/PhotonVersion.cpp.in")
writePhotonVersionFile(versionFileIn, Path.of("$buildDir", "generated", "native", "cpp", "PhotonVersion.cpp"),
versionString)
}
}
// https://github.com/wpilibsuite/allwpilib/blob/main/wpilibj/build.gradle#L52
sourceSets.main.java.srcDir "${buildDir}/generated/java/"
compileJava.dependsOn writeCurrentVersion
// Building photon-lib requires photon-targeting to generate its proto files. This technically shouldn't be required but is needed for it to build.
model {
@@ -206,6 +256,7 @@ model {
}
it.binaries.all {
it.tasks.withType(CppCompile) {
it.dependsOn writeCurrentVersion
it.dependsOn ":photon-targeting:generateProto"
}
}
@@ -243,7 +294,7 @@ if (!project.hasProperty('copyOfflineArtifacts')) {
tasks.named('cppSourcesZip') {
dependsOn writeCurrentVersion
from("$projectDir/src/generate/native/cpp") {
from("$buildDir/generated/native/cpp") {
into '/'
}
}
@@ -252,7 +303,6 @@ tasks.named('cppSourcesZip') {
def zipBaseNameCombined = '_GROUP_org.photonvision_combinedcpp_ID_photonvision-combinedcpp_CLS'
task combinedCppSourcesZip(type: Zip) {
dependsOn(':photon-lib:cppSourcesZip', ':photon-targeting:cppSourcesZip')
mustRunAfter(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip')
destinationDirectory = file("$buildDir/outputs")
archiveBaseName = zipBaseNameCombined
@@ -270,7 +320,6 @@ task combinedCppSourcesZip(type: Zip) {
}
task combinedHeadersZip(type: Zip) {
dependsOn(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip')
mustRunAfter(':photon-lib:cppHeadersZip', ':photon-targeting:cppHeadersZip')
destinationDirectory = file("$buildDir/outputs")
archiveBaseName = zipBaseNameCombined
@@ -316,7 +365,6 @@ def nativeTasks = wpilibTools.createExtractionTasks {
nativeTasks.addToSourceSetResources(sourceSets.test)
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpilibc")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")

View File

@@ -9,5 +9,3 @@ build
build/*
photonvision/*
photonvision_config/*
src/main/java/org/photonvision/PhotonVersion.java

View File

@@ -14,8 +14,6 @@ wpi.maven.useDevelopment = false
wpi.versions.wpilibVersion = "2025.1.1-beta-1"
wpi.versions.wpimathVersion = "2025.1.1-beta-1"
apply from: "${rootDir}/../shared/examples_common.gradle"
// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project DeployUtils.
deploy {

View File

@@ -14,8 +14,6 @@ wpi.maven.useDevelopment = false
wpi.versions.wpilibVersion = "2025.1.1-beta-1"
wpi.versions.wpimathVersion = "2025.1.1-beta-1"
apply from: "${rootDir}/../shared/examples_common.gradle"
// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project DeployUtils.
deploy {

View File

@@ -22,9 +22,5 @@ spotless {
}
java {
target "**/*.java"
targetExclude("photon-core/src/main/java/org/photonvision/PhotonVersion.java")
targetExclude("photon-lib/src/main/java/org/photonvision/PhotonVersion.java")
}
}
apply from: "examples.gradle"

View File

@@ -14,8 +14,6 @@ wpi.maven.useDevelopment = false
wpi.versions.wpilibVersion = "2025.1.1-beta-1"
wpi.versions.wpimathVersion = "2025.1.1-beta-1"
apply from: "${rootDir}/../shared/examples_common.gradle"
// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project DeployUtils.
deploy {

View File

@@ -6,8 +6,6 @@ plugins {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
apply from: "${rootDir}/../shared/examples_common.gradle"
def ROBOT_MAIN_CLASS = "frc.robot.Main"
repositories {

View File

@@ -6,8 +6,6 @@ plugins {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
apply from: "${rootDir}/../shared/examples_common.gradle"
def ROBOT_MAIN_CLASS = "frc.robot.Main"
wpi.maven.useDevelopment = true

View File

@@ -2,8 +2,6 @@ plugins {
id "com.diffplug.spotless" version "6.1.2"
}
apply from: "examples.gradle"
allprojects {
repositories {
mavenCentral()
@@ -24,7 +22,5 @@ spotless {
}
java {
target "**/*.java"
targetExclude("photon-core/src/main/java/org/photonvision/PhotonVersion.java")
targetExclude("photon-lib/src/main/java/org/photonvision/PhotonVersion.java")
}
}

View File

@@ -6,8 +6,6 @@ plugins {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
apply from: "${rootDir}/../shared/examples_common.gradle"
def ROBOT_MAIN_CLASS = "frc.robot.Main"
wpi.maven.useDevelopment = true

View File

@@ -1,20 +0,0 @@
task copyPhotonlib() {
doFirst {
// Assume publish to maven local has just be run. Kinda curst
def vendorJsonSrc = new File("${rootDir}", "../photon-lib/build/generated/vendordeps/");
def vendorJsonDst = new File("${projectDir}/vendordeps/");
delete(fileTree(vendorJsonDst) {
exclude '.gitignore'
})
println("Copying from ${vendorJsonSrc} to ${vendorJsonDst}")
copy {
from vendorJsonSrc
into vendorJsonDst
}
}
outputs.upToDateWhen { false }
}

View File

@@ -1,106 +0,0 @@
apply plugin: 'cpp'
apply plugin: 'google-test-test-suite'
apply from: "${rootDir}/shared/config.gradle"
apply from: "${rootDir}/shared/javacommon.gradle"
wpilibTools.deps.wpilibVersion = wpi.versions.wpilibVersion.get()
def nativeConfigName = 'wpilibNatives'
def nativeConfig = configurations.create(nativeConfigName)
def nativeTasks = wpilibTools.createExtractionTasks {
configurationName = nativeConfigName
}
nativeTasks.addToSourceSetResources(sourceSets.main)
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("apriltag")
nativeConfig.dependencies.add wpilibTools.deps.wpilib("hal")
nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv("frc" + openCVYear, wpi.versions.opencvVersion.get())
// Windows specific functionality to export all symbols from a binary automatically
nativeUtils {
exportsConfigs {
"${nativeName}" {}
}
}
model {
components {
"${nativeName}"(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp"
include '**/*.cpp', '**/*.cc'
}
exportedHeaders {
srcDirs 'src/main/native/include', "$buildDir/generated/source/proto/main/cpp"
if (project.hasProperty('generatedHeaders')) {
srcDir generatedHeaders
}
include "**/*.h"
}
}
}
binaries.all {
it.tasks.withType(CppCompile) {
it.dependsOn generateProto
}
if(project.hasProperty('includePhotonTargeting')) {
lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared'
}
}
nativeUtils.useRequiredLibrary(it, "wpilib_shared")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
}
}
testSuites {
"${nativeName}Test"(GoogleTestTestSuiteSpec) {
for(NativeComponentSpec c : $.components) {
if (c.name == nativeName) {
testing c
break
}
}
sources {
cpp {
source {
srcDirs 'src/test/native/cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDirs 'src/test/native/include', "$buildDir/generated/source/proto/main/cpp"
}
}
}
binaries.all {
it.tasks.withType(CppCompile) {
it.dependsOn generateProto
}
if(project.hasProperty('includePhotonTargeting')) {
lib project: ':photon-targeting', library: 'photontargeting', linkage: 'shared'
}
}
nativeUtils.useRequiredLibrary(it, "cscore_shared")
nativeUtils.useRequiredLibrary(it, "cameraserver_shared")
nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared")
nativeUtils.useRequiredLibrary(it, "googletest_static")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
}
}
}
apply from: "${rootDir}/shared/javacpp/publish.gradle"