diff --git a/BUILD.bazel b/BUILD.bazel index 17bd36acf98..be5ed712f1d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -173,7 +173,6 @@ publish_all( "//thirdparty/imgui_suite:imguiSuite-cpp_publish.publish", "//tools/datalogtool:datalogtool_publish.publish", "//tools/outlineviewer:outlineviewer_publish.publish", - "//tools/processstarter:processstarter_publish.publish", "//tools/sysid:sysid_publish.publish", "//tunables:tunables-cpp_publish.publish", "//tunables:tunables-java_publish.publish", diff --git a/settings.gradle b/settings.gradle index 3eeba0246e9..952ac0494c3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -57,7 +57,6 @@ include 'docs' include 'msvcruntime' include 'ntcoreffi' include 'apriltag' -include 'tools:processstarter' include 'epilogue-processor' include 'epilogue-runtime' include 'thirdparty:catch2' diff --git a/tools/processstarter/BUILD.bazel b/tools/processstarter/BUILD.bazel deleted file mode 100644 index 7207303a43b..00000000000 --- a/tools/processstarter/BUILD.bazel +++ /dev/null @@ -1,51 +0,0 @@ -load("@rules_cc//cc:cc_binary.bzl", "cc_binary") -load("//shared/bazel/rules:objectivec_rules.bzl", "wpilib_objc_library") -load("//shared/bazel/rules:packaging.bzl", "package_binary_cc_project") - -WIN_SRCS = glob([ - "src/main/native/windows/**", -]) - -LINUX_SRCS = glob([ - "src/main/native/linux/**", -]) - -MAC_SRCS = glob([ - "src/main/native/osx/**", -]) - -filegroup( - name = "native-srcs", - srcs = select({ - "@platforms//os:osx": MAC_SRCS, - "@platforms//os:windows": WIN_SRCS, - "@wpilib_toolchains//constraints/combined:is_linux": LINUX_SRCS, - }), -) - -wpilib_objc_library( - name = "processstarter-osx", - srcs = [":native-srcs"], -) - -cc_binary( - name = "processstarter", - srcs = select({ - "@platforms//os:osx": [], - "//conditions:default": [":native-srcs"], - }), - linkopts = select({ - "@platforms//os:windows": ["-SUBSYSTEM:WINDOWS"], - "//conditions:default": [], - }), - deps = select({ - "@platforms//os:osx": ["processstarter-osx"], - "//conditions:default": [], - }), -) - -package_binary_cc_project( - name = "processstarter", - maven_artifact_name = "processstarter", - maven_group_id = "org.wpilib.tools", -) diff --git a/tools/processstarter/build.gradle b/tools/processstarter/build.gradle deleted file mode 100644 index 5b033eb215f..00000000000 --- a/tools/processstarter/build.gradle +++ /dev/null @@ -1,85 +0,0 @@ -import org.gradle.internal.os.OperatingSystem - -if (project.hasProperty('onlylinuxsystemcore')) { - return; -} - -description = "Process Starter" - -apply plugin: 'cpp' -apply plugin: 'objective-cpp' -apply plugin: 'visual-studio' -apply plugin: 'org.wpilib.NativeUtils' - -ext { - nativeName = 'processstarter' -} - -apply from: "${rootDir}/shared/config.gradle" - -// Replace shared crt with static crt. -// Note this means no wpilib binaries can be dependencies -nativeUtils.platformConfigs.named(nativeUtils.wpi.platforms.windowsx64).configure { - cppCompiler.debugArgs.remove('/MDd') - cppCompiler.debugArgs.add('/MTd') - cppCompiler.releaseArgs.remove('/MD') - cppCompiler.releaseArgs.add('/MT') -} - -project(':').libraryBuild.dependsOn build - -model { - components { - "${nativeName}"(NativeExecutableSpec) { - baseName = 'processstarter' - binaries.all { - if (it.targetPlatform.name == nativeUtils.wpi.platforms.systemcore) { - it.buildable = false - return - } - if (it.targetPlatform.operatingSystem.isMacOsX()) { - it.sources { - macObjCpp(ObjectiveCppSourceSet) { - source { - srcDirs 'src/main/native/osx' - include '**/*.mm' - } - exportedHeaders { - srcDirs 'src/main/native/include' - include '**/*.h' - } - } - } - } else if (it.targetPlatform.operatingSystem.isLinux()) { - it.sources { - linuxCpp(CppSourceSet) { - source { - srcDirs 'src/main/native/linux' - include '**/*.cpp' - } - exportedHeaders { - srcDirs 'src/main/native/include' - include '**/*.h' - } - } - } - } else if (it.targetPlatform.operatingSystem.isWindows()) { - it.sources { - windowsCpp(CppSourceSet) { - source { - srcDirs 'src/main/native/windows' - include '**/*.cpp' - } - exportedHeaders { - srcDirs 'src/main/native/include' - include '**/*.h' - } - } - } - } - } - } - } -} - -apply from: 'publish.gradle' diff --git a/tools/processstarter/publish.gradle b/tools/processstarter/publish.gradle deleted file mode 100644 index 7f57db4224e..00000000000 --- a/tools/processstarter/publish.gradle +++ /dev/null @@ -1,71 +0,0 @@ -apply plugin: 'maven-publish' - -def baseArtifactId = 'processstarter' -def artifactGroupId = 'org.wpilib.tools' -def zipBaseName = makeZipBaseName(artifactGroupId, baseArtifactId) - -def outputsFolder = file("$project.buildDir/outputs") - -model { - tasks { - // Create the run task. - $.components.processstarter.binaries.each { bin -> - if (bin.buildable && bin.name.toLowerCase().contains("debug") && nativeUtils.isNativeDesktopPlatform(bin.targetPlatform)) { - project.tasks.register("run", Exec) { - commandLine bin.tasks.install.runScriptFile.get().asFile.toString() - dependsOn bin.tasks.install - } - } - } - } - publishing { - def processstarterTaskList = [] - $.components.each { component -> - component.binaries.each { binary -> - if (binary in NativeExecutableBinarySpec && binary.component.name.contains("processstarter")) { - if (binary.buildable && (binary.name.contains('Release') || binary.name.contains('release'))) { - // We are now in the binary that we want. - // This is the default application path for the ZIP task. - def applicationPath = binary.executable.file - - // Create the ZIP. - def task = project.tasks.create("copyprocessstarterExecutable" + binary.targetPlatform.architecture.name, Zip) { - description = "Copies the processstarter executable to the outputs directory." - destinationDirectory = outputsFolder - - archiveBaseName = zipBaseName - duplicatesStrategy = 'exclude' - archiveClassifier = nativeUtils.getPublishClassifier(binary) - - // Use permissions from the file system - useFileSystemPermissions() - - from(licenseFile) { - into '/' - } - - from(applicationPath) - into(nativeUtils.getPlatformPath(binary)) - } - - task.dependsOn binary.tasks.link - processstarterTaskList.add(task) - project.build.dependsOn task - project.artifacts { task } - addTaskToCopyAllOutputs(task) - } - } - } - } - - publications { - processstarter(MavenPublication) { - processstarterTaskList.each { artifact it } - - artifactId = baseArtifactId - groupId = artifactGroupId - version = wpilibVersioning.version.get() - } - } - } -} diff --git a/tools/processstarter/src/main/native/linux/main.cpp b/tools/processstarter/src/main/native/linux/main.cpp deleted file mode 100644 index 2207c4add7c..00000000000 --- a/tools/processstarter/src/main/native/linux/main.cpp +++ /dev/null @@ -1,124 +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 "main.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -int main(int argc, char* argv[]) { - char path[PATH_MAX]; - char dest[PATH_MAX]; - std::memset(dest, 0, sizeof(dest)); // readlink does not null terminate! - pid_t pid = getpid(); - std::snprintf(path, PATH_MAX, "/proc/%d/exe", pid); - int readlink_len = readlink(path, dest, PATH_MAX); - if (readlink_len < 0) { - std::perror("readlink"); - return 1; - } else if (readlink_len == PATH_MAX) { - std::printf("Truncation occurred\n"); - return 1; - } - - std::filesystem::path exePath{dest}; - if (exePath.empty()) { - return 1; - } - - if (!exePath.has_stem()) { - return 1; - } - - if (!exePath.has_parent_path()) { - return 1; - } - - if (exePath.stem() == (L"AdvantageScope")) { - std::filesystem::path AdvantageScopePath{ - exePath.parent_path().parent_path() / L"advantagescope" / - L"advantagescope-wpilib"}; - return StartExeTool(AdvantageScopePath); - } else if (exePath.stem() == (L"Elastic")) { - std::filesystem::path ElasticPath{exePath.parent_path().parent_path() / - L"elastic" / L"elastic_dashboard"}; - return StartExeTool(ElasticPath); - } else { - return StartJavaTool(exePath); - } -} - -int StartJavaTool(std::filesystem::path& exePath) { - pid_t pid = 0; - std::filesystem::path jarPath{exePath}; - jarPath.replace_extension("jar"); - std::filesystem::path parentPath{exePath.parent_path()}; - - if (!parentPath.has_parent_path()) { - return 1; - } - std::filesystem::path toolsFolder{parentPath.parent_path()}; - - std::filesystem::path Java = toolsFolder / "jdk" / "bin" / "java"; - - std::string data = jarPath; - std::string jarArg = "-jar"; - auto javaGenericStr = Java.generic_string(); - char* const arguments[] = {javaGenericStr.data(), jarArg.data(), data.data(), - nullptr}; - - int status = - posix_spawn(&pid, Java.c_str(), nullptr, nullptr, arguments, environ); - if (status != 0) { - char* home = std::getenv("JAVA_HOME"); - std::string javaLocal = "java"; - if (home != nullptr) { - std::filesystem::path javaHomePath{home}; - javaHomePath /= "bin"; - javaHomePath /= "java"; - javaLocal = javaHomePath; - } - - status = posix_spawn(&pid, javaLocal.c_str(), nullptr, nullptr, arguments, - environ); - if (status != 0) { - return 1; - } - } - - int childPid = syscall(SYS_pidfd_open, pid, 0); - if (childPid <= 0) { - return 1; - } - - struct pollfd pfd = {childPid, POLLIN, 0}; - return poll(&pfd, 1, 3000); -} - -int StartExeTool(std::filesystem::path& exePath) { - char* const arguments[] = {nullptr}; - pid_t pid = 0; - - int status = - posix_spawn(&pid, exePath.c_str(), nullptr, nullptr, arguments, environ); - - if (status != 0) { - return 1; - } - int childPid = syscall(SYS_pidfd_open, pid, 0); - if (childPid <= 0) { - return 1; - } - - struct pollfd pfd = {childPid, POLLIN, 0}; - return poll(&pfd, 1, 5000); -} diff --git a/tools/processstarter/src/main/native/linux/main.hpp b/tools/processstarter/src/main/native/linux/main.hpp deleted file mode 100644 index 227d666b7f7..00000000000 --- a/tools/processstarter/src/main/native/linux/main.hpp +++ /dev/null @@ -1,11 +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. - -#pragma once - -#include - -int StartExeTool(std::filesystem::path& exePath); -int StartJavaTool(std::filesystem::path& exePath); -int main(int argc, char* argv[]); diff --git a/tools/processstarter/src/main/native/osx/main.hpp b/tools/processstarter/src/main/native/osx/main.hpp deleted file mode 100644 index 227d666b7f7..00000000000 --- a/tools/processstarter/src/main/native/osx/main.hpp +++ /dev/null @@ -1,11 +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. - -#pragma once - -#include - -int StartExeTool(std::filesystem::path& exePath); -int StartJavaTool(std::filesystem::path& exePath); -int main(int argc, char* argv[]); diff --git a/tools/processstarter/src/main/native/osx/main.mm b/tools/processstarter/src/main/native/osx/main.mm deleted file mode 100644 index 63db75a308b..00000000000 --- a/tools/processstarter/src/main/native/osx/main.mm +++ /dev/null @@ -1,119 +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 -#include "main.hpp" - -#include -#include - -int main(int argc, char* argv[]) { - (void)argc; - (void)argv; - NSString* exePathPlat = [[NSBundle mainBundle] bundlePath]; - NSString* identifier = [[NSBundle mainBundle] bundleIdentifier]; - if (identifier == nil) { - exePathPlat = [[NSBundle mainBundle] executablePath]; - } - - std::filesystem::path exePath{[exePathPlat UTF8String]}; - if (exePath.empty()) { - return 1; - } - - if (!exePath.has_stem()) { - return 1; - } - - if (!exePath.has_parent_path()) { - return 1; - } - - if (exePath.stem() == (L"AdvantageScope")) { - std::filesystem::path AdvantageScopePath{ - exePath.parent_path().parent_path() / L"advantagescope" / - L"Advantagescope (WPILib).app" / L"Contents" / L"MacOS" / - L"advantagescope"}; - return StartExeTool(AdvantageScopePath); - } else if (exePath.stem() == (L"Elastic")) { - std::filesystem::path ElasticPath{exePath.parent_path().parent_path() / - L"elastic" / L"elastic_dashboard.app" / - L"Contents" / L"MacOS" / - L"elastic_dashboard"}; - return StartExeTool(ElasticPath); - } else { - return StartJavaTool(exePath); - } -} - -int StartJavaTool(std::filesystem::path& exePath) { - std::filesystem::path jarPath{exePath}; - jarPath.replace_extension("jar"); - std::filesystem::path parentPath{exePath.parent_path()}; - - if (!parentPath.has_parent_path()) { - return 1; - } - std::filesystem::path toolsFolder{parentPath.parent_path()}; - - std::filesystem::path java = toolsFolder / "jdk" / "bin" / "java"; - - NSArray* Arguments = - @[ @"-jar", [NSString stringWithFormat:@"%s", jarPath.c_str()] ]; - - NSTask* task = [[NSTask alloc] init]; - task.launchPath = [NSString stringWithFormat:@"%s", java.c_str()]; - task.arguments = Arguments; - task.terminationHandler = ^(NSTask* t) { - (void)t; - CFRunLoopStop(CFRunLoopGetMain()); - }; - - if (![task launchAndReturnError:nil]) { - task.terminationHandler = nil; - - NSString* javaHome = - [[[NSProcessInfo processInfo] environment] objectForKey:@"JAVA_HOME"]; - task = [[NSTask alloc] init]; - task.launchPath = @"java"; - if (javaHome != nil) { - std::filesystem::path javaHomePath{[javaHome UTF8String]}; - javaHomePath /= "bin"; - javaHomePath /= "java"; - task.launchPath = [NSString stringWithFormat:@"%s", javaHomePath.c_str()]; - } - task.arguments = Arguments; - task.terminationHandler = ^(NSTask* t) { - (void)t; - CFRunLoopStop(CFRunLoopGetMain()); - }; - - if (![task launchAndReturnError:nil]) { - return 1; - } - } - - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 3, false); - - return task.running ? 0 : 1; -} - -int StartExeTool(std::filesystem::path& exePath) { - std::cout << "exePath: " << exePath.c_str() << std::endl; - NSTask* task = [[NSTask alloc] init]; - task.launchPath = [NSString stringWithFormat:@"%s", exePath.c_str()]; - // task.arguments = Arguments; - task.terminationHandler = ^(NSTask* t) { - (void)t; - CFRunLoopStop(CFRunLoopGetMain()); - }; - - if (![task launchAndReturnError:nil]) { - return 1; - } - - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 3, false); - - return task.running ? 0 : 1; -} diff --git a/tools/processstarter/src/main/native/windows/main.cpp b/tools/processstarter/src/main/native/windows/main.cpp deleted file mode 100644 index d01db81ce6b..00000000000 --- a/tools/processstarter/src/main/native/windows/main.cpp +++ /dev/null @@ -1,123 +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 "main.hpp" - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPTSTR pCmdLine, int nCmdShow) { - DWORD Status; - WCHAR ExePathRaw[1024]; - Status = GetModuleFileNameW(NULL, ExePathRaw, 1024); - if (Status == 0) { - DWORD LastError = GetLastError(); - return LastError; - } - - std::filesystem::path ExePath{ExePathRaw}; - if (ExePath.empty()) { - return 1; - } - - if (!ExePath.has_stem()) { - return 1; - } - - if (!ExePath.has_parent_path()) { - return 1; - } - - if (ExePath.stem() == (L"AdvantageScope")) { - std::filesystem::path AdvantageScopePath{ - ExePath.parent_path().parent_path() / L"advantagescope" / - L"AdvantageScope (WPILib).exe"}; - return StartExeTool(AdvantageScopePath); - } else if (ExePath.stem() == (L"Elastic")) { - std::filesystem::path ElasticPath{ExePath.parent_path().parent_path() / - L"elastic" / L"elastic_dashboard.exe"}; - return StartExeTool(ElasticPath); - } else { - return StartJavaTool(ExePath); - } -} - -int StartJavaTool(std::filesystem::path& ExePath) { - WCHAR ExePathRaw[1024]; - DWORD Status; - - std::filesystem::path JarPath{ExePath}; - JarPath.replace_extension(L"jar"); - std::filesystem::path ParentPath{ExePath.parent_path()}; - - if (!ParentPath.has_parent_path()) { - return 1; - } - std::filesystem::path ToolsFolder{ParentPath.parent_path()}; - - std::filesystem::path Javaw = ToolsFolder / L"jdk" / L"bin" / L"javaw.exe"; - - std::wstring ToRun = L" -jar \""; - ToRun += JarPath; - ToRun += L"\""; - - STARTUPINFOW StartupInfo; - PROCESS_INFORMATION ProcessInfo; - - ZeroMemory(&StartupInfo, sizeof(StartupInfo)); - StartupInfo.cb = sizeof(StartupInfo); - ZeroMemory(&ProcessInfo, sizeof(ProcessInfo)); - - if (!CreateProcessW(Javaw.c_str(), ToRun.data(), NULL, NULL, FALSE, 0, NULL, - NULL, &StartupInfo, &ProcessInfo)) { - ZeroMemory(&StartupInfo, sizeof(StartupInfo)); - StartupInfo.cb = sizeof(StartupInfo); - ZeroMemory(&ProcessInfo, sizeof(ProcessInfo)); - - ToRun = L" -jar \""; - ToRun += JarPath; - ToRun += L"\""; - - Status = GetEnvironmentVariableW(L"JAVA_HOME", ExePathRaw, 1024); - std::wstring JavawLocal = L"javaw"; - if (Status != 0 && Status < 1024) { - std::filesystem::path JavaHomePath{ExePathRaw}; - JavaHomePath /= "bin"; - JavaHomePath /= "javaw.exe"; - JavawLocal = JavaHomePath; - } - - if (!CreateProcessW(JavawLocal.c_str(), ToRun.data(), NULL, NULL, FALSE, 0, - NULL, NULL, &StartupInfo, &ProcessInfo)) { - return 1; - } - } - - Status = - WaitForSingleObject(ProcessInfo.hProcess, 3000); // Wait for 3 seconds - CloseHandle(ProcessInfo.hProcess); - CloseHandle(ProcessInfo.hThread); - - return Status == WAIT_TIMEOUT ? 0 : 1; -} - -int StartExeTool(std::filesystem::path& ExePath) { - STARTUPINFOW StartupInfo; - PROCESS_INFORMATION ProcessInfo; - DWORD Status; - - ZeroMemory(&StartupInfo, sizeof(StartupInfo)); - StartupInfo.cb = sizeof(StartupInfo); - ZeroMemory(&ProcessInfo, sizeof(ProcessInfo)); - - if (!CreateProcessW(ExePath.c_str(), NULL, NULL, NULL, FALSE, 0, NULL, NULL, - &StartupInfo, &ProcessInfo)) { - return 1; - } - - Status = - WaitForSingleObject(ProcessInfo.hProcess, 5000); // Wait for 5 seconds - CloseHandle(ProcessInfo.hProcess); - CloseHandle(ProcessInfo.hThread); - - return Status == WAIT_TIMEOUT ? 0 : 1; -} diff --git a/tools/processstarter/src/main/native/windows/main.hpp b/tools/processstarter/src/main/native/windows/main.hpp deleted file mode 100644 index 99877d2de2e..00000000000 --- a/tools/processstarter/src/main/native/windows/main.hpp +++ /dev/null @@ -1,15 +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. - -#pragma once - -#include - -#include -#include - -int StartExeTool(std::filesystem::path& ExePath); -int StartJavaTool(std::filesystem::path& ExePath); -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPTSTR pCmdLine, int nCmdShow);