Skip to content

Commit

Permalink
Clean up build
Browse files Browse the repository at this point in the history
Fixes PhotonVision#1564. Also copies vendordep JSONs to the examples as advised by Thad. Removes unused shared/javacpp/setupBuild.gradle.
  • Loading branch information
Gold856 committed Nov 15, 2024
1 parent dfed7e3 commit 77db2ff
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 246 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ 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
Expand All @@ -77,13 +76,11 @@ jobs:
working-directory: photonlib-java-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build
- name: Build C++ examples
working-directory: photonlib-cpp-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew build
build-gradle:
name: "Gradle Build"
Expand Down
21 changes: 2 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,13 @@ 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
bin*/
build*/
.gitattributes
lib/*
photon-server/lib/libapriltag.so
photon-server/bin/main/nativelibraries/apriltag/*
photon-server/src/main/resources/nativelibraries/apriltag/*

photonlib-java-examples/*/vendordeps/*
photonlib-cpp-examples/*/vendordeps/*
Expand All @@ -162,9 +148,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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 2 additions & 22 deletions docs/source/docs/contributing/building-photon.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
```

Expand Down
2 changes: 0 additions & 2 deletions photon-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ photonvision/*
photonvision_config/*
photon-server/lib/*
photon-server/package-lock.json

src/main/java/org/photonvision/PhotonVersion.java
12 changes: 8 additions & 4 deletions photon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
78 changes: 63 additions & 15 deletions photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -182,17 +180,69 @@ task publishVendorJsonToLocalOutputs(type: Copy) {
publish.dependsOn it
}

task copyVendorJsonToExamples {
outputs.upToDateWhen { false }
jar.finalizedBy it
}

[
"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 {
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)
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)
}
}

build.mustRunAfter writeCurrentVersion
cppHeadersZip.dependsOn writeCurrentVersion
// 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 {
Expand Down Expand Up @@ -243,7 +293,7 @@ if (!project.hasProperty('copyOfflineArtifacts')) {
tasks.named('cppSourcesZip') {
dependsOn writeCurrentVersion

from("$projectDir/src/generate/native/cpp") {
from("$buildDir/generated/native/cpp") {
into '/'
}
}
Expand All @@ -252,7 +302,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
Expand All @@ -270,7 +319,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
Expand Down
2 changes: 0 additions & 2 deletions photon-targeting/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ build
build/*
photonvision/*
photonvision_config/*

src/main/java/org/photonvision/PhotonVersion.java
2 changes: 0 additions & 2 deletions photonlib-cpp-examples/aimandrange/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions photonlib-cpp-examples/aimattarget/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions photonlib-cpp-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 0 additions & 14 deletions photonlib-cpp-examples/examples.gradle

This file was deleted.

2 changes: 0 additions & 2 deletions photonlib-cpp-examples/poseest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions photonlib-cpp-examples/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
apply from: "examples.gradle"

exampleFolderNames.each { line -> include line }
2 changes: 0 additions & 2 deletions photonlib-java-examples/aimandrange/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions photonlib-java-examples/aimattarget/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions photonlib-java-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ plugins {
id "com.diffplug.spotless" version "6.1.2"
}

apply from: "examples.gradle"

allprojects {
repositories {
mavenCentral()
Expand All @@ -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")
}
}
14 changes: 0 additions & 14 deletions photonlib-java-examples/examples.gradle

This file was deleted.

2 changes: 0 additions & 2 deletions photonlib-java-examples/poseest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions photonlib-java-examples/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
apply from: "examples.gradle"

exampleFolderNames.each { line -> include line }
Loading

0 comments on commit 77db2ff

Please sign in to comment.