|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +use { |
| 6 | + anyhow::Result, |
| 7 | + serde::Deserialize, |
| 8 | + std::collections::{BTreeMap, HashMap}, |
| 9 | +}; |
| 10 | + |
| 11 | +#[derive(Debug, Deserialize)] |
| 12 | +pub struct LinkEntry { |
| 13 | + pub name: String, |
| 14 | + pub path_static: Option<String>, |
| 15 | + pub path_dynamic: Option<String>, |
| 16 | + pub framework: Option<bool>, |
| 17 | + pub system: Option<bool>, |
| 18 | +} |
| 19 | + |
| 20 | +#[derive(Debug, Deserialize)] |
| 21 | +pub struct PythonBuildExtensionInfo { |
| 22 | + pub in_core: bool, |
| 23 | + pub init_fn: String, |
| 24 | + pub licenses: Option<Vec<String>>, |
| 25 | + pub license_paths: Option<Vec<String>>, |
| 26 | + pub license_public_domain: Option<bool>, |
| 27 | + pub links: Vec<LinkEntry>, |
| 28 | + pub objs: Vec<String>, |
| 29 | + pub required: bool, |
| 30 | + pub static_lib: Option<String>, |
| 31 | + pub shared_lib: Option<String>, |
| 32 | + pub variant: String, |
| 33 | +} |
| 34 | + |
| 35 | +#[derive(Debug, Deserialize)] |
| 36 | +pub struct PythonBuildCoreInfo { |
| 37 | + pub objs: Vec<String>, |
| 38 | + pub links: Vec<LinkEntry>, |
| 39 | + pub shared_lib: Option<String>, |
| 40 | + pub static_lib: Option<String>, |
| 41 | +} |
| 42 | + |
| 43 | +#[derive(Debug, Deserialize)] |
| 44 | +pub struct PythonBuildInfo { |
| 45 | + pub core: PythonBuildCoreInfo, |
| 46 | + pub extensions: BTreeMap<String, Vec<PythonBuildExtensionInfo>>, |
| 47 | + pub inittab_object: String, |
| 48 | + pub inittab_source: String, |
| 49 | + pub inittab_cflags: Vec<String>, |
| 50 | + pub object_file_format: String, |
| 51 | +} |
| 52 | + |
| 53 | +#[derive(Debug, Deserialize)] |
| 54 | +pub struct PythonJsonMain { |
| 55 | + pub version: String, |
| 56 | + pub target_triple: String, |
| 57 | + pub optimizations: String, |
| 58 | + pub python_tag: String, |
| 59 | + pub python_abi_tag: Option<String>, |
| 60 | + pub python_config_vars: HashMap<String, String>, |
| 61 | + pub python_platform_tag: String, |
| 62 | + pub python_implementation_cache_tag: String, |
| 63 | + pub python_implementation_hex_version: u64, |
| 64 | + pub python_implementation_name: String, |
| 65 | + pub python_implementation_version: Vec<String>, |
| 66 | + pub python_version: String, |
| 67 | + pub python_major_minor_version: String, |
| 68 | + pub python_paths: HashMap<String, String>, |
| 69 | + pub python_paths_abstract: HashMap<String, String>, |
| 70 | + pub python_exe: String, |
| 71 | + pub python_stdlib_test_packages: Vec<String>, |
| 72 | + pub python_suffixes: HashMap<String, Vec<String>>, |
| 73 | + pub python_bytecode_magic_number: String, |
| 74 | + pub python_symbol_visibility: String, |
| 75 | + pub python_extension_module_loading: Vec<String>, |
| 76 | + pub libpython_link_mode: String, |
| 77 | + pub crt_features: Vec<String>, |
| 78 | + pub run_tests: String, |
| 79 | + pub build_info: PythonBuildInfo, |
| 80 | + pub licenses: Option<Vec<String>>, |
| 81 | + pub license_path: Option<String>, |
| 82 | + pub tcl_library_path: Option<String>, |
| 83 | + pub tcl_library_paths: Option<Vec<String>>, |
| 84 | +} |
| 85 | + |
| 86 | +pub fn parse_python_json(json_data: &[u8]) -> Result<PythonJsonMain> { |
| 87 | + let v: PythonJsonMain = serde_json::from_slice(&json_data)?; |
| 88 | + |
| 89 | + Ok(v) |
| 90 | +} |
0 commit comments