Bind native format inputs after moving a project tree
This commit is contained in:
1 parent
c2e1e64a60
commit
1ad9c4db82
8 files changed
+509
-23
No files matched your search
@@ -1554,6 +1554,184 @@ fn format_seed_reuse_restarts_execution_and_checks_live_dependencies() {
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relocated_format_checks_current_sources_and_consumed_stream_ranges() {
|
||||
let root = directory("format-relocation").canonicalize().unwrap();
|
||||
let origin = root.join("origin");
|
||||
let project = root.join("project");
|
||||
for directory in [&origin, &project] {
|
||||
fs::create_dir_all(directory.join("formats")).unwrap();
|
||||
fs::create_dir_all(directory.join("parts")).unwrap();
|
||||
}
|
||||
let fixed = origin.join("pinned.tex");
|
||||
let seed = format!(
|
||||
"\\catcode123=1 \\catcode125=2 \\pdfoutput=1\n\
|
||||
\\input parts/layout.tex\n\
|
||||
\\input \"{}\"\n\
|
||||
\\openin3=range.tex \\read3 to\\storedwidth \\closein3\n\
|
||||
\\dump\n",
|
||||
fixed.display()
|
||||
);
|
||||
let layout = br"\def\savedrule{\vrule width\storedwidth height\fixedheight depth0pt}";
|
||||
fs::write(origin.join("seed.tex"), &seed).unwrap();
|
||||
fs::write(origin.join("parts/layout.tex"), layout).unwrap();
|
||||
fs::write(origin.join("range.tex"), b"8pt\nunread before move\n").unwrap();
|
||||
fs::write(&fixed, br"\def\fixedheight{4pt}").unwrap();
|
||||
|
||||
let mut build = request(&origin);
|
||||
build.input = "seed.tex".into();
|
||||
build.output = "formats/seed.tfx".into();
|
||||
let dumped = dump_format(build, Cancellation::default()).unwrap();
|
||||
assert!(dumped.resources.trace.stream_reads.iter().any(|range| {
|
||||
range.path == origin.join("range.tex") && range.offset == 0 && range.bytes == 4
|
||||
}));
|
||||
|
||||
let seed_path = project.join("seed.tex");
|
||||
let library = project.join("parts/layout.tex");
|
||||
let stream = project.join("range.tex");
|
||||
let format = project.join("formats/seed.tfx");
|
||||
let entry = project.join("entry.tex");
|
||||
let padding = format!("{}\n", "\\relax ".repeat(30)).repeat(42);
|
||||
let prefix = "\\shipout\\hbox{\\savedrule}\n";
|
||||
let source = |width| {
|
||||
format!(
|
||||
"{prefix}{padding}\\shipout\\hbox{{\\vrule width{width}pt height3pt depth0pt}}\\end\n"
|
||||
)
|
||||
};
|
||||
|
||||
let world = WorldConfig::new(&project);
|
||||
let snapshot = ProjectSnapshot::new(ProjectDefinition {
|
||||
configuration: world.clone(),
|
||||
revision: 1,
|
||||
roots: [root.clone()].into(),
|
||||
files: [
|
||||
(seed_path.clone(), Arc::from(seed.as_bytes())),
|
||||
(library.clone(), Arc::from(layout.as_slice())),
|
||||
(
|
||||
stream.clone(),
|
||||
Arc::from(b"8pt\nunread after move\n".as_slice()),
|
||||
),
|
||||
(
|
||||
format.clone(),
|
||||
fs::read(origin.join("formats/seed.tfx")).unwrap().into(),
|
||||
),
|
||||
(entry.clone(), Arc::from(source(3).into_bytes())),
|
||||
(fixed.clone(), fs::read(&fixed).unwrap().into()),
|
||||
(
|
||||
project.join("pinned.tex"),
|
||||
Arc::from(br"\def\fixedheight{99pt}".as_slice()),
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
directories: Default::default(),
|
||||
aliases: Default::default(),
|
||||
generated_roots: [project.clone()].into(),
|
||||
generated: Default::default(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let mut job = request(&project);
|
||||
job.world = world;
|
||||
job.input = entry.clone();
|
||||
job.entry = Entry::Format(format);
|
||||
let compiler = NativeCompiler::default().with_entry_checkpoints(prefix.len() + 48);
|
||||
let first = compiler
|
||||
.compile(job.clone().with_project(snapshot.clone()))
|
||||
.unwrap();
|
||||
assert!(
|
||||
first
|
||||
.execution
|
||||
.execution
|
||||
.sources
|
||||
.iter()
|
||||
.any(|source| source.name == library.to_string_lossy())
|
||||
);
|
||||
assert!(
|
||||
first
|
||||
.resources
|
||||
.trace
|
||||
.reads
|
||||
.iter()
|
||||
.any(|resource| resource.path == fixed)
|
||||
);
|
||||
assert_eq!(
|
||||
first
|
||||
.resources
|
||||
.trace
|
||||
.format_input_bindings
|
||||
.get(&origin.join("parts/layout.tex")),
|
||||
Some(&library)
|
||||
);
|
||||
assert_eq!(
|
||||
first
|
||||
.resources
|
||||
.trace
|
||||
.format_input_bindings
|
||||
.get(&origin.join("range.tex")),
|
||||
Some(&stream)
|
||||
);
|
||||
assert!(
|
||||
!first
|
||||
.resources
|
||||
.trace
|
||||
.format_input_bindings
|
||||
.contains_key(&fixed)
|
||||
);
|
||||
|
||||
let changed = snapshot
|
||||
.with_file_edits(2, [(entry, source(5).into_bytes().into())].into())
|
||||
.unwrap();
|
||||
let revised = job.clone().with_project(changed.clone());
|
||||
let next = compiler.compile(revised.clone()).unwrap();
|
||||
assert!(
|
||||
next.entry_checkpoint_work.reused_steps > 0,
|
||||
"{:?}",
|
||||
next.entry_checkpoint_work
|
||||
);
|
||||
let delta = next.preview_since(Some(first.revision())).unwrap();
|
||||
assert_eq!(
|
||||
delta
|
||||
.pages
|
||||
.iter()
|
||||
.map(|page| page.index)
|
||||
.collect::<Vec<_>>(),
|
||||
[1]
|
||||
);
|
||||
let full = NativeCompiler::default().compile(revised).unwrap();
|
||||
assert_eq!(next.pdf, full.pdf);
|
||||
assert_eq!(next.pages, full.pages);
|
||||
assert_eq!(next.source_map.pages, full.source_map.pages);
|
||||
assert_eq!(next.source_map.sources, full.source_map.sources);
|
||||
assert_eq!(
|
||||
next.preview_since(None).unwrap().pages,
|
||||
full.preview_since(None).unwrap().pages
|
||||
);
|
||||
|
||||
for (path, bytes) in [
|
||||
(
|
||||
&library,
|
||||
br"\def\savedrule{\vrule width5pt height4pt}".as_slice(),
|
||||
),
|
||||
(&stream, b"9pt\nunread after move\n".as_slice()),
|
||||
] {
|
||||
let edited = changed
|
||||
.with_file_edits(3, [(path.clone(), Arc::from(bytes))].into())
|
||||
.unwrap();
|
||||
let failure = compiler
|
||||
.compile_detailed(job.clone().with_project(edited))
|
||||
.err()
|
||||
.unwrap();
|
||||
let message = failure.error.to_string();
|
||||
assert!(
|
||||
message.contains("native format source changed")
|
||||
&& message.contains(path.to_str().unwrap()),
|
||||
"{message}"
|
||||
);
|
||||
assert!(Arc::ptr_eq(&next, &compiler.latest().unwrap()));
|
||||
}
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_format_build_load_and_cancelled_build_preserve_real_output_policy() {
|
||||
let p = directory("format");
|
||||
|
||||
Reference in new issue
Block a user