forked from s3s-project/s3s
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
106 lines (84 loc) · 2.44 KB
/
mod.rs
File metadata and controls
106 lines (84 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
mod rust;
mod smithy;
mod utils;
mod access;
mod dto;
mod error;
mod headers;
mod minio;
mod ops;
mod order;
mod s3_trait;
mod sts;
mod xml;
mod aws_conv;
mod aws_proxy;
use std::fs::File;
use std::io::BufWriter;
pub use self::utils::o;
fn write_file(path: &str, f: impl FnOnce()) {
let mut writer = BufWriter::new(File::create(path).unwrap());
scoped_writer::scoped(&mut writer, f);
}
#[derive(Debug, Clone, Copy)]
enum Patch {
Minio,
}
pub fn run() {
inner_run(None);
inner_run(Some(Patch::Minio));
}
fn inner_run(code_patch: Option<Patch>) {
let model = {
let mut s3_model = smithy::Model::load_json("data/s3.json").unwrap();
let mut sts_model = smithy::Model::load_json("data/sts.json").unwrap();
sts::reduce(&mut sts_model);
s3_model.shapes.append(&mut sts_model.shapes);
if matches!(code_patch, Some(Patch::Minio)) {
minio::patch(&mut s3_model);
}
s3_model
};
let ops = ops::collect_operations(&model);
let rust_types = dto::collect_rust_types(&model, &ops);
let suffix = match code_patch {
Some(Patch::Minio) => "_minio",
None => "",
};
{
let path = format!("crates/s3s/src/dto/generated{suffix}.rs");
write_file(&path, || dto::codegen(&rust_types, &ops, code_patch));
}
{
let path = format!("crates/s3s/src/header/generated{suffix}.rs");
write_file(&path, || headers::codegen(&model));
}
{
let path = format!("crates/s3s/src/error/generated{suffix}.rs");
write_file(&path, || error::codegen(&model));
}
{
let path = format!("crates/s3s/src/xml/generated{suffix}.rs");
write_file(&path, || xml::codegen(&ops, &rust_types));
}
{
let path = "crates/s3s/src/s3_trait.rs";
write_file(path, || s3_trait::codegen(&ops));
}
{
let path = format!("crates/s3s/src/ops/generated{suffix}.rs");
write_file(&path, || ops::codegen(&ops, &rust_types));
}
{
let path = format!("crates/s3s/src/access/generated{suffix}.rs");
write_file(&path, || access::codegen(&ops));
}
{
let path = format!("crates/s3s-aws/src/conv/generated{suffix}.rs");
write_file(&path, || aws_conv::codegen(&ops, &rust_types));
}
{
let path = format!("crates/s3s-aws/src/proxy/generated{suffix}.rs");
write_file(&path, || aws_proxy::codegen(&ops, &rust_types));
}
}