Skip to content

Commit

Permalink
Replace CR/CRLF line endings by LF in vendored makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mthh committed Jan 22, 2025
1 parent 2189a51 commit 032a60a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
31 changes: 29 additions & 2 deletions dev/vendoring.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#' The code of this function was copied/pasted from
#' https://github.com/PRQL/prqlc-r/blob/main/dev/vendoring.R
#' (licensed under MIT - (c) prqlr authors)
#' with minor modification to remove the vendor folder
#' after the vendor.tar.xz has been created
#' with minor modification to :
#' - remove the vendor folder after the vendor.tar.xz has been created
#' - replace cr/crlf line end by lf in savvy-bindgen/src/gen/templates/Makevars.in
#' (and any other file if necessary)
vendor_crates <- function(path = ".") {
src_dir <- rprojroot::find_package_root_file("src", path = path)

Expand All @@ -28,6 +30,11 @@ vendor_crates <- function(path = ".") {
path = config_toml_file
)

# We need to replace CR/CRLF line endings by LF in
# src/rust/savvy-bindgen/src/gen/templates/Makevars.in in an attempt to fix
# https://github.com/riatelab/distanamo/actions/runs/12913965346/job/36012421388#step:6:132
find_and_replace_crlf(file.path(src_dir, "rust", "vendor"))

withr::local_dir(file.path(src_dir, vendor_rel_path))
withr::local_envvar(c(XZ_OPT = "-9"))
processx::run(
Expand All @@ -48,4 +55,24 @@ vendor_crates <- function(path = ".") {
unlink(file.path(src_dir, "rust", "vendor"), recursive = TRUE)
}

replace_crcrlf <- function(file_path) {
content <- readLines(file_path, warn = FALSE)
content <- stringr::str_replace_all(content, "\r\n|\r", "\n")
writeLines(content, file_path, sep = "\n")
}

find_and_replace_crlf <- function(directory_path) {
files_and_dirs <- list.files(directory_path, full.names = TRUE)

for (item in files_and_dirs) {
if (file.info(item)$isdir) {
find_and_replace_crlf(item)
} else {
if (startsWith(basename(item), "Makevars")) {
replace_crcrlf(item)
}
}
}
}

vendor_crates()
5 changes: 4 additions & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ $(STATLIB):
# therefore is only used if cargo is absent from the user's PATH.

# Use vendored crates
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
mkdir -p ./rust/vendor && \
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust/vendor && \
mkdir -p ./rust/.cargo && \
cp ./rust/vendor-config.toml ./rust/.cargo/config.toml

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

rm -Rf ./rust/vendor

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) ./rust/.cargo

Expand Down
5 changes: 4 additions & 1 deletion src/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ $(STATLIB):


# Use vendored crates
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust && \
mkdir -p ./rust/vendor && \
$(TAR) --extract --xz -f ./rust/vendor.tar.xz -C ./rust/vendor && \
mkdir -p ./rust/.cargo && \
cp ./rust/vendor-config.toml ./rust/.cargo/config.toml

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

rm -Rf ./rust/vendor

C_clean:
rm -Rf $(SHLIB) $(STATLIB) $(OBJECTS) ./rust/.cargo

Expand Down
Binary file modified src/rust/vendor.tar.xz
Binary file not shown.

0 comments on commit 032a60a

Please sign in to comment.