Skip to content

Commit fa6a996

Browse files
committed
Correctly install overridden packages without cache.
1 parent a8bb8c8 commit fa6a996

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -712,21 +712,36 @@ transitive.dependencies <- function(pkg, lib, pl = as.data.frame(available.packa
712712

713713
pkg.cache.in.overrides <- function(pkgname) pkgname %in% (if(is.fastr()) overrides$fastr else overrides$gnur)
714714

715+
pkg.cache.full.install <- function(install.candidate.names, contriburl, lib.install) {
716+
# separate uncached packages that are listed in 'overrides'
717+
pkgs.in.overrides <- as.character(install.candidate.names[pkg.cache.in.overrides(install.candidate.names)])
718+
pkgs.not.in.overrides <- as.character(install.candidate.names[!pkg.cache.in.overrides(install.candidate.names)])
719+
720+
# override packages need to be installed differently
721+
if (length(pkgs.in.overrides) > 0) {
722+
install.fastr.packages(as.character(pkgs.in.overrides), lib=lib.install, INSTALL_opts="--install-tests")
723+
}
724+
725+
if (length(pkgs.not.in.overrides) > 0) {
726+
install.packages(as.character(pkgs.not.in.overrides), contriburl=contriburl, type="source", lib=lib.install, INSTALL_opts="--install-tests")
727+
}
728+
}
729+
715730
# Fetches the package from the cache or installs it. This is also done for all transitive dependencies.
716731
pkg.cache.internal.install <- function(pkg.cache.env, pkgname, contriburl, lib.install) {
717732
tryCatch({
718-
if (pkg.cache.is.enabled(pkg.cache.env)) {
719-
# determine available packages
720-
pkg.list <- as.data.frame(available.packages(contriburl=contriburl, filters=list(add=TRUE, function(x) x), stringAsFactors=FALSE))
733+
# determine available packages
734+
pkg.list <- as.data.frame(available.packages(contriburl=contriburl, filters=list(add=TRUE, function(x) x), stringAsFactors=FALSE))
721735

722-
# query version of the package
723-
pkg <- pkg.list[pkgname, c("Package", "Version")]
736+
# query version of the package
737+
pkg <- pkg.list[pkgname, c("Package", "Version")]
724738

725-
# compute transitive dependencies of the package to install
726-
log.message("Computing transitive package dependencies for ", paste0(pkgname, "_", as.character(pkg$Version)), level=1)
727-
transitive.pkg.list <- rbind(transitive.dependencies(pkgname, lib=lib.install, pl=pkg.list), pkg)
728-
log.message("transitive deps: ", as.character(transitive.pkg.list$Package), level=1)
739+
# compute transitive dependencies of the package to install
740+
log.message("Computing transitive package dependencies for ", paste0(pkgname, "_", as.character(pkg$Version)), level=1)
741+
transitive.pkg.list <- rbind(transitive.dependencies(pkgname, lib=lib.install, pl=pkg.list), pkg)
742+
log.message("transitive deps: ", as.character(transitive.pkg.list$Package), level=1)
729743

744+
if (pkg.cache.is.enabled(pkg.cache.env)) {
730745
# apply pkg cache to fetch cached packages first
731746
cached.pkgs <- apply(transitive.pkg.list, 1, function(pkg) pkg.cache.get(pkg.cache.env, pkg, lib.install))
732747
log.message("Number of uncached packages:", nrow(transitive.pkg.list[!cached.pkgs, ]), level=1)
@@ -736,29 +751,17 @@ pkg.cache.internal.install <- function(pkg.cache.env, pkgname, contriburl, lib.i
736751
# install the package (and the transitive dependencies implicitly)
737752
uncached.pkg.names <- transitive.pkg.list[!cached.pkgs, "Package"]
738753

739-
# separate uncached packages that are listed in 'overrides'
740-
pkgs.in.overrides <- as.character(uncached.pkg.names[pkg.cache.in.overrides(uncached.pkg.names)])
741-
pkgs.not.in.overrides <- as.character(uncached.pkg.names[!pkg.cache.in.overrides(uncached.pkg.names)])
742-
743-
# override packages need to be installed differently
744-
if (length(pkgs.in.overrides) > 0) {
745-
install.fastr.packages(as.character(pkgs.in.overrides), lib=lib.install, INSTALL_opts="--install-tests")
746-
}
747-
748-
if (length(pkgs.not.in.overrides) > 0) {
749-
install.packages(as.character(pkgs.not.in.overrides), contriburl=contriburl, type="source", lib=lib.install, INSTALL_opts="--install-tests")
750-
}
754+
# install uncached packages
755+
pkg.cache.full.install(uncached.pkg.names, contriburl, lib.install)
751756

752757
# cache packages that were not in the cache before
753758
log.message("Caching uncached dependencies:", as.character(transitive.pkg.list[!cached.pkgs, "Package"]), level=1)
754759
apply(transitive.pkg.list[!cached.pkgs, ], 1, function(pkg) pkg.cache.insert(pkg.cache.env, pkg, lib.install))
755760
}
756761
} else {
757-
if (pkg.cache.in.overrides(pkgname)) {
758-
install.fastr.packages(pkgname, lib=lib.install, INSTALL_opts="--install-tests")
759-
} else {
760-
install.packages(pkgname, contriburl=contriburl, type="source", lib=lib.install, INSTALL_opts="--install-tests")
761-
}
762+
# Even if we do not use the package cache, we need to compute the dependencies transitively
763+
# because the deps may contain overridden packages.
764+
pkg.cache.full.install(transitive.pkg.list[, "Package"], contriburl, lib.install)
762765
}
763766

764767
# if we reach here, installation was a success

0 commit comments

Comments
 (0)