mirror of
https://github.com/typst/typst
synced 2025-07-27 06:17:53 +08:00
feat: --deps0
flag for getting a NUL-separated dependency list
This commit is contained in:
parent
627f5b9d4f
commit
b8b4116255
@ -267,6 +267,10 @@ pub struct CompileArgs {
|
|||||||
#[clap(long = "make-deps", value_name = "PATH")]
|
#[clap(long = "make-deps", value_name = "PATH")]
|
||||||
pub make_deps: Option<PathBuf>,
|
pub make_deps: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// File path to which a list of NUL-separated current compilation's dependencies will be written
|
||||||
|
#[clap(long, value_name = "PATH")]
|
||||||
|
pub deps0: Option<PathBuf>,
|
||||||
|
|
||||||
/// Processing arguments.
|
/// Processing arguments.
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
pub process: ProcessArgs,
|
pub process: ProcessArgs,
|
||||||
|
@ -67,6 +67,8 @@ pub struct CompileConfig {
|
|||||||
pub pdf_standards: PdfStandards,
|
pub pdf_standards: PdfStandards,
|
||||||
/// A path to write a Makefile rule describing the current compilation.
|
/// A path to write a Makefile rule describing the current compilation.
|
||||||
pub make_deps: Option<PathBuf>,
|
pub make_deps: Option<PathBuf>,
|
||||||
|
/// A path to write a list of NUL-separated dependencies.
|
||||||
|
pub deps0: Option<PathBuf>,
|
||||||
/// The PPI (pixels per inch) to use for PNG export.
|
/// The PPI (pixels per inch) to use for PNG export.
|
||||||
pub ppi: f32,
|
pub ppi: f32,
|
||||||
/// The export cache for images, used for caching output files in `typst
|
/// The export cache for images, used for caching output files in `typst
|
||||||
@ -152,6 +154,7 @@ impl CompileConfig {
|
|||||||
pdf_standards,
|
pdf_standards,
|
||||||
creation_timestamp: args.world.creation_timestamp,
|
creation_timestamp: args.world.creation_timestamp,
|
||||||
make_deps: args.make_deps.clone(),
|
make_deps: args.make_deps.clone(),
|
||||||
|
deps0: args.deps0.clone(),
|
||||||
ppi: args.ppi,
|
ppi: args.ppi,
|
||||||
diagnostic_format: args.process.diagnostic_format,
|
diagnostic_format: args.process.diagnostic_format,
|
||||||
open: args.open.clone(),
|
open: args.open.clone(),
|
||||||
@ -210,6 +213,8 @@ pub fn compile_once(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_deps0(world, config)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,6 +605,38 @@ fn write_make_deps(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_deps0(world: &mut SystemWorld, config: &CompileConfig) -> StrResult<()> {
|
||||||
|
let Some(ref deps_path) = config.deps0 else { return Ok(()) };
|
||||||
|
fn write(
|
||||||
|
deps_path: &Path,
|
||||||
|
root: PathBuf,
|
||||||
|
dependencies: impl Iterator<Item = PathBuf>,
|
||||||
|
) -> io::Result<()> {
|
||||||
|
let mut file = File::create(deps_path)?;
|
||||||
|
let current_dir = std::env::current_dir()?;
|
||||||
|
let relative_root = diff_paths(&root, ¤t_dir).unwrap_or(root.clone());
|
||||||
|
|
||||||
|
dependencies
|
||||||
|
.into_iter()
|
||||||
|
.map(|dependency| {
|
||||||
|
dependency
|
||||||
|
.strip_prefix(&root)
|
||||||
|
.map_or_else(|_| dependency.clone(), |x| relative_root.join(x))
|
||||||
|
.into_os_string()
|
||||||
|
.into_encoded_bytes()
|
||||||
|
.into_boxed_slice()
|
||||||
|
})
|
||||||
|
.try_for_each(|ref dep| {
|
||||||
|
file.write_all(dep)?;
|
||||||
|
file.write_all(b"\0")?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
write(deps_path, world.root().to_owned(), world.dependencies()).map_err(|err| {
|
||||||
|
eco_format!("failed to create dependencies file due to IO error ({err})")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Opens the output if desired.
|
/// Opens the output if desired.
|
||||||
fn open_output(config: &mut CompileConfig) -> StrResult<()> {
|
fn open_output(config: &mut CompileConfig) -> StrResult<()> {
|
||||||
let Some(viewer) = config.open.take() else { return Ok(()) };
|
let Some(viewer) = config.open.take() else { return Ok(()) };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user