Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions R/build_record.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,8 @@ assess_build <- function(expected, current) {
#' `"unavailable"`, and `reason`, which is `NULL` when the record is available
#' and otherwise one of `"missing"` (no record beside the executable),
#' `"unreadable"` (a record that could not be read), `"executable_mismatch"`
#' (the record describes a different executable, so the one at this path was
#' replaced after the record was written) or `"unsupported_format"` (written by
#' (the record describes a different executable, so the one at this path has
#' changed since the record was written) or `"unsupported_format"` (written by
#' a CmdStanR that stores records differently, in which case the result also
#' has a `format_version` field).
#'
Expand All @@ -681,9 +681,12 @@ assess_build <- function(expected, current) {
#' * `stanc_options`: the flags as given to stanc, in order.
#' For example, `list(O1 = TRUE)` and `list("O1")` both come back as
#' `list("--O1")`.
#' * `stanc_options_from_make`: the flags `make/local` added to the stanc
#' call through `STANCFLAGS`. A flag that `stanc_options` also sets is not
#' repeated here since `stanc_options` takes precedence.
#' * `include_paths`: a character vector of the directories searched for
#' included files. When none were given, this is the Stan program's own
#' directory if the program has includes and empty otherwise.
#' included files. When none were provided but the Stan program has includes
#' this is set to the program's own directory.
#'
#' * `dependencies`: A list describing the files the build read. Contains sublists
#' `stan_file`, `included_files`, `user_header` and `make_local`. `user_header`
Expand All @@ -710,10 +713,8 @@ assess_build <- function(expected, current) {
#' was found in.
#'
#' The result leaves out some of what the record holds: the file hashes the
#' rebuild check compares, the stanc flags CmdStanR added or `make/local`
#' contributed, the model name given to stanc, and the TBB directory.
#' `dependencies$make_local` names the file those flags came from, though its
#' contents may have changed since the build.
#' rebuild check compares, the stanc flags CmdStanR added itself, the model
#' name given to stanc, and the TBB directory.
#'
#' Absent items and empty items have different interpretations. A field missing
#' from the result means there was no usable record to read it from. An empty
Expand Down Expand Up @@ -746,6 +747,7 @@ stan_build_info <- function(exe_file) {
info$configuration <- list(
cpp_options = record$configuration$cpp_options,
stanc_options = record$configuration$stanc_options,
stanc_options_from_make = record$configuration$stanc_options_from_make,
include_paths = as.character(unlist(record$configuration$include_paths))
)
info$dependencies <- public_dependencies(record$dependencies)
Expand Down Expand Up @@ -847,8 +849,12 @@ print.stan_build_info <- function(x, ...) {
stanc_options <- unlist(x$configuration$stanc_options)
cat(" stanc_options: ", if (length(stanc_options) == 0) "none" else
paste(stanc_options, collapse = " "), "\n", sep = "")
cat(" include_paths: ", paste(x$configuration$include_paths, collapse = ", "),
"\n", sep = "")
from_make <- unlist(x$configuration$stanc_options_from_make)
cat(" stanc_options_from_make: ", if (length(from_make) == 0) "none" else
paste(from_make, collapse = " "), "\n", sep = "")
include_paths <- x$configuration$include_paths
cat(" include_paths: ", if (length(include_paths) == 0) "none" else
paste(include_paths, collapse = ", "), "\n", sep = "")

cat("Dependencies:\n")
path_line <- function(label, entry) {
Expand Down Expand Up @@ -890,24 +896,24 @@ build_record_status_line <- function(x) {
}
switch(x$record$reason,
missing = paste0(
"Build record: none. There is no build record beside this executable, ",
"so only what it reports about itself is known."
"Build record: not found. Only what the executable says about itself ",
"is known."
),
unreadable = "Build record: could not be read.",
executable_mismatch = paste0(
"Build record: does not match this executable, which was replaced ",
"after the record was written."
unreadable = paste0(
"Build record: could not be read. Rebuilding the executable writes a ",
"new one."
),
executable_mismatch =
"Build record: does not match. Executable changed after the build.",
unsupported_format = if (x$format_version > build_record_format_version) {
paste0(
"Build record: written in format ", x$format_version, " by a newer ",
"version of CmdStanR. Upgrade CmdStanR to read it."
"Build record: format ", x$format_version, " (newer CmdStanR). ",
"Upgrade CmdStanR to read it."
)
} else {
paste0(
"Build record: written in format ", x$format_version, " by an older ",
"version of CmdStanR. To get a record this version reads, rebuild ",
"the executable."
"Build record: format ", x$format_version, " (older CmdStanR). ",
"Rebuild the executable to replace it."
)
}
)
Expand Down
1 change: 1 addition & 0 deletions dev-notes/compilation-state-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ list(
configuration = list(
cpp_options = list(STAN_THREADS = "true"),
stanc_options = list(),
stanc_options_from_make = list("--O1"),
include_paths = "/proj"
),
dependencies = list(
Expand Down
10 changes: 6 additions & 4 deletions dev-notes/compilation-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -2994,11 +2994,12 @@ shipped yet, so the set can still be chosen freely; after 1.0 it cannot. The has
fail that test. The artifact hash answers a question the caller can already answer
by hashing the file whose path they just passed in, and the dependency hashes
compare against nothing but another record's same field. So do
`stanc_options_added`, `stanc_options_from_make` and `stanc_name`, which say how
cmdstanr assembled the stanc command line rather than what was asked of it. `tbb_dir` is out on the same
`stanc_options_added` and `stanc_name`, which say how cmdstanr assembled the stanc
command line rather than what was asked of it. `tbb_dir` is out on the same
test; the record keeps it because Windows needs it at launch (§4). `configuration` keeps
`include_paths` for diagnosis alone: a caller debugging an include has no other way
to see where the build searched.
`include_paths` and `stanc_options_from_make` for diagnosis alone: a caller debugging
an include has no other way to see where the build searched, and `make/local` can
change after a build, so the file alone does not say which flags the build saw.

<!-- contract -->

Expand All @@ -3017,6 +3018,7 @@ list(
configuration = list(
cpp_options = list(STAN_THREADS = "true"),
stanc_options = list(),
stanc_options_from_make = list("--O1"),
include_paths = "/proj"
),
dependencies = list(
Expand Down
17 changes: 9 additions & 8 deletions man/stan_build_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions tests/testthat/_snaps/build-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# print.stan_build_info() output for each record state

Code
print(full_x)
Output
Build record: available
Reported features:
stan_threads: TRUE
stan_mpi: FALSE
stan_opencl: FALSE
stan_no_range_checks: unknown
stan_version: 2.39.0
Configuration:
cpp_options: STAN_THREADS=true STAN_CPP_OPTIMS=true
stanc_options: --O1
stanc_options_from_make: --warn-pedantic
include_paths: /proj/inc, /proj/shared
Dependencies:
stan_file: /proj/bernoulli.stan
included_file: /proj/inc/half.stan
included_file: /proj/shared/prior.stan (no longer exists)
user_header: /proj/helpers.hpp
make_local: /opt/cmdstan-2.39.0/make/local
CmdStan 2.39.0 at /opt/cmdstan-2.39.0
Dependencies CmdStanR does not track:
make/local includes another makefile (/opt/cmdstan-2.39.0/make/local)
the user header includes other headers (/proj/helpers.hpp)

---

Code
print(sparse_x)
Output
Build record: available
Reported features:
stan_threads: TRUE
stan_mpi: unknown
stan_opencl: FALSE
stan_no_range_checks: unknown
stan_version: 2.39.0
Configuration:
cpp_options: STAN_THREADS=true
stanc_options: --O1
stanc_options_from_make: none
include_paths: none
Dependencies:
stan_file: bernoulli.stan (no longer exists)
CmdStan 2.39.0 at /opt/cmdstan-2.39.0 (no longer exists)

---

Code
print(missing_x)
Output
Build record: not found. Only what the executable says about itself is known.
Reported features:
stan_threads: unknown
stan_mpi: unknown
stan_opencl: unknown
stan_no_range_checks: unknown
stan_version: unknown

---

Code
print(unreadable_x)
Output
Build record: could not be read. Rebuilding the executable writes a new one.
Reported features:
stan_threads: unknown
stan_mpi: unknown
stan_opencl: unknown
stan_no_range_checks: unknown
stan_version: unknown

---

Code
print(mismatch_x)
Output
Build record: does not match. Executable changed after the build.
Reported features:
stan_threads: unknown
stan_mpi: unknown
stan_opencl: unknown
stan_no_range_checks: unknown
stan_version: unknown

---

Code
print(newer_x)
Output
Build record: format 2 (newer CmdStanR). Upgrade CmdStanR to read it.
Reported features:
stan_threads: unknown
stan_mpi: unknown
stan_opencl: unknown
stan_no_range_checks: unknown
stan_version: unknown

---

Code
print(older_x)
Output
Build record: format 0 (older CmdStanR). Rebuild the executable to replace it.
Reported features:
stan_threads: unknown
stan_mpi: unknown
stan_opencl: unknown
stan_no_range_checks: unknown
stan_version: unknown

Loading
Loading