mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
This modifies Rojo's build script to throw a fit if we're building a plugin with a semver incompatible version. In the process, it moves the version of the plugin to a file named `Version.txt` that's parsed at runtime. This should be minimally invasive but it's technically worse for performance than the hardcoded table and string we had before. This feels better than a CI check or just manually verifying because it makes it physically impossible for us to forget since Rojo won't build with it being wrong.
82 lines
2.7 KiB
Rust
82 lines
2.7 KiB
Rust
use std::{
|
|
env, io,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use fs_err as fs;
|
|
use fs_err::File;
|
|
use maplit::hashmap;
|
|
use memofs::VfsSnapshot;
|
|
use semver::Version;
|
|
|
|
fn snapshot_from_fs_path(path: &Path) -> io::Result<VfsSnapshot> {
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
|
|
if path.is_dir() {
|
|
let mut children = Vec::new();
|
|
|
|
for entry in fs::read_dir(path)? {
|
|
let entry = entry?;
|
|
|
|
let file_name = entry.file_name().to_str().unwrap().to_owned();
|
|
|
|
// We can skip any TestEZ test files since they aren't necessary for
|
|
// the plugin to run.
|
|
if file_name.ends_with(".spec.lua") || file_name.ends_with(".spec.luau") {
|
|
continue;
|
|
}
|
|
|
|
let child_snapshot = snapshot_from_fs_path(&entry.path())?;
|
|
children.push((file_name, child_snapshot));
|
|
}
|
|
|
|
Ok(VfsSnapshot::dir(children))
|
|
} else {
|
|
let content = fs::read_to_string(path)?;
|
|
|
|
Ok(VfsSnapshot::file(content))
|
|
}
|
|
}
|
|
|
|
fn main() -> Result<(), anyhow::Error> {
|
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
|
|
|
let root_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
|
|
let plugin_root = PathBuf::from(root_dir).join("plugin");
|
|
|
|
let our_version = Version::parse(env::var_os("CARGO_PKG_VERSION").unwrap().to_str().unwrap())?;
|
|
let plugin_version =
|
|
Version::parse(fs::read_to_string(&plugin_root.join("Version.txt"))?.trim())?;
|
|
|
|
assert!(
|
|
our_version.major == plugin_version.major,
|
|
"plugin version does not match Cargo version"
|
|
);
|
|
assert!(
|
|
our_version.minor == plugin_version.minor,
|
|
"plugin version does not match Cargo version"
|
|
);
|
|
|
|
let snapshot = VfsSnapshot::dir(hashmap! {
|
|
"default.project.json" => snapshot_from_fs_path(&plugin_root.join("default.project.json"))?,
|
|
"fmt" => snapshot_from_fs_path(&plugin_root.join("fmt"))?,
|
|
"http" => snapshot_from_fs_path(&plugin_root.join("http"))?,
|
|
"log" => snapshot_from_fs_path(&plugin_root.join("log"))?,
|
|
"rbx_dom_lua" => snapshot_from_fs_path(&plugin_root.join("rbx_dom_lua"))?,
|
|
"src" => snapshot_from_fs_path(&plugin_root.join("src"))?,
|
|
"Packages" => snapshot_from_fs_path(&plugin_root.join("Packages"))?,
|
|
"Version.txt" => snapshot_from_fs_path(&plugin_root.join("Version.txt"))?,
|
|
});
|
|
|
|
let out_path = Path::new(&out_dir).join("plugin.bincode");
|
|
let out_file = File::create(out_path)?;
|
|
|
|
bincode::serialize_into(out_file, &snapshot)?;
|
|
|
|
println!("cargo:rerun-if-changed=build/windows/rojo-manifest.rc");
|
|
println!("cargo:rerun-if-changed=build/windows/rojo.manifest");
|
|
embed_resource::compile("build/windows/rojo-manifest.rc");
|
|
|
|
Ok(())
|
|
}
|