16
16
17
17
import argparse
18
18
import json
19
+ import platform
20
+ from collections import defaultdict
19
21
20
22
_LIST_OF_PACKAGES_TO_EXCLUDE = ['fuchsia/third_party/rust/' ]
21
23
@@ -32,12 +34,27 @@ def include_package(package: dict) -> bool:
32
34
return True
33
35
34
36
35
- def generate_new_cipd_package_json (input , output ):
37
+ def generate_new_cipd_package_json (input , output , extra ):
36
38
with open (input ) as ins :
37
39
packages = json .load (ins )
40
+
38
41
file_packages = packages .get ('packages' )
39
42
new_file_packages = [x for x in file_packages if include_package (x )]
40
43
44
+ # Extra is a list of platform:json.
45
+ # Filter it for the given platform and append any resulting packages
46
+ my_platform = platform .system ().lower ()
47
+ for item in extra :
48
+ inject_platform , path = item .split (':' , 1 )
49
+
50
+ if inject_platform .lower () != my_platform :
51
+ continue
52
+
53
+ with open (path ) as ins :
54
+ for package in json .load (ins ).get ('packages' ):
55
+ new_file_packages .append (package )
56
+
57
+
41
58
new_packages = {'packages' : new_file_packages }
42
59
with open (output , 'w' ) as f :
43
60
json .dump (new_packages , f , indent = 2 )
@@ -54,6 +71,11 @@ def main():
54
71
parser .add_argument (
55
72
'--output' , '-o' , required = True
56
73
)
74
+ parser .add_argument (
75
+ '--extra' , '-e' , nargs = '*' , default = [],
76
+ help = "Inject extra packages for specific platforms. Format is <platform>:<path_to_json>"
77
+ )
78
+
57
79
generate_new_cipd_package_json (** vars (parser .parse_args ()))
58
80
59
81
0 commit comments