@@ -46,6 +46,14 @@ BLOCK_PAYLOADS = 2
4646
4747CONTENTS_FILE = '_contents_.yaml'
4848
49+ # Must be kept up to date with new payload types
50+ KNOWN_PAYLOAD_TYPES = ('image-sparse' , 'script' , 'tmpfile' , 'eeprom-ab' )
51+
52+ # The final artefact is already zstd-compressed as a whole, so an
53+ # individually-compressed payload (e.g. 'boot.sparse.zst' instead of
54+ # 'boot.sparse') is almost always a mistake.
55+ COMPRESSED_SUFFIXES = ('.zst' , '.gz' , '.bz2' , '.xz' , '.lz4' , '.tgz' , '.tzst' )
56+
4957def main ():
5058 parser = argparse .ArgumentParser ()
5159 parser .add_argument ('contents' ,
@@ -72,6 +80,7 @@ def main():
7280 payloads = [CONTENTS_FILE ]
7381 outfile = args .outfile
7482 errors = 0
83+ current_payload = {}
7584
7685 with tempfile .TemporaryDirectory () as tmpdir :
7786 for raw_line in lines :
@@ -100,9 +109,11 @@ def main():
100109 # Normalise list item: '- name: x' -> ' name: x'
101110 payload_line = re .sub (r'^\s*-\s*' , ' ' , line )
102111 name_m = re .match (r'^\s+name:\s*(.+)$' , payload_line )
112+ type_m = re .match (r'^\s+type:\s*(.+)$' , payload_line )
103113 if name_m :
104114 name = name_m .group (1 ).strip ()
105115 target = (comment if comment is not None else name ).strip ()
116+ current_payload = {'name' : name , 'target' : target }
106117 src = os .path .join (cwd , target )
107118 dst = os .path .join (tmpdir , name )
108119 if not os .path .isfile (src ) and not os .path .islink (src ) and not os .path .isdir (src ):
@@ -120,6 +131,18 @@ def main():
120131 else :
121132 print (f'* error: cannot symlink { target } ' )
122133 errors += 1
134+ elif type_m :
135+ ptype = type_m .group (1 ).strip ()
136+ pname = current_payload .get ('name' , '?' )
137+ target = current_payload .get ('target' , pname )
138+ if ptype not in KNOWN_PAYLOAD_TYPES :
139+ print (f"* error: payload '{ pname } ' has unknown type '{ ptype } ' "
140+ f"(expected one of: { ', ' .join (KNOWN_PAYLOAD_TYPES )} )" )
141+ errors += 1
142+ if ptype != "tmpfile" and target .endswith (COMPRESSED_SUFFIXES ):
143+ print (f"* warning: payload '{ pname } ' file '{ target } ' looks pre-compressed; "
144+ f"the artefact is already compressed as a whole, "
145+ f"did you mean '{ re .sub (r'(?:' + '|' .join (re .escape (s ) for s in COMPRESSED_SUFFIXES )+ r')$' , '' , target )} '?" )
123146
124147 if errors :
125148 sys .exit (1 )
0 commit comments