mirror of
https://github.com/taiki-e/install-action.git
synced 2026-04-08 18:05:42 +08:00
codegen: Avoid allocation in workspace_root()
This commit is contained in:
@@ -2,14 +2,11 @@
|
||||
|
||||
#![allow(clippy::missing_panics_doc, clippy::too_long_first_doc_paragraph)]
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
use std::{env, path::Path};
|
||||
|
||||
pub use install_action_manifest_schema::*;
|
||||
|
||||
#[must_use]
|
||||
pub fn workspace_root() -> PathBuf {
|
||||
let mut dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
dir.pop(); // codegen
|
||||
dir.pop(); // tools
|
||||
dir
|
||||
pub fn workspace_root() -> &'static Path {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR").strip_suffix("tools/codegen").unwrap())
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ fn main() -> Result<()> {
|
||||
let version_req_given = version_req.is_some();
|
||||
let skip_existing_manifest_versions = std::env::var("SKIP_EXISTING_MANIFEST_VERSIONS").is_ok();
|
||||
|
||||
let workspace_root = &workspace_root();
|
||||
let workspace_root = workspace_root();
|
||||
let manifest_path = &workspace_root.join("manifests").join(format!("{package}.json"));
|
||||
let download_cache_dir = &workspace_root.join("tools/codegen/tmp/cache").join(package);
|
||||
fs::create_dir_all(manifest_path.parent().unwrap())?;
|
||||
|
||||
@@ -40,9 +40,9 @@ fn main() -> Result<()> {
|
||||
|
||||
let workspace_root = workspace_root();
|
||||
|
||||
let mut manifest_dir = workspace_root.clone();
|
||||
let mut manifest_dir = workspace_root.to_owned();
|
||||
manifest_dir.push("manifests");
|
||||
let mut base_info_dir = workspace_root.clone();
|
||||
let mut base_info_dir = workspace_root.to_owned();
|
||||
base_info_dir.push("tools");
|
||||
base_info_dir.push("codegen");
|
||||
base_info_dir.push("base");
|
||||
@@ -112,7 +112,7 @@ fn main() -> Result<()> {
|
||||
|
||||
tools.sort_by(|x, y| x.name.cmp(&y.name));
|
||||
|
||||
let mut markdown_file = workspace_root.clone();
|
||||
let mut markdown_file = workspace_root.to_owned();
|
||||
markdown_file.push("TOOLS.md");
|
||||
|
||||
let mut file = BufWriter::new(fs::File::create(markdown_file).unwrap()); // Buffered because it is written many times.
|
||||
|
||||
Reference in New Issue
Block a user