13
13
from collections import defaultdict
14
14
from west .manifest import Manifest
15
15
from west .manifest import ManifestProject
16
+ from git import Repo
17
+ from pathlib import Path
16
18
17
19
TOP_DIR = os .path .join (os .path .dirname (__file__ ))
18
20
sys .path .insert (0 , os .path .join (TOP_DIR , "scripts" ))
19
21
from get_maintainer import Maintainers
20
22
23
+ zephyr_base = os .getenv ('ZEPHYR_BASE' , os .path .join (TOP_DIR , '..' ))
24
+
21
25
def log (s ):
22
26
if args .verbose > 0 :
23
27
print (s , file = sys .stdout )
@@ -50,11 +54,46 @@ def parse_args():
50
54
parser .add_argument ("-r" , "--repo" , default = "zephyr" ,
51
55
help = "Github repository" )
52
56
57
+ parser .add_argument ("-c" , "--commits" , default = None ,
58
+ help = "Commit range in the form: a..b" )
59
+
53
60
parser .add_argument ("-v" , "--verbose" , action = "count" , default = 0 ,
54
61
help = "Verbose Output" )
55
62
56
63
args = parser .parse_args ()
57
64
65
+
66
+ def process_manifest ():
67
+ repo = Repo (zephyr_base )
68
+ old_manifest_content = repo .git .show (f"{ args .commits [:- 2 ]} :west.yml" )
69
+ with open ("west_old.yml" , "w" ) as manifest :
70
+ manifest .write (old_manifest_content )
71
+ old_manifest = Manifest .from_file ("west_old.yml" )
72
+ new_manifest = Manifest .from_file ("west.yml" )
73
+ old_projs = set ((p .name , p .revision ) for p in old_manifest .projects )
74
+ new_projs = set ((p .name , p .revision ) for p in new_manifest .projects )
75
+ # Removed projects
76
+ rprojs = set (filter (lambda p : p [0 ] not in list (p [0 ] for p in new_projs ),
77
+ old_projs - new_projs ))
78
+ # Updated projects
79
+ uprojs = set (filter (lambda p : p [0 ] in list (p [0 ] for p in old_projs ),
80
+ new_projs - old_projs ))
81
+ # Added projects
82
+ aprojs = new_projs - old_projs - uprojs
83
+
84
+ # All projs
85
+ projs = rprojs | uprojs | aprojs
86
+ projs_names = [name for name , rev in projs ]
87
+
88
+ if not projs_names :
89
+ return
90
+ areas = []
91
+ for p in projs_names :
92
+ areas .append (f'West project: { p } ' )
93
+
94
+ log (f'manifest areas: { areas } ' )
95
+ return areas
96
+
58
97
def process_pr (gh , maintainer_file , number ):
59
98
60
99
gh_repo = gh .get_repo (f"{ args .org } /{ args .repo } " )
@@ -70,10 +109,6 @@ def process_pr(gh, maintainer_file, number):
70
109
all_areas = set ()
71
110
fn = list (pr .get_files ())
72
111
73
- for changed_file in fn :
74
- if changed_file .filename in ['west.yml' ,'submanifests/optional.yaml' ]:
75
- break
76
-
77
112
if pr .commits == 1 and (pr .additions <= 1 and pr .deletions <= 1 ):
78
113
labels = {'size: XS' }
79
114
@@ -84,7 +119,16 @@ def process_pr(gh, maintainer_file, number):
84
119
for changed_file in fn :
85
120
num_files += 1
86
121
log (f"file: { changed_file .filename } " )
87
- areas = maintainer_file .path2areas (changed_file .filename )
122
+
123
+ areas = []
124
+ if changed_file .filename in ['west.yml' ,'submanifests/optional.yaml' ]:
125
+ changed_areas = process_manifest ()
126
+ for _area in changed_areas :
127
+ area_match = maintainer_file .name2areas (_area )
128
+ if area_match :
129
+ areas .extend (area_match )
130
+ else :
131
+ areas = maintainer_file .path2areas (changed_file .filename )
88
132
89
133
if not areas :
90
134
continue
0 commit comments