Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "riddle" and metadata generation #3266

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
run: cargo clippy -p cppwinrt
- name: Clippy helpers
run: cargo clippy -p helpers
- name: Clippy riddle
run: cargo clippy -p riddle
- name: Clippy sample_bits
run: cargo clippy -p sample_bits
- name: Clippy sample_com_uri
Expand Down Expand Up @@ -239,8 +237,6 @@ jobs:
run: cargo clippy -p test_return_handle
- name: Clippy test_return_struct
run: cargo clippy -p test_return_struct
- name: Clippy test_riddle
run: cargo clippy -p test_riddle
- name: Clippy test_standalone
run: cargo clippy -p test_standalone
- name: Clippy test_string_param
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ jobs:
run: cargo test -p cppwinrt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test helpers
run: cargo test -p helpers --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test riddle
run: cargo test -p riddle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_bits
run: cargo test -p sample_bits --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_com_uri
Expand Down Expand Up @@ -153,10 +151,10 @@ jobs:
run: cargo test -p test_agile_reference --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_alternate_success_code
run: cargo test -p test_alternate_success_code --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_arch
run: cargo test -p test_arch --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_array
Expand Down Expand Up @@ -255,10 +253,10 @@ jobs:
run: cargo test -p test_registry --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_registry_default
run: cargo test -p test_registry_default --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_reserved
run: cargo test -p test_reserved --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_resources
run: cargo test -p test_resources --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_result
Expand All @@ -267,8 +265,6 @@ jobs:
run: cargo test -p test_return_handle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_return_struct
run: cargo test -p test_return_struct --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_riddle
run: cargo test -p test_riddle --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_standalone
run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_string_param
Expand Down
57 changes: 2 additions & 55 deletions crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
mod args;
mod error;
mod metadata;
mod rdl;
mod rust;
mod tokens;
mod tree;
mod winmd;

pub use error::{Error, Result};
use tree::Tree;
Expand Down Expand Up @@ -35,7 +33,6 @@ where
let mut include = Vec::<&str>::new();
let mut exclude = Vec::<&str>::new();
let mut config = std::collections::BTreeMap::<&str, &str>::new();
let mut format = false;

for arg in &args {
if arg.starts_with('-') {
Expand All @@ -48,7 +45,6 @@ where
"-o" | "--out" => kind = ArgKind::Output,
"-f" | "--filter" => kind = ArgKind::Filter,
"--config" => kind = ArgKind::Config,
"--format" => format = true,
_ => return Err(Error::new(&format!("invalid option `{arg}`"))),
},
ArgKind::Output => {
Expand Down Expand Up @@ -76,29 +72,6 @@ where
}
}

if format {
if output.is_some() || !include.is_empty() || !exclude.is_empty() {
return Err(Error::new(
"`--format` cannot be combined with `--out` or `--filter`",
));
}

let input = filter_input(&input, &["rdl"])?;

if input.is_empty() {
return Err(Error::new("no .rdl inputs"));
}

for path in &input {
read_file_text(path)
.and_then(|source| rdl::File::parse_str(&source))
.and_then(|file| write_to_file(path, file.fmt()))
.map_err(|err| err.with_path(path))?;
}

return Ok(String::new());
}

let Some(output) = output else {
return Err(Error::new("no output"));
};
Expand All @@ -115,10 +88,8 @@ where
let reader = metadata::Reader::filter(input, &include, &exclude, &config);

match extension(&output) {
"rdl" => rdl::from_reader(reader, config, &output)?,
"winmd" => winmd::from_reader(reader, config, &output)?,
"rs" => rust::from_reader(reader, config, &output)?,
_ => return Err(Error::new("output extension must be one of winmd/rdl/rs")),
_ => return Err(Error::new("output extension must be one of `rs`")),
}

let elapsed = time.elapsed().as_secs_f32();
Expand Down Expand Up @@ -195,22 +166,12 @@ fn read_input(input: &[&str]) -> Result<Vec<metadata::File>> {
}

for input in &input {
let file = if extension(input) == "winmd" {
read_winmd_file(input)?
} else {
read_rdl_file(input)?
};

results.push(file);
results.push(read_winmd_file(input)?);
}

Ok(results)
}

fn read_file_text(path: &str) -> Result<String> {
std::fs::read_to_string(path).map_err(|_| Error::new("failed to read text file"))
}

fn read_file_bytes(path: &str) -> Result<Vec<u8>> {
std::fs::read(path).map_err(|_| Error::new("failed to read binary file"))
}
Expand All @@ -228,20 +189,6 @@ fn read_file_lines(path: &str) -> Result<Vec<String>> {
Ok(lines)
}

fn read_rdl_file(path: &str) -> Result<metadata::File> {
read_file_text(path)
.and_then(|source| rdl::File::parse_str(&source))
.and_then(|file| file.into_winmd())
.map(|bytes| {
// TODO: Write bytes to file if you need to debug the intermediate .winmd file like so:
_ = write_to_file("temp.winmd", &bytes);

// Unwrapping here is fine since `rdl_to_winmd` should have produced a valid winmd
metadata::File::new(bytes).unwrap()
})
.map_err(|err| err.with_path(path))
}

fn read_winmd_file(path: &str) -> Result<metadata::File> {
read_file_bytes(path).and_then(|bytes| {
metadata::File::new(bytes)
Expand Down
Loading