Skip to content

Commit 3ac092c

Browse files
YangGangUEFImergify[bot]
authored andcommitted
BaseTools: Clean up os.path.normcase and os.path.normpath usage
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]>
1 parent 8593eca commit 3ac092c

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

BaseTools/Source/Python/Common/MultipleWorkspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MultipleWorkspace(object):
3434
#
3535
@classmethod
3636
def convertPackagePath(cls, Ws, Path):
37-
if str(os.path.normcase (Path)).startswith(Ws):
37+
if str(os.path.normcase (os.path.normpath(Path))).startswith(os.path.normcase(os.path.normpath(Ws))):
3838
return os.path.join(Ws, os.path.relpath(Path, Ws))
3939
return Path
4040

BaseTools/Source/Python/Common/TargetTxtClassObject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _GetTarget(self):
176176
ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], ConfDirectoryPath)
177177
else:
178178
if "CONF_PATH" in os.environ:
179-
ConfDirectoryPath = os.path.normcase(os.path.normpath(os.environ["CONF_PATH"]))
179+
ConfDirectoryPath = os.path.normpath(os.environ["CONF_PATH"])
180180
else:
181181
# Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf
182182
ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], 'Conf')

BaseTools/Source/Python/Ecc/EccMain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(self):
6363
self.ParseOption()
6464
EdkLogger.info(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n")
6565

66-
WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"]))
66+
WorkspaceDir = os.path.normpath(os.environ["WORKSPACE"])
6767
os.environ["WORKSPACE"] = WorkspaceDir
6868

6969
# set multiple workspace

BaseTools/Source/Python/GenFds/GenFds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
134134
EdkLogger.error("GenFds", PARAMETER_INVALID, "WORKSPACE is invalid",
135135
ExtraData="Please use '-w' switch to pass it or set the WORKSPACE environment variable.")
136136
else:
137-
Workspace = os.path.normcase(FdsCommandDict.get("Workspace",os.environ.get('WORKSPACE')))
137+
Workspace = os.path.normpath(FdsCommandDict.get("Workspace",os.environ.get('WORKSPACE')))
138138
GenFdsGlobalVariable.WorkSpaceDir = Workspace
139139
if FdsCommandDict.get("debug"):
140140
GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)
@@ -200,7 +200,7 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
200200
ConfDirectoryPath = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ConfDirectoryPath)
201201
else:
202202
if "CONF_PATH" in os.environ:
203-
ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"])
203+
ConfDirectoryPath = os.path.normpath(os.environ["CONF_PATH"])
204204
else:
205205
# Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf
206206
ConfDirectoryPath = mws.join(GenFdsGlobalVariable.WorkSpaceDir, 'Conf')

BaseTools/Source/Python/build/build.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def CheckEnvVariable():
105105
EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
106106
ExtraData="WORKSPACE")
107107

108-
WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"]))
108+
WorkspaceDir = os.path.normpath(os.environ["WORKSPACE"])
109109
if not os.path.exists(WorkspaceDir):
110110
EdkLogger.error("build", FILE_NOT_FOUND, "WORKSPACE doesn't exist", ExtraData=WorkspaceDir)
111111
elif ' ' in WorkspaceDir:
@@ -124,7 +124,7 @@ def CheckEnvVariable():
124124
EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in PACKAGES_PATH", ExtraData=Path)
125125

126126

127-
os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"])
127+
os.environ["EDK_TOOLS_PATH"] = os.path.normpath(os.environ["EDK_TOOLS_PATH"])
128128

129129
# check EDK_TOOLS_PATH
130130
if "EDK_TOOLS_PATH" not in os.environ:
@@ -817,11 +817,11 @@ def __init__(self, Target, WorkspaceDir, BuildOptions,log_q):
817817
EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))
818818
if "PACKAGES_PATH" in os.environ:
819819
# WORKSPACE env has been converted before. Print the same path style with WORKSPACE env.
820-
EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normcase(os.path.normpath(os.environ["PACKAGES_PATH"]))))
820+
EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normpath(os.environ["PACKAGES_PATH"])))
821821
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))
822822
if "EDK_TOOLS_BIN" in os.environ:
823823
# Print the same path style with WORKSPACE env.
824-
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]))))
824+
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normpath(os.environ["EDK_TOOLS_BIN"])))
825825
EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory))
826826
if "PYTHON3_ENABLE" in os.environ:
827827
PYTHON3_ENABLE = os.environ["PYTHON3_ENABLE"]
@@ -2685,7 +2685,7 @@ def Main():
26852685

26862686
if Option.ModuleFile:
26872687
if os.path.isabs (Option.ModuleFile):
2688-
if os.path.normcase (os.path.normpath(Option.ModuleFile)).find (Workspace) == 0:
2688+
if os.path.normcase (os.path.normpath(Option.ModuleFile)).find (os.path.normcase(Workspace)) == 0:
26892689
Option.ModuleFile = NormFile(os.path.normpath(Option.ModuleFile), Workspace)
26902690
Option.ModuleFile = PathClass(Option.ModuleFile, Workspace)
26912691
ErrorCode, ErrorInfo = Option.ModuleFile.Validate(".inf", False)
@@ -2694,13 +2694,13 @@ def Main():
26942694

26952695
if Option.PlatformFile is not None:
26962696
if os.path.isabs (Option.PlatformFile):
2697-
if os.path.normcase (os.path.normpath(Option.PlatformFile)).find (Workspace) == 0:
2697+
if os.path.normcase (os.path.normpath(Option.PlatformFile)).find (os.path.normcase(Workspace)) == 0:
26982698
Option.PlatformFile = NormFile(os.path.normpath(Option.PlatformFile), Workspace)
26992699
Option.PlatformFile = PathClass(Option.PlatformFile, Workspace)
27002700

27012701
if Option.FdfFile is not None:
27022702
if os.path.isabs (Option.FdfFile):
2703-
if os.path.normcase (os.path.normpath(Option.FdfFile)).find (Workspace) == 0:
2703+
if os.path.normcase (os.path.normpath(Option.FdfFile)).find (os.path.normcase(Workspace)) == 0:
27042704
Option.FdfFile = NormFile(os.path.normpath(Option.FdfFile), Workspace)
27052705
Option.FdfFile = PathClass(Option.FdfFile, Workspace)
27062706
ErrorCode, ErrorInfo = Option.FdfFile.Validate(".fdf", False)

0 commit comments

Comments
 (0)