280 Commits

Author SHA1 Message Date
Michael D Kinney
a0002ddc53 BaseTools/build: Add defines for Windows build environments
The stuart tools automatically add -D WIN_HOST_BUILD to
edk2 build command line if a Windows build environment
is detected. This behavior is added to build.py so that
builds of the EmulatorPkg using build.py are not required
to add the option -D WIN_HOST_BUILD when building in a
Windows environment. This aligns Linux and Windows builds
of the EmulatorPkg removing the need to specify extra
defines.

In order to build the EmulatorPkg for Windows Mingw
environments, EmulatorPkg DSC/FDF files require a way
to detect if Windows Mingw environment is present.
The Windows Mingw environment can be detected if
CLANG_BIN is set and mingw32-make.exe is detected
in the CLANG_BIN directory.

If a Windows Mingw environment is detected, add
-D WIN_MINGW32_BUILD to the edk2 build command line.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-06 04:44:08 +00:00
Ayden Meng
a058a2856d BaseTools: Cap AutoGen thread count to avoid file descriptor exhaustion
When the number of build threads multiplied by per-thread file
descriptor usage exceeds the system's open file descriptor limit,
some threads may fail to acquire necessary resources (e.g., pipes
or semaphores), leading to deadlocks or hangs during parallel builds.

To prevent this situation, calculate the safety upper limit of
concurrency by dividing the system's maximum file descriptor limit by
3 (An empirical value derived from balancing performance overhead
against the theoretical number of file descriptors consumed per thread).
The actual thread count is then clamped to this safe value.

Other usages of ThreadNum()—such as during actual compilation or log
queue creation—do not significantly contribute to file descriptor
consumption. Therefore, adjusting ThreadNum() globally would be
unwarranted, as it could unnecessarily restrict parallelism in stages
that are not FD-bound.

This ensures stable parallel builds even under constrained resource
limits.

Signed-off-by: Ayden Meng <mengxiangdong@loongson.cn>
2025-12-03 14:11:32 +00:00
Ayden Meng
7aaf742d2d BaseTools: Handle file descriptor exhaustion during parallel build
Previously, when file descriptors were exhausted in high-concurrency
builds (e.g., 512 threads with 1024 FD limit), the build would hang or
fail silently without clear indication of the root cause.

This change catches relevant OSError instances and terminates the build,
ensuring failures due to resource limits are explicit.

Signed-off-by: Ayden Meng <mengxiangdong@loongson.cn>
2025-12-03 14:11:32 +00:00
Sathya Ravichandran
98d1f8a6fd BaseTools: Remove DXE_SAL_DRIVER
The DXE_SAL_DRIVER module type was introduced to support
Itanium (IPF) platforms. Since support for Itanium processors has been
dropped, the instances of DXE_SAL_DRIVER have been removed.

Ref: [3cb0a311cb]

Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Sathya Ravichandran <sathyar@ami.com>
2025-10-30 10:00:32 +00:00
Leif Lindholm
fcc568ca6e BaseTools/build.py: set BUILD_TIME_EPOCH if not already in environment
Set BUILD_TIME_EPOCH to the current UTC timestamp if not already present
in the environment.

Use the resulting value to print the "Build start time:" message.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-10-16 10:41:09 +00:00
Leif Lindholm
5ca97bf64f BaseTools/build.py: language cleanup around CheckEnvVariable
The function CheckEnvVariable in fact checks several environment
variables. And the comment at its invocation enumerates a specific set of
variables, which defeats half the point of abstracting it out into a
helper function.

Rename the function to the plural form and turn the comment into a list
of examples.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-10-16 10:41:09 +00:00
Oliver Smith-Denny
2ff173af12 BaseTools: Remove ARM32 Support
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 code from BaseTools.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-09-25 22:04:10 +00:00
Aaron Pop
0277d5d8f1 BaseTools: Improve report generation for Nested Fvs.
Build report would not detect a nested FV if the nested
FV was not in a subsection of an FFS statement.

Modify the build report to better handle some of the
variations of nested FVs.

Failing Example:

[Fv.FvName1]
  INF <path to some driver>.inf

[Fv.FvName0]
  FILE FV_IMAGE = B25ACDEF-39CE-4FA5-B50A-33E24DB1BDDF {
    SECTION FV_IMAGE = FvName1
  }

Working Example:

[Fv.FvName1]
  INF <path to some driver>.inf

[Fv.FvName0]
FILE FV_IMAGE = DA04F6BF-A0FD-47EC-928B-5101A6C95026 {
  SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF
    PROCESSING_REQUIRED = TRUE {
      SECTION FV_IMAGE = FvName1
  }
}

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2025-07-08 10:06:36 +08:00
Pierre Gondois
ac9dc33396 BaseTools: build: Remove unnecessary code
Running the vulture tool on the build folder gave the following
report. Remove the unnecessary code.

- build/build.py:79:
  unused function 'IsToolInPath' (60% confidence)
- build/build.py:396:
  unused class 'PlatformMakeUnit' (60% confidence)
- build/build.py:570:
  unused method 'GetErrorMessage' (60% confidence)
- build/build.py:806:
  unused attribute 'HashSkipModules' (60% confidence)
- build/build.py:807:
  unused attribute 'Db_Flag' (60% confidence)
- build/build.py:1048:
  unused attribute 'Db_Flag' (60% confidence)
- build/build.py:2500:
  unused method 'GetRealPathOfTool' (60% confidence)
- build/BuildReport.py:1497:
  unused method 'StrtoHex' (60% confidence)

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-07-01 09:51:38 +08:00
Pierre Gondois
f54fe78d9a BaseTools: Remove unused import
Running the vulture tool gave the following report.
Remove the unused import.

- BPDG/BPDG.py:21:
  unused import 'encodings' (90% confidence)
- build/build.py:61:
  unused import 'Manager' (90% confidence)
- Ecc/CParser4/CLexer.py:4:
  unused import 'TextIO' (90% confidence)
- Ecc/CParser4/CParser.py:5:
  unused import 'TextIO' (90% confidence)
- Eot/CParser4/CLexer.py:4:
  unused import 'TextIO' (90% confidence)
- Eot/CParser4/CParser.py:5:
  unused import 'TextIO' (90% confidence)
- Eot/EotMain.py:28:
  unused import 'ConvertGuid' (90% confidence)
- GenFds/FdfParser.py:16:
  unused import 'hexdigits' (90% confidence)
- Table/TableEotReport.py:16:
  unused import 'EotToolError' (90% confidence)
- UPT/Library/CommentGenerating.py:19:
  unused import 'USAGE_ITEM_NOTIFY' (90% confidence)
- UPT/Library/ParserValidate.py:18:
  unused import 'COMPONENT_TYPE_LIST' (90% confidence)
- UPT/Library/UniClassObject.py:25:
  unused import 'CheckUTF16FileHeader' (90% confidence)

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2025-07-01 09:51:38 +08:00
Zhiguang Liu
9b6d1126de BaseTools: Add GUID section for build report
Add GUID section for build report.
Also, change the GUID format to string format to be easier to parse

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2025-05-28 06:00:44 +00:00
Michael D Kinney
09faa4a1ce BaseTools/build: Reduce special FV full to warning
If an FV_SPARE_SPACE_THRESHOLD is enabled and an FV
is 100% full with 0 bytes free, then this is likely
a special FV that may have alignment requirements
for the FFS file for both the start address and the
length and the FFS file consumes all the available
FV space.

Reduce FV_SPARE_SPACE_THRESHOLD from an error to a
warning if this FV 0 bytes free condition is
detected.

PR #10828 introduced the generation of these error
conditions for an FV with large alignment requirements.
The pad region before the aligned FFS file used to
be counted as free space even though it could never
be used due to the alignment requirements. There was
actually no free space available. PR #10828 fixed the
free space calculation to properly show it as 0 bytes
free, and this change then caused build error when
FV_SPARE_SPACE_THRESHOLD feature was enabled. The
reduction to a warning for this condition allows the
build to complete with errors and also provides a
build log warning message for review.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-03-31 16:04:37 +00:00
Zhiguang Liu
e01f4180b3 BaseTools: Fix missing module PCD in compile information of build report
Module PCD in compile information is missed in module_report.json

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2025-03-25 10:10:20 +00:00
Yang Gang
3ac092cf72 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 <yanggang@byosoft.com.cn>
2025-01-09 07:25:45 +00:00
Dionna Glaze
74ac8cc0e8 BaseTools: Typo fixes
Some in error messages, some in local variable names.

Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
2024-12-11 09:00:21 +08:00
Taylor Beebe
cac0955658 BaseTools: Update Stack Cookie Logic
This patch updates the GenC logic to generate a random stack cookie value
for the stack check libraries. These random values improve security
for modules which cannot update the global intrinsics.

If the stack cookie value is randomized in the AutoGen.h file each
build, the build system will determine the module/library must be
rebuilt causing effectively a clean build every time. This also makes
binary reproducibility impossible.

This patch updates the early build scripts to create 32 and 64-bit JSON
files in the build output directory which each contain 100 randomized
stack cookie values for each bitwidth. If the JSON files are already
present, then they are not recreated which allows them to be stored and
moved to other builds for binary reproducibility. Because they are in
the build directory, a clean build will cause the values to be
regenerated.

The logic which creates AutoGen.h will read these JSON files and use a
hash of the module GUID (the hash seed is fixed in Basetools) to index
into the array of stack cookie values for the module bitwidth. This
model is necessary because there isn't thread-consistent data so we
cannot use a locking mechanism to ensure only one thread is writing to
the stack cookie files at a time. With this model, the build threads
only need to read from the files.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-13 03:58:46 +00:00
Jeff Brasen
aa99d36be9 BaseTools/BuildReport: Improve compile_commands generation
This produces output that matches CodeChecker log command

- Set directory to build output path
- Set build destination to the object created instead of the path
- Add recursive macro support
- Add lookup in module.Macros dictionary
- Add leading include flag to include list
- Add source file to compile commands

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
2024-06-15 11:07:28 +00:00
Guillermo Antonio Palomino Sosa
d2bfe28966 BaseTools: Extend fields for module_report.json
Adding following fields to module_report.json:
* LibraryClass
* ModuleEntryPointList
* ConstructorList
* DestructorList

Signed-off-by: Guillermo Antonio Palomino Sosa <guillermo.a.palomino.sosa@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2023-03-11 06:21:49 +00:00
Palomino Sosa, Guillermo A
4ad7ea9c84 BaseTools: Generate compile information in build report
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2850

Add "-Y REPORT_INFO" option to build command to generate compile
information as part of BuildReport.
This option generates files to be used by external tools as IDE's
to enhance functionality.
Files are created inside build folder:
<Build>/<BuildTarget>/<ToolChain>/CompileInfo

Files created:
* compile_commands.json - Compilation Database. To be used by IDE's
  to enable advance features
* cscope.files - List of files used in compilation. Used by Cscope to parse
  C code and provide browse functionality.
* module_report.json - Module data form buildReport in Json format.

Signed-off-by: Guillermo Antonio Palomino Sosa <guillermo.a.palomino.sosa@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2023-03-11 06:21:49 +00:00
Pierre Gondois
b03dceb87f BaseTools: Remove duplicated words in Python tools
In an effort to clean the documentation of the above
package, remove duplicated words.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2022-10-19 06:32:07 +00:00
Chao Li
c53807cb7b BaseTools: Updated build tools to support new LoongArch.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4053

Python code changes for building EDK2 LoongArch platform.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>

Signed-off-by: Chao Li <lichao@loongson.cn>
Co-authored-by: Baoqi Zhang <zhangbaoqi@loongson.cn>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2022-10-14 02:16:33 +00:00
Pierre Gondois
c7d5b046d9 BaseTools: Remove hard-coded strings for target and tools_def
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3653

The "target.txt" and "tools_def.txt" filenames are hard-coded
at some places when global definitions are available at:
BaseTools/Source/Python/Common/TargetTxtClassObject.py:
DefaultTargetTxtFile
and
BaseTools/Source/Python/Common/ToolDefClassObject.py:
DefaultToolsDefFile

Use these global definitions instead.

Also remove the unused gBuildConfiguration and gToolsDefinition
variables from build.py

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Chris Jones <christopher.jones@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2021-09-29 14:31:37 +00:00
Pierre Gondois
445c39f757 BaseTools: Remove Makefile/MakefileName fields
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3653

The Makefile and MakefilName fields are never set/used. Remove them.
To check this, the following commands can be used:
- grep -rIn "\.Makefile"
- grep -rIn "\.MakefileName"

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Chris Jones <christopher.jones@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2021-09-29 14:31:37 +00:00
Pierre Gondois
259c184c8f BaseTools/build: Set MakefileName
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3653

Running the following command:
  python3 build/build.py -a AARCH64 -t GCC5
  -p ArmPlatformPkg/ArmPlatformPkg.dsc -b DEBUG libraries
triggers the following error:
  make: *** Build/ArmPlatform/DEBUG_GCC5/AARCH64/MdePkg/Library/
  BasePcdLibNull/BasePcdLibNull: Is a directory.  Stop.

Indeed, MakefileName is set to en empty string. Setting MakefileName
resolves the error.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Reviewed-by: Chris Jones <christopher.jones@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2021-09-29 14:31:37 +00:00
Cole
2e1fb41339 build: Fix python3.10 threading DeprecationWarnings
threading camelCase functions have preferred alternatives since
python2.6. python3.10 has started emitting DeprecationWarnings
for them

Signed-off-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
2021-08-02 03:09:59 +00:00