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

BaseTools: Clean up os.path.normcase and os.path.normpath usage #6561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YangGangUEFI
Copy link
Contributor

Refer to the docs of python, os.path.normcase(path) function: "Normalize the case of a pathname. On Windows, convert all characters in the pathname to lowercase, and also convert forward slashes to backward slashes. On other operating systems, return the path unchanged."

os.path.normpath(path) also convert forward slashes to backward slashes.

So call os.path.normcase after os.path.normpath just convert path to lowercase on Windows(only).

And Windows is case-insensitive but case-preserving.

So the usage of os.path.normcase(os.path.normpath(path)) can be simplified to os.path.normpath(path). Then we can use case-preserving paths rather than lowercase paths in compile_commands.json file or build log.

But this patch continue to use os.path.normcase
when comparing/searching paths.

Description

  • Breaking change?

    • Not Select this but file path in generated .fd binary has been changed(In Windows, lowercase to uppercase). Do not known if it's "breaking".
      image
  • Impacts security?

    • N/A
  • Includes tests?

    • N/A

How This Was Tested

Compare build log.

Or use -y report.txt -Y COMPILE_INFO and compare workspace path string in report.txt or CompileInfo/compile_commands.json file.

e.g.

In build log output:

before: WORKSPACE = d:\opensource\edk2

after: WORKSPACE = D:\OpenSource\edk2

D:\OpenSource is matched with real charactor case in FileExplorer/CMD...

Integration Instructions

N/A

Refer to the docs of python, `os.path.normcase(path)` function:
"Normalize the case of a pathname. On Windows, convert all characters in
the pathname to lowercase, and also convert forward slashes to backward
slashes. On other operating systems, return the path unchanged."

`os.path.normpath(path)` also convert forward slashes to backward slashes.

So call `os.path.normcase` after `os.path.normpath` just convert path to
lowercase on Windows(only).

And Windows is case-insensitive but case-preserving.

So the usage of `os.path.normcase(os.path.normpath(path))` can be
simplified to `os.path.normpath(path)`. Then we can use case-preserving
paths rather than lowercase paths in compile_commands.json file
or build log.

But this patch continue to use `os.path.normcase`
when comparing/searching paths.

Signed-off-by: Yang Gang <[email protected]>
@YangGangUEFI
Copy link
Contributor Author

Not sure if this is acceptable. But please give some comments or discussion.🤝

@YangGangUEFI YangGangUEFI marked this pull request as ready for review December 20, 2024 01:13
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.

1 participant