Skip to content

[Bug]: toolsetup.bat is trying to use delayed expansion incorrectly. #11744

@FuntimeMS

Description

@FuntimeMS

Is there an existing issue for this?

  • I have searched existing issues

Bug Type

  • Firmware
  • Tool
  • Unit Test

What packages are impacted?

BaseTools

Which targets are impacted by this bug?

No response

Current Behavior

I downloaded a fresh copy of the EDK2 repo and the submodules, then I tried to run edksetup.bat and I get the following error:

Image

After looking into edksetup.bat, I realized the error was coming from BaseTools\toolsetup.bat.

I narrowed the error down to this massive nested if statement.
if not defined EDK_TOOLS_BIN ( if defined BASETOOLS_MINGW_BUILD ( if /I "%MINGW_ARCH%"=="X64" ( set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win64 ) else ( if /I "%MINGW_ARCH%"=="AARCH64" ( set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win64 ) else ( set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32 ) ) set MINGW_ARCH= ) else ( set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32 ) if not defined FORCE_REBUILD ( if not defined REBUILD ( if not exist "%EDK_TOOLS_BIN%" ( echo. echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!! echo Please check the directory %EDK_TOOLS_BIN% echo Or configure EDK_TOOLS_BIN env to point to Bin directory. echo. ) ) ) )

This was added on 6/6/2025 as part of a larger improvement.
The problem is that when the variable "EDK_TOOLS_BIN" is set within the if statement, "delayed expansion" is needed in order to get the updated valued of the variable from within the same statement.

A simpler fix is to split the if statement into smaller pieces.
Maybe flip the top if statement into something like this:
if not defined EDK_TOOLS_BIN GOTO :EDKToolsDefined
and then add the label ":EDKToolsDefined" below the current if statement.

Expected Behavior

I expected edksetup.bat to run successfully after pulling a new clone of the EDK2 repo.

Steps To Reproduce

I pulled a fresh copy of the EDK2 repo, and ran edksetup.bat on a Win11 system that was not yet fully configured to build EDK2 projects.
This gave me an unexpected error as well as some expected errors.

Build Environment

- OS(s): Win 11
- Tool Chain(s): cmd prompt + edksetup.bat

Version Information

Commit: SHA-1: c0ef2b017855177903d87937ac4cdaec5c7851db

Urgency

Low

Are you going to fix this?

I will fix it

Do you need maintainer feedback?

Maintainer feedback requested

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions