Skip to content

Commit ea76bae

Browse files
author
urbaneks
committed
enable support for binary packages for custom builds
git-svn-id: https://svn.r-project.org/R/trunk@89370 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 5570961 commit ea76bae

File tree

6 files changed

+84
-59
lines changed

6 files changed

+84
-59
lines changed

src/library/tools/R/packages.R

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,33 @@
1717
# https://www.R-project.org/Licenses/
1818

1919
write_PACKAGES <-
20-
function(dir = ".", fields = NULL,
21-
type = c("source", "mac.binary", "win.binary"),
20+
function(dir = ".", fields = NULL, type,
2221
verbose = FALSE, unpacked = FALSE, subdirs = FALSE,
23-
latestOnly = TRUE, addFiles = FALSE, rds_compress = "xz",
22+
latestOnly = TRUE, addFiles = grepl("binary", type), rds_compress = "xz",
2423
validate = FALSE)
2524
{
26-
if(missing(type) && .Platform$OS.type == "windows")
27-
type <- "win.binary"
28-
type <- match.arg(type)
29-
25+
## FIXME: IMHO this should be either .Platform$pkgType or "source"
26+
## I don't like the Windows-only exception, but is it too late to change it?
27+
if(missing(type))
28+
type <- if (.Platform$OS.type == "windows") "win.binary" else "source"
29+
if (type == "binary") {
30+
if (.Platform$pkgType == "source")
31+
stop("There is no binary type for this build of R.")
32+
type <- .Platform$pkgType
33+
}
34+
if (grepl(".binary", type, fixed=TRUE)) {
35+
## strip build name
36+
type <- gsub("^([[:lower:]]+[.]binary)[.].*", "\\1", type)
37+
## at this point we only care about win, mac or other
38+
if (! type %in% c("win.binary", "mac.binary"))
39+
type <- "other.binary"
40+
} else {
41+
## for compatibility with R < 4.6.0 we handle partial matching
42+
## of c("source", "win.binary", "mac.binary") as it was using match.arg
43+
choices <- c("source", "win.binary", "mac.binary")
44+
type <- choices[pmatch(type, choices)]
45+
if (any(is.na(type))) stop("invalid 'type'")
46+
}
3047
paths <- ""
3148
if(is.logical(subdirs) && subdirs) {
3249
owd <- setwd(dir)
@@ -113,7 +130,7 @@ function(desc, path, addFiles, addPaths, latestOnly)
113130

114131
## factored out so it can be used in multiple
115132
## places without threat of divergence
116-
.get_pkg_file_pattern = function(type = c("source", "mac.binary", "win.binary"),
133+
.get_pkg_file_pattern = function(type = c("source", "mac.binary", "win.binary", "other.binary"),
117134
ext.only = FALSE)
118135
{
119136

@@ -124,7 +141,9 @@ function(desc, path, addFiles, addPaths, latestOnly)
124141
ret = switch(type,
125142
"source" = "_.*\\.tar\\.[^_]*$",
126143
"mac.binary" = "_.*\\.tgz$",
127-
"win.binary" = "_.*\\.zip$")
144+
"win.binary" = "_.*\\.zip$",
145+
"other.binary" = "_.*\\.tar\\.[^_]*$" ## we assume any custom binaries are still tar balls
146+
)
128147
if(ext.only)
129148
ret = gsub("_.*", "", fixed = TRUE, ret)
130149
ret
@@ -133,7 +152,7 @@ function(desc, path, addFiles, addPaths, latestOnly)
133152
## what you add.
134153
.build_repository_package_db <-
135154
function(dir, fields = NULL,
136-
type = c("source", "mac.binary", "win.binary"),
155+
type = c("source", "mac.binary", "win.binary", "other.binary"),
137156
verbose = getOption("verbose"),
138157
unpacked = FALSE, validate = FALSE)
139158
{

src/library/tools/R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ function()
14081408
### ** .get_standard_repository_db_fields
14091409

14101410
.get_standard_repository_db_fields <-
1411-
function(type = c("source", "mac.binary", "win.binary")) {
1411+
function(type = c("source", "mac.binary", "win.binary", "other.binary")) {
14121412
type <- match.arg(type)
14131413
c("Package", "Version", "Priority",
14141414
"Depends", "Imports", "LinkingTo", "Suggests", "Enhances",

src/library/tools/man/writePACKAGES.Rd

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
files for a repository of source or Mac/Windows binary packages.
1212
}
1313
\usage{
14-
write_PACKAGES(dir = ".", fields = NULL,
15-
type = c("source", "mac.binary", "win.binary"),
14+
write_PACKAGES(dir = ".", fields = NULL, type,
1615
verbose = FALSE, unpacked = FALSE, subdirs = FALSE,
17-
latestOnly = TRUE, addFiles = FALSE, rds_compress = "xz",
18-
validate = FALSE)
16+
latestOnly = TRUE, addFiles = grepl("binary", type),
17+
rds_compress = "xz", validate = FALSE)
1918
}
2019
\arguments{
2120
\item{dir}{Character vector describing the location of the repository
@@ -40,9 +39,18 @@ write_PACKAGES(dir = ".", fields = NULL,
4039
are used.
4140
}
4241
\item{type}{
43-
Type of packages: currently source \file{.tar.\{gz,bz2,xz,zstd\}} archives,
44-
and macOS or Windows binary (\file{.tgz} or \file{.zip},
45-
respectively) packages are supported. Defaults to
42+
Type of packages. It can be either \code{"source"} or the name of
43+
the binary type (e.g., \code{"win.binary"} or
44+
\code{"mac.binary.big-sur-x86_64"}). In addition, the value
45+
\code{"binary"} corresponds to default binary type for this R build
46+
(see \code{.Platform$pkgType}).
47+
In R versions before 4.6.0 this argument was partially matched to
48+
the choices \code{"source"}, \code{"mac.binary"} and \code{"win.binary"}
49+
which is still honored, but the partial matching is now deprecated
50+
to better support other binary types.
51+
Currently, source and custom binary \file{.tar.\{gz,bz2,xz,zstd\}}
52+
archives, legacy macOS or Windows binary (\file{.tgz} or
53+
\file{.zip}, respectively) packages are supported. Defaults to
4654
\code{"win.binary"} on Windows and to \code{"source"} otherwise.
4755
}
4856
\item{verbose}{logical. Should packages be listed as they are

src/library/utils/R/packages.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,18 @@ download.packages <- function(pkgs, destdir, available = NULL,
819819
keep[duplicated(keep)] <- FALSE
820820
ok[ok][!keep] <- FALSE
821821
}
822-
if (startsWith(type, "mac.binary")) type <- "mac.binary"
823822
## in Oct 2009 we introduced file names in PACKAGES files
824823
File <- available[ok, "File"]
824+
## strip build name for ext detection
825+
type <- gsub("^([[:lower:]]+[.]binary)[.].*", "\\1", type)
826+
## this is just a fall-back if there is no File: so hopefully
827+
## no longer used
825828
fn <- paste0(p, "_", available[ok, "Version"],
826829
switch(type,
827830
"source" = ".tar.gz",
828831
"mac.binary" = ".tgz",
829832
"win.binary" = ".zip",
830-
stop("invalid 'type'")))
833+
".tar.xz")) ## for any other binaries, but they should use File:
831834
have_fn <- !is.na(File)
832835
fn[have_fn] <- File[have_fn]
833836
repos <- available[ok, "Repository"]
@@ -1050,7 +1053,8 @@ setRepositories <-
10501053
stop("invalid options(\"pkgType\"); must be a character string")
10511054
if (pkgType == "both") pkgType <- "source" #.Platform$pkgType
10521055
if (pkgType == "binary") pkgType <- .Platform$pkgType
1053-
if(startsWith(pkgType, "mac.binary")) pkgType <- "mac.binary"
1056+
## strip build names (until we need them and start recording them)
1057+
pkgType <- gsub("^([[:lower:]]+[.]binary)[.].*", "\\1", pkgType)
10541058
thisType <- a[[pkgType]]
10551059
a <- a[thisType, 1L:3L]
10561060
repos <- getOption("repos")

src/library/utils/R/packages2.R

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# A copy of the GNU General Public License is available at
1717
# https://www.R-project.org/Licenses/
1818

19+
## FIXME: at some point we may want to allow custom binary installs on Windows as well
1920
if (.Platform$OS.type == "windows")
2021
.install.macbinary <- function(...) NULL # globalVariables isn't available, so use this to suppress the warning
2122

@@ -194,7 +195,7 @@ install.packages <-
194195
get_package_name <- function(pkg) {
195196
## Since the pkg argument can be the name of a file rather than
196197
## a regular package name, we have to clean that up.
197-
gsub("_[.](zip|tar[.](gz|bzip2|bz2|xz|zstd|xst))", "",
198+
gsub("_[.](zip|tar[.](gz|bzip2|bz2|xz|zstd|zst))", "",
198199
gsub(.standard_regexps()$valid_package_version, "",
199200
basename(pkg)))
200201
}
@@ -350,9 +351,10 @@ install.packages <-
350351

351352
## check if we should infer repos = NULL
352353
if(length(pkgs) == 1L && missing(repos) && missing(contriburl)) {
353-
if((type == "source" && any(grepl("[.]tar[.](gz|bz2|xz)$", pkgs))) ||
354+
if((type == "source" && any(grepl("[.]tar[.](gz|bz2|xz|zstd|zst)$", pkgs))) ||
354355
(type %in% "win.binary" && endsWith(pkgs, ".zip")) ||
355-
(startsWith(type, "mac.binary") && endsWith(pkgs, ".tgz"))) {
356+
(startsWith(type, "mac.binary") && endsWith(pkgs, ".tgz")) ||
357+
(grepl("[.]binary", type) && any(grepl("[.]tar[.](gz|bz2|xz|zstd|zst)$", pkgs)))) {
356358
repos <- NULL
357359
message("inferring 'repos = NULL' from 'pkgs'")
358360
}
@@ -366,8 +368,10 @@ install.packages <-
366368
repos <- NULL
367369
type <- type2
368370
message("inferring 'repos = NULL' from 'pkgs'")
369-
} else if (grepl("[.]tar[.](gz|bz2|xz)$", pkgs)) {
371+
} else if (grepl("[.]tar[.](gz|bz2|xz|zstd|zst)$", pkgs)) {
370372
repos <- NULL
373+
## can be either source or custom binary, but source falls back to
374+
## R CMD INSTALL which can handle both, so choose "source" to be safe
371375
type <- "source"
372376
message("inferring 'repos = NULL' from 'pkgs'")
373377
}
@@ -380,7 +384,7 @@ install.packages <-
380384
||(startsWith(type2, "mac.binary")
381385
&& endsWith(pkgs, ".tgz"))) {
382386
type <- type2
383-
} else if (grepl("[.]tar[.](gz|bz2|xz)$", pkgs)) {
387+
} else if (grepl("[.]tar[.](gz|bz2|xz|zstd|zst)$", pkgs)) {
384388
type <- "source"
385389
}
386390
}
@@ -550,7 +554,7 @@ install.packages <-
550554
}
551555

552556
if(length(bins)) {
553-
if(type2 == "win.binary")
557+
if(startsWith(type2, "win.binary"))
554558
.install.winbinary(pkgs = bins, lib = lib,
555559
contriburl = contrib.url(repos, type2),
556560
method = method, available = av2,
@@ -576,7 +580,7 @@ install.packages <-
576580
flush.console()
577581
## end of "both"
578582
} else if (getOption("install.packages.check.source", "yes") %in% "yes"
579-
&& (type %in% "win.binary" || startsWith(type, "mac.binary"))) {
583+
&& (grepl("^[[:lower::]]+[.]binary", type))) {
580584
if (missing(contriburl) && is.null(available) && !is.null(repos)) {
581585
contriburl2 <- contrib.url(repos, "source")
582586
# The line above may have changed the repos option, so..
@@ -630,10 +634,11 @@ install.packages <-
630634
}
631635

632636
if(.Platform$OS.type == "windows") {
633-
if(startsWith(type, "mac.binary"))
634-
stop("cannot install macOS binary packages on Windows")
637+
## FIXME: we may want allow custom binaries on Windows as well...
638+
if(!startsWith(type, "win.binary") && type != "source")
639+
stop("cannot install binary packages from other operating systems on Windows")
635640

636-
if(type %in% "win.binary") {
641+
if(startsWith(type, "win.binary")) {
637642
## include local .zip files
638643
.install.winbinary(pkgs = pkgs, lib = lib, contriburl = contriburl,
639644
method = method, available = available,
@@ -655,19 +660,17 @@ install.packages <-
655660
## -- will mess up UNC names, but they don't work
656661
pkgs <- gsub("\\", "/", pkgs, fixed=TRUE)
657662
} else {
658-
if(startsWith(type, "mac.binary")) {
659-
if(!grepl("darwin", R.version$platform))
660-
stop("cannot install macOS binary packages on this platform")
663+
if(startsWith(type, "win.binary"))
664+
stop("cannot install Windows binary packages on this platform")
665+
666+
if(grepl("^[[:lower:]]+[.]binary", type)) {
661667
.install.macbinary(pkgs = pkgs, lib = lib, contriburl = contriburl,
662668
method = method, available = available,
663669
destdir = destdir,
664670
dependencies = dependencies, quiet = quiet, ...)
665671
return(invisible())
666672
}
667673

668-
if(type %in% "win.binary")
669-
stop("cannot install Windows binary packages on this platform")
670-
671674
if(!file.exists(file.path(R.home("bin"), "INSTALL")))
672675
stop("This version of R is not set up to install source packages\nIf it was installed from an RPM, you may need the R-devel RPM")
673676
}

src/library/utils/R/unix/mac.install.R

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/utils/R/unix/mac.install.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2017 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -17,27 +17,16 @@
1717
# https://www.R-project.org/Licenses/
1818

1919

20-
if(!startsWith(R.version$os, "darwin")) {
2120
.install.macbinary <-
2221
function(pkgs, lib, repos = getOption("repos"),
23-
contriburl = contrib.url(repos, type="mac.binary"),
24-
method, available = NULL, destdir = NULL,
25-
dependencies = FALSE,
26-
lock = getOption("install.lock", FALSE), quiet = FALSE,
27-
...)
28-
{}
29-
} else {
30-
## edited from windows/.install.winbinary
31-
##
32-
.install.macbinary <-
33-
function(pkgs, lib, repos = getOption("repos"),
34-
contriburl = contrib.url(repos, type="mac.binary"),
22+
contriburl = contrib.url(repos, type=type),
3523
method, available = NULL, destdir = NULL,
3624
dependencies = FALSE,
3725
lock = getOption("install.lock", FALSE), quiet = FALSE,
26+
type = .Platform$pkgType,
3827
...)
3928
{
40-
untar <- function(what, where)
29+
untar0 <- function(what, where)
4130
{
4231
## FIXME: should this look for Sys.getenv('TAR')?
4332
## Leopard has GNU tar, SL has BSD tar.
@@ -48,6 +37,9 @@ if(!startsWith(R.version$os, "darwin")) {
4837
domain = NA, call. = FALSE)
4938
}
5039

40+
## not sure why the above was used - possibly it pre-dates utils::untar()?
41+
untar <- function(what, where) utils::untar(what, exdir=where)
42+
5143
unpackPkg <- function(pkg, pkgname, lib, lock = FALSE)
5244
{
5345
## Create a temporary directory and unpack the zip to it
@@ -64,15 +56,15 @@ if(!startsWith(R.version$os, "darwin")) {
6456
setwd(tmpDir)
6557
## sanity check: people have tried to install source .tgz files
6658
if (!file.exists(file <- file.path(pkgname, "Meta", "package.rds")))
67-
stop(gettextf("file %s is not a macOS binary package", sQuote(pkg)),
59+
stop(gettextf("file %s is not a binary package", sQuote(pkg)),
6860
domain = NA, call. = FALSE)
6961
desc <- readRDS(file)$DESCRIPTION
7062
if (length(desc) < 1L)
71-
stop(gettextf("file %s is not a macOS binary package", sQuote(pkg)),
63+
stop(gettextf("file %s is not a binary package", sQuote(pkg)),
7264
domain = NA, call. = FALSE)
7365
desc <- as.list(desc)
7466
if (is.null(desc$Built))
75-
stop(gettextf("file %s is not a macOS binary package", sQuote(pkg)),
67+
stop(gettextf("file %s is not a binary package", sQuote(pkg)),
7668
domain = NA, call. = FALSE)
7769

7870
res <- tools::checkMD5sums(pkgname, file.path(tmpDir, pkgname))
@@ -137,7 +129,7 @@ if(!startsWith(R.version$os, "darwin")) {
137129
if(is.null(contriburl)) {
138130
pkgnames <- basename(pkgs)
139131
pkgnames <- sub("\\.tgz$", "", pkgnames)
140-
pkgnames <- sub("\\.tar\\.gz$", "", pkgnames)
132+
pkgnames <- sub("\\.tar\\.(gz|bzip2|bz2|xz|zstd|zst)$", "", pkgnames)
141133
pkgnames <- sub("_.*$", "", pkgnames)
142134
## there is no guarantee we have got the package name right:
143135
## foo.zip might contain package bar or Foo or FOO or ....
@@ -160,12 +152,12 @@ if(!startsWith(R.version$os, "darwin")) {
160152

161153
if(is.null(available))
162154
available <- available.packages(contriburl = contriburl,
163-
method = method, ...)
155+
method = method, type = type, ...)
164156
pkgs <- getDependencies(pkgs, dependencies, available, lib, binary = TRUE)
165157

166158
foundpkgs <- download.packages(pkgs, destdir = tmpd, available = available,
167159
contriburl = contriburl, method = method,
168-
type = "mac.binary", quiet = quiet, ...)
160+
type = type, quiet = quiet, ...)
169161

170162
if(length(foundpkgs)) {
171163
update <- unique(cbind(pkgs, lib))
@@ -187,4 +179,3 @@ if(!startsWith(R.version$os, "darwin")) {
187179

188180
invisible()
189181
}
190-
}

0 commit comments

Comments
 (0)