Skip to content

Commit 5d7d736

Browse files
committed
rust: add validation of Python platform tag
This required teaching our code to parse the JSON file. There are currently some failures due to a regression on macOS builds.
1 parent 167c978 commit 5d7d736

File tree

4 files changed

+225
-40
lines changed

4 files changed

+225
-40
lines changed

Cargo.lock

Lines changed: 76 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ clap = "2.33"
1010
goblin = "0.3"
1111
lazy_static = "1.4"
1212
scroll = "0.10"
13+
serde_json = "1.0"
14+
serde = { version = "1.0", features = ["derive"] }
1315
tar = "0.4"
1416
version-compare = "0.0.11"
1517
zstd = "0.6"

src/json.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)