-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_one.R
153 lines (151 loc) · 5.36 KB
/
check_one.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
cargs <- commandArgs(trailingOnly=TRUE)
if(length(cargs)==0){
## before running interactively, make sure to start emacs/R with
## environment defined in /scratch/...check_one.sh, particularly
## R_LIBS_USER=/tmp/... otherwise we get error when installing
## data.table.
base <- "/scratch/th798/data.table-revdeps/*"
cargs <- c(
Sys.glob(file.path(base,"deps.csv")),
"349",
Sys.glob(file.path(base, "data.table_release_*tar.gz")),
Sys.glob(file.path(base, "data.table_master_*tar.gz"))
)
}
names(cargs) <- c("deps.csv", "task.str", "release", "master")
dput(cargs)
(task.dir <- dirname(.libPaths()[1]))#should be /tmp/th798/slurmid/R-vers
if(requireNamespace("R.cache"))R.cache::getCachePath()
task.id <- as.integer(cargs[["task.str"]])
deps.df <- read.csv(cargs[["deps.csv"]])
(rev.dep <- deps.df$Package[task.id])
job.dir <- file.path(dirname(cargs[["deps.csv"]]), "tasks", task.id)
setwd(task.dir)
.libPaths()
options(repos=c(#this should be in ~/.Rprofile too.
CRAN="http://cloud.r-project.org"))
print(Sys.time())
install.time <- system.time({
install.packages(rev.dep, dep=TRUE)
})
cat("Time to install revdep:\n")
print(install.time)
print(Sys.time())
downloaded_packages <- file.path(
tempdir(),
"downloaded_packages")
dl.glob <- file.path(
downloaded_packages,
paste0(rev.dep,"_*.tar.gz"))
rev.dep.dl.row <- cbind(rev.dep, Sys.glob(dl.glob))
colnames(rev.dep.dl.row) <- c("pkg","path")
rev.dep.release.tar.gz <- normalizePath(rev.dep.dl.row[,"path"], mustWork=TRUE)
pkg.Rcheck <- paste0(rev.dep, ".Rcheck")
proj.dir <- "~/genomic-ml/data.table-revdeps"
source(file.path(proj.dir, "myStatus.R"))
Rvers <- gsub("[()]", "", gsub(" ", "_", R.version[["version.string"]]))
dir.create(Rvers, showWarnings=FALSE)
Rcheck.list <- list()
for(dt.version.short in c("release", "master")){
dt.tar.gz <- cargs[[dt.version.short]]
dt.version <- gsub(".tar.gz|/.*?_", "", dt.tar.gz)
print(Sys.time())
install.packages(dt.tar.gz, repos=NULL)
print(Sys.time())
check.cmd <- get_check_cmd(rev.dep.release.tar.gz)
system(check.cmd)
print(Sys.time())
dest.Rcheck <- file.path(
Rvers,
paste0(dt.version, ".Rcheck"))
unlink(dest.Rcheck, recursive=TRUE)
file.rename(pkg.Rcheck, dest.Rcheck)
Rcheck.list[[dt.version]] <- file.path(dest.Rcheck, "00check.log")
}
system(paste(c("diff -u", Rcheck.list), collapse=" "))
library(data.table, lib.loc=R.home("library"))
(sig.diff.dt <- myDiff(Rvers))
## If there are significant differences, use git bisect to find when
## they started.
if(nrow(sig.diff.dt)){
dt.git <- file.path(task.dir, "data.table.git")
system(paste("cd ~/R/data.table && git fetch --tags"))
system(paste("git clone ~/R/data.table", dt.git))
release.tag <- gsub(".tar.gz|.*_", "", cargs[["release"]])
rev.parse.cmd <- paste(
"cd", dt.git, "&& git rev-parse master")
master.sha <- system(rev.parse.cmd, intern=TRUE)
merge.base.cmd <- paste(
"cd", dt.git, "&& git merge-base master", release.tag)
merge.base.sha <- system(merge.base.cmd, intern=TRUE)
old.sha <- merge.base.sha
run_R <- file.path(proj.dir, "install_dt_then_check_dep.R")
sig.diff.dt[, first.bad.commit := NA_character_]
sig.diff.dt[, comments := NA_character_]
for(diff.i in 1:nrow(sig.diff.dt)){
sig.diff.row <- sig.diff.dt[diff.i]
bisect.cmd <- paste(
"cd", dt.git, "&&",
"git bisect start &&",
"git bisect old", old.sha, "&&",
"git bisect new master &&",
"git bisect run",
R.home('bin/Rscript'),
run_R,
shQuote(sig.diff.row$checking),
sig.diff.row$release,
rev.dep.release.tar.gz,
release.tag)
print(bisect.cmd)
bisect.out <- system(bisect.cmd, intern=TRUE)
cat(bisect.out,sep="\n")
if(is.null(attr(bisect.out,"status"))){
first.bad.sha <- nc::capture_all_str(
bisect.out,
sha="[0-9a-f]+",
" is the first new commit")$sha
parent.cmd <- paste(
"cd ~/R/data.table && git log --pretty=%P -n 1",
first.bad.sha)
parent.sha <- system(parent.cmd, intern=TRUE)
sig.diff.dt[diff.i, first.bad.commit := first.bad.sha]
parent.msg <- paste0("parent=", parent.sha)
this.comment <- if(parent.sha==old.sha){
paste(parent.msg, "same as git bisect old")
}else if(first.bad.sha==master.sha){
paste("same as git bisect new=master,", parent.msg)
}else{
parent.msg
}
sig.diff.dt[diff.i, comments := this.comment]
}
}
## add CRAN column.
sig.diff.dt[, CRAN := {
flavor <- get_flavor(Rvers)
details <- data.table(flavor=unique(flavor))[, {
base <- "https://www.r-project.org/nosvn/R.check/"
u <- paste0(base, flavor, "/", rev.dep, "-00check.txt")
check.txt <- tempfile()
tryCatch({
download.file(u, check.txt, quiet=TRUE)
}, error=function(e){
NULL
})
check.lines <- if(file.exists(check.txt)){
readLines(check.txt,encoding="UTF-8")
}else{
""
}
repl.lines <- gsub("[\u2018\u2019]", "'", check.lines)
##gsub("[‘’]", "'", check.lines) does not work with LC_ALL=C.
myStatus(line.vec=repl.lines)
}, by=flavor]
select.dt <- data.table(flavor, checking)
details[select.dt, msg, on=.(flavor, checking)]
}]
dir.create(file.path(job.dir, Rvers))
diffs.csv <- file.path(job.dir, Rvers, "significant_differences.csv")
data.table::fwrite(sig.diff.dt, diffs.csv)
print(sig.diff.dt)
}