Skip to content

Commit

Permalink
fix: extendrtests points to libR-sys submodule
Browse files Browse the repository at this point in the history
updated `xtask` as well
  • Loading branch information
CGMossa committed Jan 28, 2024
1 parent 61eae64 commit 5e4efa4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/extendrtests/src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ libR-sys = "*"
[patch.crates-io]
# root is `tests/extendrtests/src/rust`
extendr-api = { path = "../../../../extendr-api/" }
libR-sys = { path = "../../../../libR-sys/" }
30 changes: 28 additions & 2 deletions xtask/src/extendrtests/with_absolute_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,40 @@ pub(crate) fn swap_extendr_api_path(shell: &Shell) -> Result<DocumentHandle, Box

let mut replacement = InlineTable::new();

let item = Value::from(get_replacement_path(&current_path));
let item = Value::from(get_replacement_path_extendr_api(&current_path));
replacement.entry("path").or_insert(item);
*extendr_api_entry = Value::InlineTable(replacement);

#[allow(non_snake_case)]
let libR_sys_entry =
get_libR_sys_entry(&mut cargo_toml).ok_or("`libR-sys` not found in Cargo.toml")?;

let mut replacement = InlineTable::new();

let item = Value::from(get_replacement_path_libR_sys(&current_path));
replacement.entry("path").or_insert(item);
*libR_sys_entry = Value::InlineTable(replacement);

shell.write_file(CARGO_TOML, cargo_toml.to_string())?;
Ok(DocumentHandle {
document: original_cargo_toml_bytes,
shell,
})
}

fn get_replacement_path(path: &Path) -> String {
fn get_replacement_path_extendr_api(path: &Path) -> String {
let path = path.adjust_for_r();

format!("{path}/extendr-api")
}

#[allow(non_snake_case)]
fn get_replacement_path_libR_sys(path: &Path) -> String {
let path = path.adjust_for_r();

format!("{path}/libR-sys")
}

fn get_extendr_api_entry(document: &mut Document) -> Option<&mut Value> {
document
.get_mut("patch")?
Expand All @@ -66,6 +83,15 @@ fn get_extendr_api_entry(document: &mut Document) -> Option<&mut Value> {
.as_value_mut()
}

#[allow(non_snake_case)]
fn get_libR_sys_entry(document: &mut Document) -> Option<&mut Value> {
document
.get_mut("patch")?
.get_mut("crates-io")?
.get_mut("libR-sys")?
.as_value_mut()
}

fn read_file_with_line_ending<P: AsRef<Path>>(
shell: &Shell,
path: P,
Expand Down

0 comments on commit 5e4efa4

Please sign in to comment.