diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..5e9a51e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,54 @@ +use std::env::{current_dir, set_current_dir}; +use std::fs::{create_dir_all, metadata}; +use std::path::Path; +use std::process::Command; + +use clang::{Clang, Index}; + +const TARGET_TAG: &str = "v3.1.5"; + +fn main() { + assert_eq!(current_dir().unwrap(), Path::new(env!("CARGO_MANIFEST_DIR")), "running in the wrong place"); + create_dir_all("out").unwrap(); + set_current_dir("out").unwrap(); + + if metadata("orig").is_err() { + println!("cloning wxWidgets source..."); + let git_clone = Command::new("git") + .args(&["clone", "--quiet", "https://github.com/wxWidgets/wxWidgets.git", "orig", "--depth", "1"]) + .status() + .unwrap(); + assert!(git_clone.success()); + let git_config = Command::new("git") + .args(&["-C", "orig", "config", "--local", "advice.detachedHead", "false"]) + .status() + .unwrap(); + assert!(git_config.success()); + } + let git_tag = Command::new("git").args(&["-C", "orig", "describe"]).output().unwrap(); + if String::from_utf8(git_tag.stdout).unwrap().trim() != TARGET_TAG { + let git_checkout = Command::new("git") + .args(&["-C", "orig", "checkout", "--quiet", TARGET_TAG]) + .status() + .unwrap(); + assert!(git_checkout.success()); + } + + if metadata("new").is_err() { + println!("creating wx crate..."); + let cargo_new = Command::new("cargo") + .args(&["new", "--quiet", "--vcs", "none", "--lib", "--name", "wx", "new"]) + .status() + .unwrap(); + assert!(cargo_new.success()); + } + + let clang = Clang::new().unwrap(); + let index = Index::new(&clang, true, true); + + let mut root_header_parser = index.parser("orig/include/wx/wx.h"); + root_header_parser.keep_going(true); + root_header_parser.arguments(&["-Iorig/include", "-D"]); + let root_header = root_header_parser.parse().unwrap(); + println!("{}", root_header.get_entity().get_pretty_printer().print()); +} |