Refactor Mach Mig generation scripts. [crashpad/crashpad : main]

9 views
Skip to first unread message

Justin Cohen (Gerrit)

unread,
Nov 26, 2025, 5:07:30 PMNov 26
to Mark Mentovai, crashp...@chromium.org
Attention needed from Mark Mentovai

Justin Cohen added 1 comment

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Justin Cohen . resolved

ptal!

Open in Gerrit

Related details

Attention is currently required from:
  • Mark Mentovai
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: If1ede746cfcb470dffdad20d07ab8942fd1030d2
Gerrit-Change-Number: 7205874
Gerrit-PatchSet: 4
Gerrit-Owner: Justin Cohen <justi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-Attention: Mark Mentovai <ma...@chromium.org>
Gerrit-Comment-Date: Wed, 26 Nov 2025 22:07:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Mark Mentovai (Gerrit)

unread,
Dec 1, 2025, 9:46:41 AMDec 1
to Justin Cohen, crashp...@chromium.org
Attention needed from Justin Cohen

Mark Mentovai added 6 comments

File util/mach/mig.py
Line 33, Patchset 4 (Latest):def _generate_and_fix(user_c, server_c, user_h, server_h, defs, sdk, clang_path,
Mark Mentovai . unresolved

Force callers to provide everything as a keyword argument, like in the other file: `_generate_and_fix(*, user_c, server_c, …)`.

(if you have a reason to want to leave some of the arguments as not keyword-only, that’s probably OK too, but I definitely don’t think that all of them should be allowed to be non-keyword.)

Line 33, Patchset 4 (Latest):def _generate_and_fix(user_c, server_c, user_h, server_h, defs, sdk, clang_path,
mig_path, migcom_path, arch, extra_args):
Mark Mentovai . unresolved

These are probably just as optional here as they are in the other file. `sdk=None, clang_path=None, …`

Line 34, Patchset 4 (Latest): mig_path, migcom_path, arch, extra_args):
Mark Mentovai . unresolved

`mig_args`?

Line 49, Patchset 4 (Latest): contents += open(file, 'r').read()
Mark Mentovai . unresolved

Slightly better with a `with` context manager, to ensure precise timing of the file close when the file is no longer needed.

File util/mach/mig_gen.py
Line 35, Patchset 4 (Latest): common_args=None):
Mark Mentovai . unresolved

`mig_args`

Line 82, Patchset 4 (Latest): return parser.parse_known_args(args)
Mark Mentovai . unresolved

`parse_known_args` is too loosey-goosey. I don’t like it because it masks errors and it’s not resilient in the face of future changes to the script and the set of arguments that it understands.

Preferable:

```python
parser.add_argument('mig_args', nargs='*')
return parser.parse_args(args)
```

Then, use the magic `--` argument to separate the required arguments above this line from `mig_args`. This allows option-style arguments that begin with `-` to make it through to `mig_args` without becoming argparse errors due to not being defined in `parser`.

Open in Gerrit

Related details

Attention is currently required from:
  • Justin Cohen
Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: crashpad/crashpad
    Gerrit-Branch: main
    Gerrit-Change-Id: If1ede746cfcb470dffdad20d07ab8942fd1030d2
    Gerrit-Change-Number: 7205874
    Gerrit-PatchSet: 4
    Gerrit-Owner: Justin Cohen <justi...@chromium.org>
    Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
    Gerrit-Attention: Justin Cohen <justi...@chromium.org>
    Gerrit-Comment-Date: Mon, 01 Dec 2025 14:46:38 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Justin Cohen (Gerrit)

    unread,
    Dec 1, 2025, 3:51:32 PMDec 1
    to Mark Mentovai, crashp...@chromium.org
    Attention needed from Mark Mentovai

    Justin Cohen added 6 comments

    File util/mach/mig.py
    Line 33, Patchset 4:def _generate_and_fix(user_c, server_c, user_h, server_h, defs, sdk, clang_path,
    Mark Mentovai . resolved

    Force callers to provide everything as a keyword argument, like in the other file: `_generate_and_fix(*, user_c, server_c, …)`.

    (if you have a reason to want to leave some of the arguments as not keyword-only, that’s probably OK too, but I definitely don’t think that all of them should be allowed to be non-keyword.)

    Justin Cohen

    Done

    Line 33, Patchset 4:def _generate_and_fix(user_c, server_c, user_h, server_h, defs, sdk, clang_path,
    mig_path, migcom_path, arch, extra_args):
    Mark Mentovai . resolved

    These are probably just as optional here as they are in the other file. `sdk=None, clang_path=None, …`

    Justin Cohen

    Done

    Line 34, Patchset 4: mig_path, migcom_path, arch, extra_args):
    Mark Mentovai . resolved

    `mig_args`?

    Justin Cohen

    Done

    Line 49, Patchset 4: contents += open(file, 'r').read()
    Mark Mentovai . resolved

    Slightly better with a `with` context manager, to ensure precise timing of the file close when the file is no longer needed.

    Justin Cohen

    Done

    File util/mach/mig_gen.py
    Line 35, Patchset 4: common_args=None):
    Mark Mentovai . resolved

    `mig_args`

    Justin Cohen

    Done

    Line 82, Patchset 4: return parser.parse_known_args(args)
    Mark Mentovai . resolved

    `parse_known_args` is too loosey-goosey. I don’t like it because it masks errors and it’s not resilient in the face of future changes to the script and the set of arguments that it understands.

    Preferable:

    ```python
    parser.add_argument('mig_args', nargs='*')
    return parser.parse_args(args)
    ```

    Then, use the magic `--` argument to separate the required arguments above this line from `mig_args`. This allows option-style arguments that begin with `-` to make it through to `mig_args` without becoming argparse errors due to not being defined in `parser`.

    Justin Cohen

    Done -- note to make nargs='*', I had to reorder things to be:
    "%(prog)s [OPTIONS] <defs> <user_c> <server_c> <user_h> <server_h> -- [mig arguments]"

    And I updated the ArgumentParser comment to reflect that.

    PTAL!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Mark Mentovai
    Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: crashpad/crashpad
      Gerrit-Branch: main
      Gerrit-Change-Id: If1ede746cfcb470dffdad20d07ab8942fd1030d2
      Gerrit-Change-Number: 7205874
      Gerrit-PatchSet: 5
      Gerrit-Owner: Justin Cohen <justi...@chromium.org>
      Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
      Gerrit-Attention: Mark Mentovai <ma...@chromium.org>
      Gerrit-Comment-Date: Mon, 01 Dec 2025 20:51:30 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Mark Mentovai <ma...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages