Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom search directories #814

Merged
merged 7 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ struct BridgeState {
/// The main filesystem backing for input files in the project.
filesystem: FilesystemIo,

/// Extra paths we search through for files.
extra_search_paths: Vec<FilesystemIo>,

/// Additional filesystem backing used if "shell escape" functionality is
/// activated. If None, we take that to mean that shell-escape is
/// disallowed. We have to use a persistent filesystem directory for this
Expand Down Expand Up @@ -447,6 +450,11 @@ macro_rules! bridgestate_ioprovider_cascade {
if let Some(ref mut p) = $self.shell_escape_work {
bridgestate_ioprovider_try!(p, $($inner)+);
}

// extra search paths
for fsio in $self.extra_search_paths.iter_mut() {
bridgestate_ioprovider_try!(fsio, $($inner)+);
}
}

bridgestate_ioprovider_try!($self.bundle.as_ioprovider_mut(), $($inner)+);
Expand Down Expand Up @@ -1068,6 +1076,12 @@ impl ProcessingSessionBuilder {
primary_input: pio,
mem,
filesystem,
extra_search_paths: self
.unstables
.extra_search_paths
.iter()
.map(|p| FilesystemIo::new(p, false, false, HashSet::new()))
.collect(),
shell_escape_work: None,
format_cache,
bundle,
Expand Down
30 changes: 21 additions & 9 deletions src/unstable_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
//! to be reliable or very polished. In particular, many of these prevent the build from being
//! reproducible.

use crate::errmsg;
ralismark marked this conversation as resolved.
Show resolved Hide resolved
use crate::errors::{Error, Result};
use std::default::Default;
use std::path::PathBuf;
use std::str::FromStr;

const HELPMSG: &str = r#"Available unstable options:
Expand All @@ -19,6 +21,8 @@ const HELPMSG: &str = r#"Available unstable options:
-Z min-crossrefs=<num> Equivalent to bibtex's -min-crossrefs flag - "include after <num>
crossrefs" [default: 2]
-Z paper-size=<spec> Change the default paper size [default: letter]
-Z search-path=<path> Also look in <path> for files, like TEXINPUTS. Can be specified
multiple times.
-Z shell-escape Enable \write18
"#;

Expand All @@ -29,6 +33,7 @@ pub enum UnstableArg {
Help,
MinCrossrefs(i32),
PaperSize(String),
SearchPath(PathBuf),
ShellEscapeEnabled,
}

Expand All @@ -44,25 +49,30 @@ impl FromStr for UnstableArg {
// For structopt/clap, if you pass a value to a flag which doesn't accept one, it's
// silently ignored.

let require_value = |value_name| {
value.ok_or_else(|| {
errmsg!(
"'-Z {}=<{}>' requires a value but none was supplied",
arg,
value_name
)
})
};

match arg {
"help" => Ok(UnstableArg::Help),

"continue-on-errors" => Ok(UnstableArg::ContinueOnErrors),

"min-crossrefs" => value
.ok_or_else(|| {
"'-Z min-crossrefs <spec>' requires a value but none was supplied".into()
})
"min-crossrefs" => require_value("num")
.and_then(|s| {
FromStr::from_str(s).map_err(|e| format!("-Z min-crossrefs: {}", e).into())
})
.map(UnstableArg::MinCrossrefs),

"paper-size" => value
.ok_or_else(|| {
"'-Z paper-size <spec>' requires a value but none was supplied".into()
})
.map(|s| UnstableArg::PaperSize(s.to_string())),
"paper-size" => require_value("spec").map(|s| UnstableArg::PaperSize(s.to_string())),

"search-path" => require_value("path").map(|s| UnstableArg::SearchPath(s.into())),

"shell-escape" => Ok(UnstableArg::ShellEscapeEnabled),

Expand All @@ -77,6 +87,7 @@ pub struct UnstableOptions {
pub paper_size: Option<String>,
pub shell_escape: bool,
pub min_crossrefs: Option<i32>,
pub extra_search_paths: Vec<PathBuf>,
}

impl UnstableOptions {
Expand All @@ -97,6 +108,7 @@ impl UnstableOptions {
MinCrossrefs(num) => opts.min_crossrefs = Some(num),
PaperSize(size) => opts.paper_size = Some(size),
ShellEscapeEnabled => opts.shell_escape = true,
SearchPath(p) => opts.extra_search_paths.push(p),
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/executable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,3 +794,17 @@ fn shell_escape_env_override() {

error_or_panic(&output);
}

/// Test that include paths work
#[test]
fn extra_search_paths() {
let fmt_arg = get_plain_format_arg();
let tempdir = setup_and_copy_files(&["subdirectory/content/1.tex"]);

let output = run_tectonic_with_stdin(
tempdir.path(),
&[&fmt_arg, "-", "-Zsearch-path=subdirectory/content"],
"\\input 1.tex\n\\bye",
);
success_or_panic(&output);
}