Skip to content

Commit

Permalink
Refactor built functionality into own function.
Browse files Browse the repository at this point in the history
Be better about cleaning up after self
  • Loading branch information
hadley committed Jun 29, 2011
1 parent 92ca57e commit 860b3b1
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 29 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -14,6 +14,7 @@ Suggests:
License: MIT
Collate:
'bash.r'
'build.r'
'check.r'
'common-mistakes.r'
'devel-mode.r'
Expand Down
7 changes: 7 additions & 0 deletions NEWS
Expand Up @@ -3,6 +3,13 @@

* fix bug in ftp upload that was adding extraneous space

* `build` function builds package in specified directory. `install`, `check`
and `release` now all use this function.

* `build`, `install`, `check` and `release` better about cleaning up after
themselves - always try to both work in session temporary directory and
delete any files/directories that they create

devtools 0.2
------------

Expand Down
15 changes: 15 additions & 0 deletions R/build.r
@@ -0,0 +1,15 @@
#' Build package in specified directory.
#'
#' @param pkg package description, can be path or package name. See
#' \code{\link{as.package}} for more information
#' @param path path in which to produce package
#' @return a string giving the location (including file name) of the built
#' package
build <- function(pkg = NULL, path = tempdir()) {
pkg <- as.package(pkg)

R(paste("CMD build ", shQuote(pkg$path), sep = ""), path)

targz <- paste(pkg$package, "_", pkg$version, ".tar.gz", sep = "")
file.path(path, targz)
}
16 changes: 7 additions & 9 deletions R/check.r
Expand Up @@ -15,15 +15,13 @@ check <- function(pkg = NULL, document = TRUE) {

document(pkg)
message("Checking ", pkg$package)

built_path <- build(pkg)
on.exit(unlink(built_path))

in_dir(dirname(pkg$path), {
targz <- paste(pkg$package, "_", pkg$version, ".tar.gz", sep = "")

R(paste("CMD build ", shQuote(basename(pkg$path)), sep = ""))
on.exit(unlink(targz))

R(paste("CMD check ", targz, sep = ""))
unlink(paste(pkg$package, ".Rcheck", sep = ""), recursive = TRUE)
})
R(paste("CMD check ", built_path, sep = ""), tempdir())
check_path <- file.path(tempdir(), paste(pkg$package, ".Rcheck", sep = ""))
unlink(check_path, recursive = TRUE)

invisible(TRUE)
}
2 changes: 1 addition & 1 deletion R/has-devel.r
Expand Up @@ -13,7 +13,7 @@ has_devel <- function() {
cat("void foo(int *bar) { *bar=1; }\n", file = foo_path)
on.exit(unlink(foo_path))

in_dir(tempdir(), R("CMD SHLIB foo.c"))
R("CMD SHLIB foo.c", tempdir())
dylib <- file.path(tempdir(), paste("foo", .Platform$dynlib.ext, sep=''))
on.exit(unlink(dylib), add = TRUE)

Expand Down
12 changes: 4 additions & 8 deletions R/install.r
Expand Up @@ -16,14 +16,10 @@ install <- function(pkg = NULL, reload = TRUE) {
message("Installing ", pkg$package)
install_deps(pkg)

in_dir(dirname(pkg$path), {
targz <- paste(pkg$package, "_", pkg$version, ".tar.gz", sep = "")

R(paste("CMD build ", shQuote(basename(pkg$path)), sep = ""))
on.exit(unlink(targz))

install.packages(targz, repos = NULL, type = "source")
})
built_path <- build(pkg)
on.exit(unlink(built_path))

install.packages(built_path, repos = NULL, type = "source")

if (reload) reload(pkg)
invisible(TRUE)
Expand Down
13 changes: 5 additions & 8 deletions R/release.r
Expand Up @@ -30,15 +30,12 @@ release <- function(pkg = NULL) {
cat("Is DESCRIPTION up-to-date?")
if(menu(c("Yes", "No")) == 2) return(invisible())

targz <- paste(pkg$package, "_", pkg$version, ".tar.gz", sep = "")
in_dir(tempdir(), {
R(paste("CMD build ", shQuote(pkg$path), sep = ""))
})

message("Building and uploading")
built_path <- build(pkg)

require("RCurl", quiet = TRUE)
message("Uploading")
ftpUpload(file.path(tempdir(), targz),
paste("ftp://cran.R-project.org/incoming/", targz, sep = ""))
ftpUpload(file.path(tempdir(), built_path),
paste("ftp://cran.R-project.org/incoming/", built_path, sep = ""))

message("Preparing email")
msg <- paste(
Expand Down
5 changes: 2 additions & 3 deletions R/system.r
Expand Up @@ -6,8 +6,7 @@ system_check <- function(cmd) {
invisible(TRUE)
}

R <- function(options) {
R <- function(options, path = tempdir()) {
r_path <- shQuote(file.path(R.home("bin"), "R"))
system_check(paste(r_path, options))

in_dir(path, system_check(paste(r_path, options)))
}
15 changes: 15 additions & 0 deletions man/build.Rd
@@ -0,0 +1,15 @@
\name{build}
\alias{build}
\title{Build package in specified directory.}
\usage{build(pkg, path=tempdir())}

\description{
Build package in specified directory.
}
\value{a string giving the location (including file name) of the built
package}
\arguments{
\item{pkg}{package description, can be path or package name. See
\code{\link{as.package}} for more information}
\item{path}{path in which to produce package}
}

0 comments on commit 860b3b1

Please sign in to comment.