Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmpcodesize][2] Begin extracting regular expressions #638

Closed
wants to merge 2 commits into from

Conversation

modocache
Copy link
Contributor

This pull request should be reviewed after #636 is merged. Sorry for any confusion. I split up the pull requests to make code review easier.

What's in this pull request?

cmpcodesize.compare has a few responsibilities: matching regular expressions on otool output, and storing the results of those matches in dictionaries.

This pull request begins extracting the regular expression matching into a separate file, cmpcodesize/regex.py.

Why merge this pull request?

  • Extracting the regex logic makes the code more modular, and allows for finer-grained unit tests.
  • These changes, which include unit tests, improves test coverage.

What downsides are there to merging this pull request?

The migration process is not completely done. You'll notice a FIXME for the other regex's still in compare.py. I'd like to address those in future pull requests, but the maintainers may prefer to do it all in one pull request.

The functions in `cmpcodesize.compare` do several things: they call
otool, they use regex matchers to extract information from otool's
output, and they output that information using `print()`.

Currently, the only way to test cmpcodesize is via functional tests:
ones that actually run on a dylib like libswiftCore.dylib. This takes a
lot of time and is difficult to fully automate.

By extracting otool calls from `cmpcodesize.compare`, we can test those
in isolation. Furthermore, future commits can test the functions in
`cmpcodesize.compare` using canned strings, instead of actual otool
output.


# Cache the compiled regex into a global object.
_ARCHITECTURE_REGEX = re.compile('architecture ([\S]+)')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be \S+ without square brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it can, thanks for pointing that out! Just changed it and the unit tests still all pass. feelsgoodman. 😄

`cmpcodesize.compare` has a few responsibilities: matching regular
expressions on otool output, and storing the results of those matches
in dictionaries.

Begin extracting the regular expression matching into a separate file,
`cmpcodesize/regex.py`. This makes the code more modular, and allows
for finer-grained unit tests.
@modocache
Copy link
Contributor Author

This should probably be reviewed by @eeckstein , @swiftix, and @nadavrot. 👋

@nadavrot
Copy link
Contributor

@modocache What are your plans for cmpcodesize? Are you planning to add ELF support? Are you planning to add additional diagnostics?

@modocache
Copy link
Contributor Author

I was initially planning on doing some code cleanup and improving test coverage, then discussing further with you folks! In discussions in #548 and #553 you mentioned CSV output. I was thinking about bringing that up on the mailing list to flesh out exactly what you were looking for.

If there's anything else you're looking to do, I'd be happy to help! 👍

@modocache
Copy link
Contributor Author

I created SR-407 to track supporting ELF in cmpcodesize.

@nadavrot
Copy link
Contributor

@modocache Are you planning to work on making the output CSV? It is annoying to manually copy-and-paste values from the current format.

@modocache
Copy link
Contributor Author

Are you planning to work on making the output CSV?

Sure! I'll create a JIRA issue when I get in front of a computer.

@gottesmm
Copy link
Contributor

I talked with @eeckstein and he said he would look at this. Assigning to him.

@eeckstein
Copy link
Contributor

@modocache Sorry for the long delay. Do you want to continue with this PR?

@modocache
Copy link
Contributor Author

@eeckstein Yeah I'd love to, assuming this script is still used. Is it?

@modocache
Copy link
Contributor Author

Sorry for letting this languish. I don't think I have the capacity to shepherd this at the moment. I'll close this pull request to reduce the amount of noise on the repository. Thanks!

I also finally got around to creating a JIRA issue for outputting CSV: https://bugs.swift.org/browse/SR-2595.

@modocache modocache closed this Sep 8, 2016
freak4pc pushed a commit to freak4pc/swift that referenced this pull request Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants