Skip to content

Commit

Permalink
Remove pkgbuild dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmgarnier committed Aug 1, 2024
1 parent 3a00c2e commit 401e0e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3886-3974")),
Expand All @@ -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:
Expand Down
16 changes: 3 additions & 13 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 27 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 401e0e9

Please sign in to comment.