[PATCH 1/4] scripts/make_fit: factor dtb file name into configuration name

Uwe Kleine-König uwe at kleine-koenig.org
Tue Mar 18 04:33:30 PDT 2025


Hello,

On Tue, Mar 18, 2025 at 12:27:26PM +0100, Ahmad Fatoum wrote:
> Hello Uwe,
> 
> On 3/18/25 12:03, Uwe Kleine-König wrote:
> > On Tue, Mar 18, 2025 at 09:25:04AM +0100, Ahmad Fatoum wrote:
> >>      fsw.end_node()
> >> -    seq = 0
> >>      with fsw.add_node('configurations'):
> >> -        for model, compat, files in entries:
> >> -            seq += 1
> >> -            with fsw.add_node(f'conf-{seq}'):
> >> +        for dtbname, model, compat, files in entries:
> >> +            with fsw.add_node(f'conf-{dtbname}'):
> > 
> > Funny/surprising semantic of fsw.add_node (i.e. fsw refers to the new
> > node in the with-body?)
> 
> Yes. I suspect it's to ensure that a node end tag is inserted
> after the properties.
> 
> >> -        entries.append([model, compat, files_seq])
> >> +        dtbname = os.path.basename(fname)
> >> +        ndtbs_seen = len(dtbs_seen)
> >> +        dtbs_seen.add(dtbname)
> >> +        if len(dtbs_seen) == ndtbs_seen:
> >> +            raise RuntimeError(f"Duplicate file name '{dtbname}' during FIT creation")
> >> +
> >> +        entries.append([dtbname, model, compat, files_seq])
> > 
> > 	dtbname = os.path.basename(fname)
> > 	if dtbname in dtbs_seen:
> > 	    raise RuntimeError(...)
> > 	dtbs_seen.add(dtbname)
> > 	entries.append(...)
> > 
> > looks more pythonic (to me).
> 
> I dislike iterating twice over the dtbs. I wrote it this way,
> because I assumed calling len on the set is O(1).

I would expect that both `dtbname in dtbs_seen` and
`dtbs_seen.add(dtbname)` is O(1) (in the absense of hash collisions).

Best regards
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20250318/aa22902b/attachment-0001.sig>


More information about the barebox mailing list