Skip to content

Commit

Permalink
refactor ProjectId (#20)
Browse files Browse the repository at this point in the history
ProjectId::str now consume itself
ProjectId::from returns a Result

Also rename presubmit job from Generate to Tests
  • Loading branch information
rjodinchr authored Dec 3, 2024
1 parent 1f7bfc8 commit d039d40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
name: Generate
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ fn parse_args(

let mut project_ids: Vec<ProjectId> = Vec::new();
for arg in &args[required_args..] {
match ProjectId::from(arg) {
Some(project_id) => project_ids.push(project_id),
None => return error!(format!("Unknown project '{arg}'")),
};
project_ids.push(ProjectId::from(arg)?);
}
Ok((android_dir, ndk_dir, project_ids))
}
Expand Down
22 changes: 11 additions & 11 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ const SPIRV_HEADERS_NAME: &str = "SPIRV-Headers";
const SPIRV_TOOLS_NAME: &str = "SPIRV-Tools";

impl ProjectId {
pub fn from(str: &str) -> Option<ProjectId> {
match str {
CLVK_NAME => Some(ProjectId::Clvk),
CLSPV_NAME => Some(ProjectId::Clspv),
LLVM_PROJECT_NAME => Some(ProjectId::LlvmProject),
SPIRV_HEADERS_NAME => Some(ProjectId::SpirvHeaders),
SPIRV_TOOLS_NAME => Some(ProjectId::SpirvTools),
_ => None,
}
}
pub const fn str(&self) -> &'static str {
pub fn from(project: &str) -> Result<ProjectId, String> {
Ok(match project {
CLVK_NAME => ProjectId::Clvk,
CLSPV_NAME => ProjectId::Clspv,
LLVM_PROJECT_NAME => ProjectId::LlvmProject,
SPIRV_HEADERS_NAME => ProjectId::SpirvHeaders,
SPIRV_TOOLS_NAME => ProjectId::SpirvTools,
_ => return error!(format!("Unknown project '{project}'")),
})
}
pub const fn str(self) -> &'static str {
match self {
ProjectId::Clvk => CLVK_NAME,
ProjectId::Clspv => CLSPV_NAME,
Expand Down
6 changes: 2 additions & 4 deletions src/project/clvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ impl Project for Clvk {
fn get_gen_deps(&self, project: ProjectId) -> GenDepsMap {
let mut deps: GenDepsMap = HashMap::new();
let mut libs: HashSet<String> = HashSet::new();
let prefix = add_slash_suffix(project.str());
for library in &self.generated_libraries {
if let Some(lib) = self
.get_library_name(library)
.strip_prefix(&add_slash_suffix(project.str()))
{
if let Some(lib) = self.get_library_name(library).strip_prefix(&prefix) {
libs.insert(lib.to_string());
}
}
Expand Down

0 comments on commit d039d40

Please sign in to comment.