Skip to content

Commit 5ba2761

Browse files
committedJan 22, 2025·
Replace CR/CRLF line endings by LF in vendored makefiles
In an attempt to fix R CMD CHECK workflow in CI and notably https://github.com/riatelab/distanamo/actions/runs/12913965346/job/36012421388#step:6:132
1 parent 2189a51 commit 5ba2761

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed
 

‎dev/vendoring.R

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#' The code of this function was copied/pasted from
22
#' https://github.com/PRQL/prqlc-r/blob/main/dev/vendoring.R
33
#' (licensed under MIT - (c) prqlr authors)
4-
#' with minor modification to remove the vendor folder
5-
#' after the vendor.tar.xz has been created
4+
#' with minor modification to :
5+
#' - remove the vendor folder after the vendor.tar.xz has been created
6+
#' - replace cr/crlf line end by lf in savvy-bindgen/src/gen/templates/Makevars.in
7+
#' (and any other file if necessary)
68
vendor_crates <- function(path = ".") {
79
src_dir <- rprojroot::find_package_root_file("src", path = path)
810

@@ -23,11 +25,18 @@ vendor_crates <- function(path = ".") {
2325
)
2426
)$stdout
2527

28+
config_toml_content <- stringr::str_replace_all(config_toml_content, "rust/vendor", "vendor")
29+
2630
brio::write_lines(
2731
text = config_toml_content,
2832
path = config_toml_file
2933
)
3034

35+
# We need to replace CR/CRLF line endings by LF in
36+
# src/rust/vendor/savvy-bindgen/src/gen/templates/Makevars.in in an attempt to fix
37+
# https://github.com/riatelab/distanamo/actions/runs/12913965346/job/36012421388#step:6:132
38+
find_and_replace_crlf(file.path(src_dir, "rust", "vendor"))
39+
3140
withr::local_dir(file.path(src_dir, vendor_rel_path))
3241
withr::local_envvar(c(XZ_OPT = "-9"))
3342
processx::run(
@@ -48,4 +57,24 @@ vendor_crates <- function(path = ".") {
4857
unlink(file.path(src_dir, "rust", "vendor"), recursive = TRUE)
4958
}
5059

60+
replace_crcrlf <- function(file_path) {
61+
content <- readLines(file_path, warn = FALSE)
62+
content <- stringr::str_replace_all(content, "\r\n|\r", "\n")
63+
writeLines(content, file_path, sep = "\n")
64+
}
65+
66+
find_and_replace_crlf <- function(directory_path) {
67+
files_and_dirs <- list.files(directory_path, full.names = TRUE)
68+
69+
for (item in files_and_dirs) {
70+
if (file.info(item)$isdir) {
71+
find_and_replace_crlf(item)
72+
} else {
73+
if (startsWith(basename(item), "Makevars")) {
74+
replace_crcrlf(item)
75+
}
76+
}
77+
}
78+
}
79+
5180
vendor_crates()

‎src/Makevars.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ $(STATLIB):
2222
# therefore is only used if cargo is absent from the user's PATH.
2323

2424
# Use vendored crates
25-
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
25+
mkdir -p ./rust/vendor && \
26+
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust/vendor && \
2627
mkdir -p ./rust/.cargo && \
2728
cp ./rust/vendor-config.toml ./rust/.cargo/config.toml
2829

@@ -38,6 +39,8 @@ $(STATLIB):
3839
cargo +nightly build $(CARGO_BUILD_ARGS) --target $(TARGET) -Zbuild-std=panic_abort,std; \
3940
fi
4041

42+
rm -Rf ./rust/vendor
43+
4144
C_clean:
4245
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) ./rust/.cargo
4346

‎src/Makevars.win.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ $(STATLIB):
2828

2929

3030
# Use vendored crates
31-
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
31+
mkdir -p ./rust/vendor && \
32+
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust/vendor && \
3233
mkdir -p ./rust/.cargo && \
3334
cp ./rust/vendor-config.toml ./rust/.cargo/config.toml
3435

@@ -39,6 +40,8 @@ $(STATLIB):
3940
export RUSTFLAGS="$(RUSTFLAGS)" && \
4041
cargo build --target $(TARGET) --lib --profile $(PROFILE) --manifest-path ./rust/Cargo.toml --target-dir $(TARGET_DIR)
4142

43+
rm -Rf ./rust/vendor
44+
4245
C_clean:
4346
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) ./rust/.cargo
4447

‎src/rust/vendor-config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ git = "https://github.com/mthh/distance-cartogram-rs"
66
replace-with = "vendored-sources"
77

88
[source.vendored-sources]
9-
directory = "rust/vendor"
9+
directory = "vendor"
1010

‎src/rust/vendor.tar.xz

4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.