Skip to content

Commit 6397252

Browse files
committed
[GR-13538] Pkgtest: Allow packages from local repo 'FASTR' to depend on CRAN packages.
PullRequest: fastr/1996
2 parents d5a2ff3 + 4da813b commit 6397252

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

com.oracle.truffle.r.test.packages/pkgtest/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ def prepare_r_install_arguments(args):
147147
# GnuR in an accessible location.
148148
if '--repos' in args:
149149
repos_idx = args.index('--repos')
150-
if repos_idx + 1 < len(args) and args[repos_idx + 1] == 'SNAPSHOT':
151-
logging.info("Overwriting '--repos SNAPSHOT' with '--repos %s'" % default_cran_mirror_url)
152-
args[repos_idx + 1] = default_cran_mirror_url
150+
if repos_idx + 1 < len(args):
151+
if args[repos_idx + 1] == 'SNAPSHOT':
152+
logging.info("Overwriting '--repos SNAPSHOT' with '--repos %s'" % default_cran_mirror_url)
153+
args[repos_idx + 1] = default_cran_mirror_url
154+
elif args[repos_idx + 1] == 'FASTR':
155+
logging.info("Overwriting '--repos FASTR' with '--repos FASTR,%s'" % default_cran_mirror_url)
156+
args[repos_idx + 1] = "FASTR," + default_cran_mirror_url
153157
else:
154158
logging.info("No '--repos' specified, using default CRAN mirror: " + default_cran_mirror_url)
155159
args += [ "--repos", default_cran_mirror_url]

com.oracle.truffle.r.test.packages/r/install.packages.R

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,19 @@ abort <- function(msg) {
305305
quit("no", status=100)
306306
}
307307

308+
get.default.cran.mirror <- function() {
309+
tryCatch({
310+
con <- file("etc/DEFAULT_CRAN_MIRROR", "r");
311+
cran.mirror <<- readLines(con)[[1]]
312+
close(con)
313+
cran.mirror
314+
}, error = function(err) {
315+
cat("ERROR while getting etc/DEFAULT_CRAN_MIRROR, are you running this in FastR home directory and did you build it?")
316+
print(err)
317+
quit("no", status=1)
318+
})
319+
}
320+
308321
set.repos <- function() {
309322
# Based on the value of repos.list we set the "repos" option
310323
# which is used by available.packages etc.
@@ -328,28 +341,24 @@ set.repos <- function() {
328341
# not set on command line
329342
cran.mirror <<- Sys.getenv("CRAN_MIRROR", unset = "http://cloud.r-project.org/")
330343
} else {
331-
cran.mirror <- uri
344+
cran.mirror <<- uri
332345
}
333346
repos[["CRAN"]] <- cran.mirror
334347
} else if (name == "FASTR") {
335348
# set the FastR internal repo
336349
repos[["FASTR"]] <- paste0("file://", normalizePath("com.oracle.truffle.r.test.native/packages/repo"))
337350
} else if (name == "SNAPSHOT") {
338-
tryCatch({
339-
con <- file("etc/DEFAULT_CRAN_MIRROR", "r");
340-
cran.mirror <<- readLines(con)[[1]]
341-
close(con)
342-
}, error = function(err) {
343-
cat("ERROR while getting etc/DEFAULT_CRAN_MIRROR, are you running this in FastR home directory and did you build it?")
344-
print(err)
345-
quit("no", status=1)
346-
})
347-
repos[["CRAN"]] <- cran.mirror
351+
repos[["CRAN"]] <- get.default.cran.mirror()
348352
} else {
349353
# User defined
350354
repos[[name]] <- uri
351355
}
352356
}
357+
358+
if (("FASTR" %in% names(repos)) && !("CRAN" %in% names(repos))) {
359+
log.message("'--repos FASTR' specified but no CRAN mirror set; setting 'CRAN=", get.default.cran.mirror(), "'\n", level=1)
360+
repos[["CRAN"]] <- get.default.cran.mirror()
361+
}
353362
options(repos = repos)
354363
}
355364

@@ -823,7 +832,8 @@ install.pkg <- function(pkgname) {
823832

824833
# save and restore working dir in case the installation process doesn't
825834
prev.wd <- getwd()
826-
rc <- pkg.cache.internal.install(pkg.cache, pkgname, contrib.url(getOption("repos"), "source")[[1]], lib.install)
835+
836+
rc <- pkg.cache.internal.install(pkg.cache, pkgname, contrib.url(getOption("repos"), "source"), lib.install)
827837
setwd(prev.wd)
828838

829839
success <- FALSE

0 commit comments

Comments
 (0)