diff --git a/scopegraphs-macros/Cargo.toml b/scopegraphs-macros/Cargo.toml index 7672e52..e191041 100644 --- a/scopegraphs-macros/Cargo.toml +++ b/scopegraphs-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scopegraphs-macros" -version = "0.2.9" +version = "0.2.13" edition = "2021" license = "MIT OR Apache-2.0" authors = [ @@ -20,7 +20,7 @@ proc-macro = true [dependencies] syn = { version = "2.0.29", features = [] } quote = "1.0.33" -scopegraphs-regular-expressions = { path = "../scopegraphs-regular-expressions", features = ["dot"], version = "0.2.0" } +scopegraphs-regular-expressions = { path = "../scopegraphs-regular-expressions", features = ["dot"], version = "0.2" } proc-macro2 = "1.0.69" [dev-dependencies] diff --git a/scopegraphs-regular-expressions/Cargo.toml b/scopegraphs-regular-expressions/Cargo.toml index 20815bd..0020135 100644 --- a/scopegraphs-regular-expressions/Cargo.toml +++ b/scopegraphs-regular-expressions/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scopegraphs-regular-expressions" -version = "0.2.10" +version = "0.2.13" edition = "2021" license = "MIT OR Apache-2.0" authors = [ diff --git a/scopegraphs-render-docs/Cargo.toml b/scopegraphs-render-docs/Cargo.toml index 81e4855..2f2734f 100644 --- a/scopegraphs-render-docs/Cargo.toml +++ b/scopegraphs-render-docs/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "scopegraphs-render-docs" -version = "0.2.0" +version = "0.2.18" authors = ["Mike Lubinets ", "Frank Rehberger ", "Jonathan Dönszelmann "] description = "Derived from Aquamarine, a mermaid.js integration for rustdoc, renders scopegraphs by executing doctests to generate mermaid" keywords = ["proc_macro", "docs", "rustdoc", "mermaid", "diagram"] categories = ["visualization", "development-tools::build-utils"] -repository = "https://github.com/mersinvald/aquamarine" +repository = "https://github.com/metaborg/rust-scopegraphs/" edition = "2018" license = "MIT" include = ["src/**/*", "Cargo.toml", "doc/js/**"] diff --git a/scopegraphs-render-docs/src/attrs.rs b/scopegraphs-render-docs/src/attrs.rs index 27acfbf..fc0ac28 100644 --- a/scopegraphs-render-docs/src/attrs.rs +++ b/scopegraphs-render-docs/src/attrs.rs @@ -10,7 +10,7 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use std::io::{stderr, stdout, Write}; use std::path::Path; use std::path::PathBuf; -use std::process::Command; +use std::process::{Command, Stdio}; use std::{fs, io}; use syn::{Attribute, Ident, MetaNameValue}; @@ -297,6 +297,54 @@ fn run_code(code: &str) -> Result, EvalError> { ); let target_dir = std::env::var("CARGO_TARGET_DIR").unwrap_or("./target".to_string()); + // this if is so it works on docs.rs, + // which sets a custom target and compiles in a folder called "workdir" + let (sg_dir, target_dir) = if manifest_dir.join("..").join("workdir").exists() { + ( + manifest_dir + .join("..") + .join("workdir") + .to_string_lossy() + .to_string(), + "/opt/rustwide/target".to_string(), + ) + } else { + ( + manifest_dir + .join("..") + .join("scopegraphs") + .to_string_lossy() + .to_string(), + target_dir, + ) + }; + + fn copy_dir_all(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + fs::create_dir_all(&dst)?; + for entry in fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; + } else { + fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; + } + } + Ok(()) + } + + let sg_target_dir = temp_dir().join("SG_TARGET"); + if sg_target_dir.exists() { + fs::remove_dir_all(&sg_target_dir).map_err(EvalError::RemoveOldOutputDir)?; + } + copy_dir_all(target_dir, &sg_target_dir).expect("copy dir"); + if sg_target_dir.join("debug").join(".cargo-lock").exists() { + fs::remove_file(sg_target_dir.join("debug").join(".cargo-lock")).unwrap(); + } + if sg_target_dir.join("release").join(".cargo-lock").exists() { + fs::remove_file(sg_target_dir.join("release").join(".cargo-lock")).unwrap(); + } + let cargo = PathBuf::from(std::env::var("CARGO").expect("$CARGO is set during compilation")); let code_hash = hash_str(code).to_string(); @@ -319,9 +367,9 @@ name = \"render_docs_{code_hash}\" edition=\"2021\" [dev-dependencies] -scopegraphs = {{path = \"{}/../scopegraphs\"}} +scopegraphs = {{path = \"{}\"}} ", - manifest_dir.to_string_lossy() + sg_dir ), ) .map_err(EvalError::WriteProject)?; @@ -341,10 +389,13 @@ fn documented() {{}} let output = Command::new(cargo) .current_dir(out_dir) - .env("CARGO_TARGET_DIR", target_dir) + .env("CARGO_TARGET_DIR", sg_target_dir) .arg("test") + .arg("--offline") .arg("--doc") .arg("documented") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) .output() .map_err(EvalError::RunCargo)?; diff --git a/scopegraphs/Cargo.toml b/scopegraphs/Cargo.toml index 20e7d73..d56fda7 100644 --- a/scopegraphs/Cargo.toml +++ b/scopegraphs/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "scopegraphs" -version = "0.2.7" +version = "0.2.18" edition = "2021" license = "MIT OR Apache-2.0" authors = [ "Aron Zwaan ", - "Jonathan Dönszelmann ", + "Jonathan Dönszelmann ", ] description = "A port of scopegraphs https://pl.ewi.tudelft.nl/research/projects/scope-graphs/ to Rust" repository = "https://github.com/metaborg/rust-scopegraphs/" @@ -20,9 +20,9 @@ bumpalo = "3.14.0" scopegraphs-prust-lib = { version = "0.1.0" } log = "0.4.20" -scopegraphs-macros = { path = "../scopegraphs-macros", version = "0.2.0" } -scopegraphs-regular-expressions = { path = "../scopegraphs-regular-expressions", version = "0.2.0" } -scopegraphs-render-docs = { path = "../scopegraphs-render-docs", version = "0.2.0", optional = true } +scopegraphs-macros = { path = "../scopegraphs-macros", version = "0.2" } +scopegraphs-regular-expressions = { path = "../scopegraphs-regular-expressions", version = "0.2" } +scopegraphs-render-docs = { path = "../scopegraphs-render-docs", version = "0.2", optional = true } [dev-dependencies] env_logger = "0.10.1"