Title: | Mock the Unix Make Utility |
Version: | 1.11.1 |
Description: | Use R as a minimal build system. This might come in handy if you are developing R packages and can not use a proper build system. Stay away if you can (use a proper build system). |
License: | BSD_2_clause + file LICENSE |
URL: | https://gitlab.com/fvafrcu/fakemake |
Depends: | R (≥ 3.3.0) |
Imports: | graphics, fritools, igraph, MakefileR, utils |
Suggests: | cleanr, covr, cyclocomp, devtools, hunspell, knitr, lintr, pkgbuild, pkgload, rasciidoc, rmarkdown, roxygen2, rprojroot, RUnit, spelling, testthat, withr, usethis |
VignetteBuilder: | knitr, rasciidoc |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-08-15 21:48:05 UTC; qwer |
Author: | Andreas Dominik Cullmann [aut, cre] |
Maintainer: | Andreas Dominik Cullmann <fvafrcu@mailbox.org> |
Repository: | CRAN |
Date/Publication: | 2023-08-15 22:10:01 UTC |
Mock the Unix Make Utility
Description
Use R as a minimal build system. This might come in handy if you are developing R packages and can not use a proper build system. Stay away if you can (use a proper build system).
Details
You will find the details in
vignette("An_Introduction_to_fakemake", package = "fakemake")
.
Add a Target to a Makelist
Description
Add a target to an existing makelist
.
Usage
add_target(
makelist,
target,
code,
prerequisites = NULL,
prerequisite_to = NULL,
sink = NULL,
alias = sub("\\.(Rout|log)$", "", basename(target))
)
Arguments
makelist |
A list for
|
target |
The target to remove from |
code |
The code for the new target. |
prerequisites |
The prerequisites for the new target. |
prerequisite_to |
The targets the new target is a prerequisite to.
Set to |
sink |
The sink for the new target. |
alias |
The alias for the new target. |
Value
A list for
make
.
See Also
Other functions to manipulate makelists:
get_target()
,
remove_target()
Get a Makelist's Target
Description
Get a single target from a makelist
by
alias.
Usage
get_target(makelist, alias)
Arguments
makelist |
A list for
|
alias |
The alias of the target in question. |
Value
A list (the target requested).
See Also
Other functions to manipulate makelists:
add_target()
,
remove_target()
Examples
ml <- provide_make_list()
visualize(ml, root = "all.Rout")
i <- which(sapply(ml, "[[", "target") == "b1.Rout")
ml[[i]]["alias"] <- "b1"
t <- get_target(ml, "b1")
ml <- remove_target(ml, t[["target"]])
visualize(ml)
ml <- add_target(ml, target = t[["target"]], code = t[["code"]],
sink = t[["sink"]],
prerequisite_to = "a1.Rout", alias = NULL)
all.equal(ml, provide_make_list())
Mock the Unix Make Utility
Description
Mock the Unix Make Utility
Usage
make(
name,
make_list,
force = FALSE,
recursive = force,
verbose = FALSE,
verbosity = 2,
dry_run = FALSE,
unconditionally = FALSE,
stop_on_warning = FALSE
)
Arguments
name |
The name or alias of a make target. |
make_list |
The |
force |
Force the target to be build? See Details. |
recursive |
Force the target to be build recursively? See Details. |
verbose |
Be verbose? |
verbosity |
Give the level of verbosity. |
dry_run |
Run dry? Mock GNU |
unconditionally |
Force the target's code to be evaluated unconditionally to any prerequisites? See Details. |
stop_on_warning |
|
Details
force, recursive
Forcing a target mocks adding .PHONY to a GNU Makefile
if you
set recursive to FALSE. If recursive is TRUE, then the whole make chain will
be forced.
unconditionally
Setting unconditionally
to TRUE
allows you to fool
make
similarily to using GNU make
's –touch option.
Value
Invisibly
a character vector
containing the targets made during the current run.
Examples
str(make_list <- provide_make_list("minimal"))
# build all
withr::with_dir(tempdir(), print(make("all.Rout", make_list)))
# nothing to be done
withr::with_dir(tempdir(), print(make("all.Rout", make_list)))
# forcing all.Rout
withr::with_dir(tempdir(), print(make("all.Rout", make_list, force = TRUE,
recursive = FALSE)))
# forcing all.Rout recursively
withr::with_dir(tempdir(), print(make("all.Rout", make_list, force = TRUE)))
# show files
dir(tempdir(), pattern = ".*\\.Rout")
# dry run
file.remove(dir(tempdir(), pattern = ".*\\.Rout", full.names = TRUE))
withr::with_dir(tempdir(), print(make("all.Rout", make_list,
dry_run = TRUE)))
dir(tempdir(), pattern = ".*\\.Rout")
# make unconditionally
dir(tempdir(), pattern = ".*\\.Rout")
withr::with_dir(tempdir(), print(make("all.Rout", make_list,
unconditionally = TRUE)))
dir(tempdir(), pattern = ".*\\.Rout")
Load an Example Makelist
Provided by fakemake.
Description
Load an Example Makelist
Provided by fakemake.
Usage
provide_make_list(
type = c("minimal", "testing"),
prune = TRUE,
clean_sink = FALSE
)
Arguments
type |
The type of |
prune |
Prune the |
clean_sink |
Remove sinks identical to corresponding targets from the
list? Since |
Value
A makelist
.
Examples
str(provide_make_list("minimal"))
visualize(provide_make_list("minimal"))
Read a Makefile
Into a Makelist
Description
This is experimental! See Note.
Usage
read_makefile(path, clean_sink = FALSE)
Arguments
path |
The path to the file. |
clean_sink |
Remove sinks identical to corresponding targets from the
list? Since |
Value
The makelist
.
Note
This function will not read arbitrary Makefiles
, just those
created via write_makefile
! If you modify such a
Makefile
make sure you only add simple rules like the ones you see in that file.
Examples
make_file <- file.path(tempdir(), "Makefile")
write_makefile(provide_make_list(), path = make_file)
str(make_list <- read_makefile(path = make_file))
Remove a Target From a Makelist
Description
Remove a target and all its appearances as
other targets' dependencies from a makelist
.
Usage
remove_target(makelist, target)
Arguments
makelist |
A list for
|
target |
The target to remove from |
Value
A list for
make
.
See Also
Other functions to manipulate makelists:
add_target()
,
get_target()
Divert Message And Output Stream to File
Description
All output and messages up to the first error, for example thrown by
stop
.
Usage
sink_all(path, code)
Arguments
path |
The path of the file to divert to. |
code |
The code to be executed. |
Value
Examples
sink_path <- file.path(tempdir(), "sink_all.txt")
sink_all(sink_path, {
print("some output")
warning("a warning")
message("a message")
print("some more output")
})
cat(readLines(sink_path), sep = "\n")
Throw a Condition
Description
Throws a condition of class c("error", "fakemake", "condition").
Usage
throw(message_string, system_call = sys.call(-1), ...)
Arguments
message_string |
The message to be thrown. |
system_call |
The call to be thrown. |
... |
Arguments to be passed to
|
Details
We use this condition as an error dedicated to fakemake.
Value
The function does never return anything, it stops with a condition of class c("error", "fakemake", "condition").
Mock the Unix touch
utility
Description
See fritools::touch
.
Usage
touch(...)
Arguments
... |
Arguments passed to |
Value
The return value of fritools::touch
.
Visualize a Makelist
Description
Parse a makelist
, convert it into an igraph
and plot it.
Usage
visualize(make_list, root = NULL)
Arguments
make_list |
The |
root |
The root of a tree. |
Value
Invisibly an igraph representation of the makelist
.
Examples
str(ml <- provide_make_list())
visualize(ml)
visualize(ml, root = "all.Rout")
Write a Makelist
to File
Description
The makelist
is parsed before writing, so all R code which is not in
a "code" item will be evaluated.
So if any other item's string contains code allowing for a dynamic rule,
for example with some "dependencies" reading
"list.files(\"R\", full.names = TRUE)"
, the Makefile
will
have the
evaluated code, a static list of files in the above case.
Usage
write_makefile(make_list, path, Rbin = "Rscript-devel")
Arguments
make_list |
The list to write to file. |
path |
The path to the file. |
Rbin |
The R binary to use in the |
Value
See
MakefileR::write_makefile
.
Examples
make_file <- file.path(tempdir(), "my_Makefile")
write_makefile(provide_make_list(), path = make_file)
cat(readLines(make_file), sep = "\n")