diff --git a/photonlib-cpp-examples/README.md b/photonlib-cpp-examples/README.md new file mode 100644 index 0000000000..c089f1366a --- /dev/null +++ b/photonlib-cpp-examples/README.md @@ -0,0 +1,16 @@ +## PhotonLib C++ Examples + +### Building + +Build photonvision and publish it locally with: + +``` +photonvision$ ./gradlew photon-lib:publishtomavenlocal +``` + +Now, cd into here, pull in the latest vendor json, and simulate the project of choice + +``` +photonvision/photonlib-cpp-exaples: ./gradlew copyPhotonlib +photonvision/photonlib-cpp-exaples: ./gradlew aimandrange:simulateNativeRelease +``` diff --git a/photonlib-cpp-examples/build.gradle b/photonlib-cpp-examples/build.gradle index 3605779a96..cb4661a3a9 100644 --- a/photonlib-cpp-examples/build.gradle +++ b/photonlib-cpp-examples/build.gradle @@ -27,9 +27,11 @@ spotless { } } +apply from: "examples.gradle" + // Task that depends on the build task for every example task buildAllExamples { task -> - new File('examples.txt').eachLine { line -> + exampleFolderNames.each { line -> task.dependsOn(line + ":build") } } diff --git a/photonlib-cpp-examples/examples.gradle b/photonlib-cpp-examples/examples.gradle new file mode 100644 index 0000000000..5a48c873ef --- /dev/null +++ b/photonlib-cpp-examples/examples.gradle @@ -0,0 +1,9 @@ +// These should be the only 2 non-project subdirectories in the examples folder +// I could check for (it)/build.gradle to exist, but w/e +def EXCLUDED_DIRS = [".gradle", "bin"] + +// List all non-hidden directories not in EXCUDED_DIRS +ext.exampleFolderNames = file("${rootDir}") + .listFiles() + .findAll { it.isDirectory() && !it.isHidden() && !(it.name in EXCLUDED_DIRS) } + .collect { it.name } diff --git a/photonlib-cpp-examples/examples.txt b/photonlib-cpp-examples/examples.txt deleted file mode 100644 index 25f7648520..0000000000 --- a/photonlib-cpp-examples/examples.txt +++ /dev/null @@ -1,4 +0,0 @@ -aimandrange -getinrange -aimattarget -apriltagExample diff --git a/photonlib-cpp-examples/settings.gradle b/photonlib-cpp-examples/settings.gradle index 51a82a8d56..4c125fe51c 100644 --- a/photonlib-cpp-examples/settings.gradle +++ b/photonlib-cpp-examples/settings.gradle @@ -1 +1,3 @@ -new File('examples.txt').eachLine { line -> include line } +apply from: "examples.gradle" + +exampleFolderNames.each { line -> include line } diff --git a/photonlib-java-examples/README.md b/photonlib-java-examples/README.md index ff4abbd9d7..ffd15b1f5f 100644 --- a/photonlib-java-examples/README.md +++ b/photonlib-java-examples/README.md @@ -1,5 +1,20 @@ ## PhotonLib Java Examples +### Building + +Build photonvision and publish it locally with: + +``` +photonvision$ ./gradlew photon-lib:publishtomavenlocal +``` + +Now, cd into here, pull in the latest vendor json, and simulate the project of choice + +``` +photonvision/photonlib-java-exaples: ./gradlew copyPhotonlib +photonvision/photonlib-java-exaples: ./gradlew aimandrange:simulateJava +``` + ### [**`aimattarget`**](aimattarget) A simple demonstration of using PhotonVision's 2d target yaw to align a differential drivetrain with a target. diff --git a/photonlib-java-examples/build.gradle b/photonlib-java-examples/build.gradle index 3605779a96..29a90b45f9 100644 --- a/photonlib-java-examples/build.gradle +++ b/photonlib-java-examples/build.gradle @@ -2,6 +2,8 @@ plugins { id "com.diffplug.spotless" version "6.1.2" } +apply from: "examples.gradle" + allprojects { repositories { mavenCentral() @@ -29,7 +31,7 @@ spotless { // Task that depends on the build task for every example task buildAllExamples { task -> - new File('examples.txt').eachLine { line -> + exampleFolderNames.each { line -> task.dependsOn(line + ":build") } } diff --git a/photonlib-java-examples/examples.gradle b/photonlib-java-examples/examples.gradle new file mode 100644 index 0000000000..5a48c873ef --- /dev/null +++ b/photonlib-java-examples/examples.gradle @@ -0,0 +1,9 @@ +// These should be the only 2 non-project subdirectories in the examples folder +// I could check for (it)/build.gradle to exist, but w/e +def EXCLUDED_DIRS = [".gradle", "bin"] + +// List all non-hidden directories not in EXCUDED_DIRS +ext.exampleFolderNames = file("${rootDir}") + .listFiles() + .findAll { it.isDirectory() && !it.isHidden() && !(it.name in EXCLUDED_DIRS) } + .collect { it.name } diff --git a/photonlib-java-examples/examples.txt b/photonlib-java-examples/examples.txt deleted file mode 100644 index c7627d90a9..0000000000 --- a/photonlib-java-examples/examples.txt +++ /dev/null @@ -1,5 +0,0 @@ -aimandrange -aimattarget -getinrange -simaimandrange -swervedriveposeestsim diff --git a/photonlib-java-examples/settings.gradle b/photonlib-java-examples/settings.gradle index 63bcd788b7..4c125fe51c 100644 --- a/photonlib-java-examples/settings.gradle +++ b/photonlib-java-examples/settings.gradle @@ -1,6 +1,3 @@ -include 'photon-targeting' -include 'photon-core' -include 'photon-server' -include 'photon-lib' +apply from: "examples.gradle" -new File('examples.txt').eachLine { line -> include line } +exampleFolderNames.each { line -> include line }