Fix some build steps being re-run a second time unnecessarily

This commit is contained in:
Damien Elmes 2023-11-13 13:28:51 +10:00
parent ae7b14bf40
commit d9e5c85686
3 changed files with 12 additions and 8 deletions

View file

@ -1,12 +1,12 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::io::BufWriter;
use std::io::Cursor;
use std::io::Write;
use std::path::Path;
use anki_io::create_dir_all;
use anki_io::create_file;
use anki_io::write_file_if_changed;
use anki_proto_gen::BackendService;
use anki_proto_gen::Method;
use anyhow::Result;
@ -18,7 +18,7 @@ use prost_reflect::MessageDescriptor;
pub(crate) fn write_python_interface(services: &[BackendService]) -> Result<()> {
let output_path = Path::new("../../out/pylib/anki/_backend_generated.py");
create_dir_all(output_path.parent().unwrap())?;
let mut out = BufWriter::new(create_file(output_path)?);
let mut out = Cursor::new(Vec::new());
write_header(&mut out)?;
for service in services {
@ -29,6 +29,7 @@ pub(crate) fn write_python_interface(services: &[BackendService]) -> Result<()>
render_method(service, method, &mut out);
}
}
write_file_if_changed(output_path, out.into_inner())?;
Ok(())
}

View file

@ -11,6 +11,7 @@ use anki_proto_gen::BackendService;
use anki_proto_gen::Method;
use anyhow::Result;
use inflections::Inflect;
use itertools::Itertools;
pub(crate) fn write_ts_interface(services: &[BackendService]) -> Result<()> {
let root = Path::new("../../out/ts/lib");
@ -59,7 +60,7 @@ import type { PostProtoOptions } from "./post";
fn imports(referenced_packages: HashSet<String>) -> String {
let mut out = String::new();
for package in referenced_packages {
for package in referenced_packages.iter().sorted() {
writeln!(
&mut out,
"import * as {} from \"./anki/{}_pb\";",

View file

@ -28,10 +28,10 @@ function adjustFiles() {
const jsFiles = allFilesInDir(root).filter(f => f.endsWith(".js"));
for (const file of jsFiles) {
let contents = fs.readFileSync(file, "utf8");
const contents = fs.readFileSync(file, "utf8");
// allow tree shaking on proto messages
contents = contents.replace(
let newContents = contents.replace(
/= proto3.make/g,
"= /* @__PURE__ */ proto3.make",
);
@ -39,9 +39,11 @@ function adjustFiles() {
// strip out typeName info, which appears to only be required for
// certain JSON functionality (though this only saves a few hundred
// bytes)
contents = contents.replace(typeRe, "$1(\"\",");
newContents = contents.replace(typeRe, "$1(\"\",");
fs.writeFileSync(file, contents, "utf8");
if (contents != newContents) {
fs.writeFileSync(file, newContents, "utf8");
}
}
}