From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 10/19] support: rewrite check-bin-arch in python
Date: Tue, 8 Jan 2019 17:37:52 +0100 [thread overview]
Message-ID: <20190108163752.GK19623@scaer> (raw)
In-Reply-To: <CAAXf6LWfY8QkcveMUUgBKjBa+2TnRDoG-nHUXo7eiSZ=R7cfyQ@mail.gmail.com>
On 2019-01-08 15:56 +0100, Thomas De Schampheleire spake thusly:
> El lun., 7 ene. 2019 a las 23:05, Yann E. MORIN
> (<yann.morin.1998@free.fr>) escribi?:
[--SNIP--]
> > Rewrite that script in python.
[--SNIP--]
> > +def main():
> > + parser = argparse.ArgumentParser()
> > + parser.add_argument('--package', '-p', metavar='PACKAGE', required=True)
> > + parser.add_argument('--pkg-list', '-l', metavar='PKG_LIST', required=True)
> > + parser.add_argument('--readelf', '-r', metavar='READELF', required=True)
> > + parser.add_argument('--arch', '-a', metavar='ARCH', required=True)
> > + parser.add_argument('--ignore', '-i', metavar='PATH', action='append')
> I think the above 'metavar' options are not necessary, as they are the
> default value.
I'll check and drop if they indeed are not.
> > + args = parser.parse_args()
> > +
> > + if args.ignore is not None:
> > + # Ensure we do have single '/' as separators, and that we have a
> > + # leading and a trailing one, then append to the global list.
> > + for pattern in args.ignore:
> > + IGNORES.add(re.sub('/+', '/', '/{0}/'.format(pattern)))
> Note that the global list itself does not have trailing slashes. This
> seems inconsistent to me.
It is inconsistent, but I kept the existing behaviour intact as much as
possible, so the python script is a drop-in replacement for the shjell
script, with the same semantics.
> > + ignores_re = set()
> > + for i in IGNORES:
> > + ignores_re.add(re.compile(i))
> > +
> > + arch_re = re.compile('^ Machine: +(.+)')
> > +
> > + target_dir = os.environ['TARGET_DIR']
> > +
> > + exit_code = 0
> > + for record in parse_pkg_file_list(args.pkg_list):
> > + if record['pkg'] != args.package:
> > + continue
> > +
> > + fpath = record['file']
> > +
> > + ignored = False
> > + for i in ignores_re:
> > + if i.match(fpath):
> > + ignored = True
> > + break
> > + if ignored:
> > + continue
>
> We can never get into this if, right?, because there is already a
> break whenever ignored is set to True.
Yes we can, because the break only applied to the inner-most loop, which
is the one that iterates over the ignores regexps.
> Note that I think that performance will be better with a list
> comprehension instead of explicit for's. Something like (untested):
>
> valid_records = [ record for record in parse_pkg_file_list(args.pkg_list)
> if record['pkg'] == args.package
> and not any(ignore_re.match(record['file']) for ignore_re
> in ignores_re) ]
Sorry, but this is totally illegible to me.
> for record in valid_records:
> ...
>
>
> You can normally swap the [ ] for ( ) to reduce memory consumption
> (generator iso list comprehension, yielding one entry at a time).
>
> You can argue about readability, but for me this is not less readable
> than the expanded version.
Well, for me your version is totally unredable, sorry... :-/
The one I wrote at least clearly describes what it is doing:
- for each record in the list:
- check if the package is the one we're looking at, if not continue to
next record
- for each regecp to ignore, check if the filename matches it, and
if one is matched, memorizre the fact and break the loop (fast-path).
- if the file is to be ignored, continue to the next record
and so on...
The size argument is moot IMO, because we do not have thousands of
regexps to ignore, and the parse_pkg_file_list() already yields its
results.
Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
next prev parent reply other threads:[~2019-01-08 16:37 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 22:05 [Buildroot] [PATCH 00/19] support: limit install-time instrumentation to current package's files (branch yem/files-list-2) Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 01/19] infra/pkg-generic: display MESSAGE before running PRE_HOOKS Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 02/19] infra/pkg-generic: create $(@D) " Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 03/19] infra/pkg-generic: introduce new stampfile at the beginning of all steps Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 04/19] infra/pkg-generic: use \0 to separate .la files as they are found Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 05/19] infra/pkg-generic: tweak only .la files installed by the current package Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 06/19] infra/pkg-generic: only list " Yann E. MORIN
2019-01-08 13:07 ` Thomas De Schampheleire
2019-01-08 15:56 ` Thomas De Schampheleire
2019-01-08 19:51 ` Yann E. MORIN
2019-01-08 16:08 ` Yann E. MORIN
2019-01-08 16:55 ` Thomas De Schampheleire
2019-01-08 20:02 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 07/19] infra/pkg-generic: offload same-package filtering to check-uniq-file Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 08/19] support/check-uniq-files: decode as many strings as possible Yann E. MORIN
2019-02-07 23:40 ` Arnout Vandecappelle
2019-02-08 17:25 ` Yann E. MORIN
2019-02-08 20:42 ` Arnout Vandecappelle
2019-02-08 21:22 ` Yann E. MORIN
2019-02-08 22:02 ` Arnout Vandecappelle
2019-01-07 22:05 ` [Buildroot] [PATCH 09/19] support: add parser in python for packages-file-list files Yann E. MORIN
2019-01-08 13:35 ` Thomas De Schampheleire
2019-01-08 16:29 ` Yann E. MORIN
2019-01-08 17:30 ` Thomas De Schampheleire
2019-01-08 20:52 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 10/19] support: rewrite check-bin-arch in python Yann E. MORIN
2019-01-08 14:56 ` Thomas De Schampheleire
2019-01-08 16:37 ` Yann E. MORIN [this message]
2019-01-08 17:22 ` Thomas De Schampheleire
2019-01-08 20:33 ` Yann E. MORIN
2019-01-08 20:46 ` Thomas De Schampheleire
2019-01-08 21:16 ` Yann E. MORIN
2019-01-09 14:47 ` Thomas De Schampheleire
2019-01-07 22:05 ` [Buildroot] [PATCH 11/19] support: introduce new format for packages-file-list files Yann E. MORIN
2019-01-08 15:07 ` Thomas De Schampheleire
2019-01-08 19:27 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 12/19] infra/pkg-generic: store md5 of just-installed files Yann E. MORIN
2019-01-08 15:13 ` Thomas De Schampheleire
2019-01-08 19:31 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 13/19] support/check-uniq-file: invert condition logic Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 14/19] support/check-uniq-files: don't report files of the same content Yann E. MORIN
2019-01-08 15:22 ` Thomas De Schampheleire
2019-01-07 22:05 ` [Buildroot] [PATCH 15/19] support/check-uniq-files: use argparse to enfore required options Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 16/19] core: check unique files in the corresponding finalize step Yann E. MORIN
2019-01-08 15:24 ` Thomas De Schampheleire
2019-01-08 19:36 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 17/19] core: check for unique target files after all our cleanups Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 18/19] core: ignore non-unique files that have disapeared Yann E. MORIN
2019-01-08 15:29 ` Thomas De Schampheleire
2019-01-08 19:44 ` Yann E. MORIN
2019-01-07 22:05 ` [Buildroot] [PATCH 19/19] core: add optional failure when 2+ packages touch the same file Yann E. MORIN
2019-01-08 12:51 ` [Buildroot] [PATCH 00/19] support: limit install-time instrumentation to current package's files (branch yem/files-list-2) Thomas De Schampheleire
2019-01-08 15:53 ` Thomas De Schampheleire
2019-01-08 21:30 ` Yann E. MORIN
2019-01-09 13:39 ` Thomas De Schampheleire
2019-01-09 18:10 ` Yann E. MORIN
2019-01-10 20:34 ` Thomas De Schampheleire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190108163752.GK19623@scaer \
--to=yann.morin.1998@free.fr \
--cc=buildroot@busybox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox