Skip to content

Commit

Permalink
remove option from version::get
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Sep 27, 2023
1 parent 2d2f866 commit d3be0ba
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 38 deletions.
14 changes: 5 additions & 9 deletions bin/src/config/project/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Options {
///
/// Returns an error if the version is not a valid semver version
/// or a points to a file that does not contain a valid version macro
pub fn get(&self, vfs: Option<&VfsPath>) -> Result<Version, Error> {
pub fn get(&self, vfs: &VfsPath) -> Result<Version, Error> {
// Check for a cached version
unsafe {
if INIT {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Options {
}
}

fn _get(&self, vfs: Option<&VfsPath>) -> Result<Version, Error> {
fn _get(&self, vfs: &VfsPath) -> Result<Version, Error> {
// Check for a defined major version
if let Some(major) = self.major {
trace!("reading version from project.toml");
Expand All @@ -89,16 +89,12 @@ impl Options {
} else {
version.replace('\\', "/")
};
let path = Path::new(&binding);
let path = vfs.join(binding)?;

// Check for a path to a version macro file
if path.exists() {
if path.exists()? {
trace!("checking for version macro in {:?}", path);
let content = if let Some(vfs) = vfs {
vfs.join(&binding)?.read_to_string()?
} else {
std::fs::read_to_string(path)?
};
let content = path.read_to_string()?;
return Version::try_from_script_version(&content).map_err(Into::into);
}
error!("could not find version macro file: {:?}", path);
Expand Down
42 changes: 22 additions & 20 deletions bin/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ impl Context {
if !path.exists() {
return Err(Error::ConfigNotFound);
}
let config = Configuration::from_file(&path)?;
let version = config.version().get(None);
if let Err(Error::Git(_)) = version {
error!("Failed to find a git repository with at least one commit, if you are not using git add the following to your project.toml");
println!("\n[version]\ngit_hash = 0\n");
std::process::exit(1);
};
info!("Config loaded for {} {}", config.name(), version?,);
config
Configuration::from_file(&path)?
};
let tmp = {
let mut tmp = temp_dir().join("hemtt");
Expand Down Expand Up @@ -65,20 +57,30 @@ impl Context {
remove_dir_all(&build_folder)?;
}
create_dir_all(&build_folder)?;
let workspace = {
let mut builder = Workspace::builder().physical(&root);
if cfg!(target_os = "windows") {
builder = builder.physical(&tmp.join("output"));
}
let include = root.join("include");
if include.is_dir() {
builder = builder.physical(&include);
}
builder.memory().finish()?
};
{
let version = config.version().get(workspace.vfs());
if let Err(Error::Git(_)) = version {
error!("Failed to find a git repository with at least one commit, if you are not using git add the following to your project.toml");
println!("\n[version]\ngit_hash = 0\n");
std::process::exit(1);
};
info!("Config loaded for {} {}", config.name(), version?,);
}
Ok(Self {
config,
folder: folder.to_owned(),
workspace: {
let mut builder = Workspace::builder().physical(&root);
if cfg!(target_os = "windows") {
builder = builder.physical(&tmp.join("output"));
}
let include = root.join("include");
if include.is_dir() {
builder = builder.physical(&include);
}
builder.memory().finish()?
},
workspace,
project_folder: root,
hemtt_folder,
out_folder: build_folder,
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn release(ctx: &Context) -> Result<(), Error> {
output.set_file_name(format!(
"{}-{}.zip",
ctx.config().prefix(),
ctx.config().version().get(Some(ctx.workspace().vfs()))?
ctx.config().version().get(ctx.workspace().vfs())?
));
info!("Created release: {}", output.display());
output
Expand Down
6 changes: 1 addition & 5 deletions bin/src/modules/hook/libraries/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ impl RhaiProject {
Self {
name: ctx.config().name().to_string(),
prefix: ctx.config().prefix().to_string(),
version: ctx
.config()
.version()
.get(Some(ctx.workspace().vfs()))
.unwrap(),
version: ctx.config().version().get(ctx.workspace().vfs()).unwrap(),
// addons: ctx.addons().to_vec(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod time;
pub fn scope(ctx: &Context, vfs: bool) -> Result<Scope, Error> {
let mut scope = Scope::new();
scope.push_constant("HEMTT_VERSION", env!("CARGO_PKG_VERSION"));
let version = ctx.config().version().get(Some(ctx.workspace().vfs()))?;
let version = ctx.config().version().get(ctx.workspace().vfs())?;
scope.push_constant("HEMTT_PROJECT_VERSION", version.to_string());
scope.push_constant("HEMTT_PROJECT_VERSION_MAJOR", version.major());
scope.push_constant("HEMTT_PROJECT_VERSION_MINOR", version.minor());
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/pbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Collapse {
}

pub fn build(ctx: &Context, collapse: Collapse) -> Result<(), Error> {
let version = ctx.config().version().get(Some(ctx.workspace().vfs()))?;
let version = ctx.config().version().get(ctx.workspace().vfs())?;
let git_hash = {
Repository::discover(".").map_or(None, |repo| {
repo.revparse_single("HEAD").map_or(None, |rev| {
Expand Down
2 changes: 1 addition & 1 deletion bin/src/modules/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn get_authority(ctx: &Context, suffix: Option<&str>) -> Result<String, Error> {
|| ctx.config().prefix().to_string(),
std::string::ToString::to_string
),
ctx.config().version().get(Some(ctx.workspace().vfs()))?
ctx.config().version().get(ctx.workspace().vfs())?
);
if let Some(suffix) = suffix {
authority.push_str(&format!("_{suffix}"));
Expand Down

0 comments on commit d3be0ba

Please sign in to comment.