Skip to content

Commit

Permalink
tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Nov 16, 2023
1 parent 4e79cc7 commit 3ffbfc7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
cargo clippy -p test_core &&
cargo clippy -p test_debug &&
cargo clippy -p test_debug_inspectable &&
cargo clippy -p test_debugger_visualizer_x &&
cargo clippy -p test_debugger_visualizer &&
cargo clippy -p test_deprecated &&
cargo clippy -p test_dispatch &&
cargo clippy -p test_does_not_return &&
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ jobs:
cargo test -p test_core &&
cargo test -p test_debug &&
cargo test -p test_debug_inspectable &&
cargo test -p test_debugger_visualizer &&
cargo test -p test_deprecated &&
cargo test -p test_dispatch &&
cargo test -p test_does_not_return &&
cargo test -p test_enums &&
cargo test -p test_error &&
cargo test -p test_event &&
cargo test -p test_extensions &&
cargo clean &&
cargo test -p test_extensions &&
cargo test -p test_handles &&
cargo test -p test_helpers &&
cargo test -p test_implement &&
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/debugger_visualizer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "test_debugger_visualizer_x"
name = "test_debugger_visualizer"
version = "0.0.0"
edition = "2021"
publish = false
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/targets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ features = [ "Win32_Foundation", "Win32_Security_Authentication_Identity" ]
[dependencies.windows-sys]
path = "../../libs/sys"
features = [ "Win32_Foundation", "Win32_Security_Authentication_Identity" ]

[dependencies.tool_lib]
path = "../../tools/lib"
4 changes: 4 additions & 0 deletions crates/tests/targets/tests/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#[test]
fn test() {
let targets = tool_lib::crates("../../targets");
assert_eq!(7, targets.len());
assert!(targets.iter().all(|(_, version)| version == "0.52.0"));

std::include_bytes!("../../../targets/aarch64_gnullvm/lib/libwindows.0.52.0.a");
std::include_bytes!("../../../targets/aarch64_msvc/lib/windows.0.52.0.lib");
std::include_bytes!("../../../targets/i686_gnu/lib/libwindows.0.52.0.a");
Expand Down
1 change: 1 addition & 0 deletions crates/tools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ edition = "2021"
publish = false

[dependencies]
regex = "1.7"
metadata = { package = "windows-metadata", path = "../../libs/metadata" }
37 changes: 37 additions & 0 deletions crates/tools/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::BTreeMap;
use regex::Regex;
use std::path::Path;

pub enum CallingConvention {
Stdcall(usize),
Expand Down Expand Up @@ -82,3 +84,38 @@ fn combine_libraries(
}
}
}

pub fn crates<P: AsRef<Path>>(path: P) -> Vec<(String, String)> {
let regex = Regex::new(r#"name = "([^"]+)"\sversion = "([^"]+)""#).expect("regex");
let mut names = find(path, &regex);
names.sort();
names
}

fn find<P: AsRef<Path>>(path: P, regex: &Regex) -> Vec<(String, String)> {
let mut names = vec![];

if let Ok(files) = std::fs::read_dir(path) {
for file in files.filter_map(|file| file.ok()) {
if let Ok(file_type) = file.file_type() {
if file_type.is_dir() {
names.append(&mut find(file.path(), regex));
} else if file.file_name() == "Cargo.toml" {
let text = std::fs::read_to_string(file.path()).expect("Cargo.toml");
let captures = regex
.captures(&text)
.expect("captures");
let name = captures
.get(1)
.expect("name");
let version = captures
.get(2)
.expect("version");
names.push((name.as_str().to_string(), version.as_str().to_string()));
}
}
}
}

names
}
2 changes: 1 addition & 1 deletion crates/tools/yml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2021"
publish = false

[dependencies]
regex = "1.7"
lib = { package = "tool_lib", path = "../lib" }
43 changes: 4 additions & 39 deletions crates/tools/yml/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use regex::Regex;
use std::fmt::Write;
use std::path::Path;

fn main() {
test_yml();
Expand Down Expand Up @@ -53,16 +51,16 @@ jobs:
run: >"
.to_string();

let crates = crates(true);
let crates = lib::crates("crates");
let (first, last) = crates.split_at(crates.len() / 2);

for name in first {
for (name, _) in first {
write!(&mut yml, "\n cargo test -p {name} &&").unwrap();
}

write!(&mut yml, "\n cargo clean &&").unwrap();

for name in last {
for (name, _) in last {
write!(&mut yml, "\n cargo test -p {name} &&").unwrap();
}

Expand Down Expand Up @@ -109,43 +107,10 @@ jobs:
run: |"#
.to_string();

for name in crates(false) {
for (name, _) in lib::crates("crates") {
write!(&mut yml, "\n cargo clippy -p {name} &&").unwrap();
}

yml.truncate(yml.len() - 3);
std::fs::write(".github/workflows/clippy.yml", yml.as_bytes()).unwrap();
}

fn crates(filter: bool) -> Vec<String> {
let regex = Regex::new(r#"name = "([^"]+)""#).expect("regex");
let mut names = find("crates", &regex, filter);
names.sort();
names
}

fn find<P: AsRef<Path>>(path: P, regex: &Regex, filter: bool) -> Vec<String> {
let mut names = vec![];

if let Ok(files) = std::fs::read_dir(path) {
for file in files.filter_map(|file| file.ok()) {
if let Ok(file_type) = file.file_type() {
if file_type.is_dir() {
names.append(&mut find(file.path(), regex, filter));
} else if file.file_name() == "Cargo.toml" {
let text = std::fs::read_to_string(file.path()).expect("Cargo.toml");
let name = regex
.captures(&text)
.expect("captures")
.get(1)
.expect("name");
if !filter || !name.as_str().ends_with("_x") {
names.push(name.as_str().to_string());
}
}
}
}
}

names
}

0 comments on commit 3ffbfc7

Please sign in to comment.