From 401e0e9e17c96b1f576926a1b6e744790a880a43 Mon Sep 17 00:00:00 2001 From: Simon Garnier Date: Thu, 1 Aug 2024 03:32:52 -0400 Subject: [PATCH] Remove pkgbuild dependency. --- DESCRIPTION | 7 +++---- R/install.R | 16 +++------------- R/utils.R | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c859542..3735837 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ROpenCVLite Type: Package Title: Helper Package for Installing OpenCV with R -Version: 4.90.1 -Date: 2024-01-20 +Version: 4.90.2 +Date: 2024-08-01 Authors@R: c( person("Simon", "Garnier", email = "garnier@njit.edu", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3886-3974")), @@ -18,11 +18,10 @@ License: GPL-3 LazyData: TRUE Imports: utils, - pkgbuild, parallel SystemRequirements: cmake -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.2 Biarch: false Encoding: UTF-8 Depends: diff --git a/R/install.R b/R/install.R index a50f36e..44aac13 100644 --- a/R/install.R +++ b/R/install.R @@ -34,19 +34,9 @@ defaultOpenCVPath <- function() { config$os <- gsub("\r", "", gsub("Caption=", "", system('wmic os get Caption,CSDVersion /value', intern = TRUE)[3])) config$core <- paste0("https://github.com/opencv/opencv/archive/", version, ".tar.gz") config$contrib <- paste0("https://github.com/opencv/opencv_contrib/archive/", version, ".tar.gz") - config$rtools_path <- utils::shortPathName(pkgbuild::rtools_path()[1]) - - if (is.null(config$rtools_path)) - stop("Rtools is missing.") - - config$rtools_path <- gsub("\\\\usr\\\\bin", "", config$rtools_path) - config$rtools_version <- system( - paste0("powershell (Get-Item ", config$rtools_path, "/unins000.exe).VersionInfo.ProductVersion"), - intern = TRUE) - config$rtools_version <- gsub(" ", "", config$rtools_version) - - if (is.na(config$rtools_version)) - stop("Unsupported Rtools version.") + rtools <- .findRtools() + config$rtools_path <- rtools$path + config$rtools_version <- rtools$version if (config$rtools_version < "4.2") { config$cmake_path <- utils::shortPathName(system("where cmake.exe", intern = TRUE)) diff --git a/R/utils.R b/R/utils.R index 299045d..579127b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -218,3 +218,30 @@ opencvConfig <- function(output = "libs", arch = NULL) { stop("output should be either 'libs' or 'cflags'") } } + + +.findRtools <- function() { + if (version$major < 4) { + stop("ROpenCVLite requires a R version > 4.0.") + } + + if (version$minor < 2) { + rtools <- "rtools40" + } else { + rtools <- paste0("rtools", sub("\\D*(\\d+).*", "\\1", paste0(version$major, version$minor))) + } + + path <- strsplit(Sys.getenv("PATH"), ";")[[1]] + ix <- grep(rtools, path)[1] + rtools_path <- utils::shortPathName(sub(paste0("(", rtools, ").*"), "\\1", path[ix])) + rtools_version <- system( + paste0("powershell (Get-Item ", rtools_path, "/unins000.exe).VersionInfo.ProductVersion"), + intern = TRUE + ) + rtools_version <- gsub(" ", "", rtools_version) + + if (is.na(rtools_version)) + stop("Rtools unavailable or unsupported Rtools version.") + + list(path = unname(rtools_path), version = unname(rtools_version)) +}