public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Conditionally Include FDF File
@ 2020-04-20  5:25 Ashish Singhal
  2020-04-20  6:16 ` [edk2-devel] " Lin, Derek (HPS SW)
  2020-04-20 12:05 ` Laszlo Ersek
  0 siblings, 2 replies; 6+ messages in thread
From: Ashish Singhal @ 2020-04-20  5:25 UTC (permalink / raw)
  To: devel@edk2.groups.io, Bob Feng, Gao, Liming

[-- Attachment #1: Type: text/plain, Size: 4438 bytes --]

Hello,

I am trying to change my top-level FDF file layout by conditionally including an FDF depending on a build time define being passed or not. The behavior I am seeing is as follows.


  1.  I am passing the build time define and the included fdf.inc file gets included.
  2.  I am not passing the build time define and the included fdf.inc file still gets included apparently.
     *   However, there is a strange behavior which is that in the conditional block if I have anything else other than the !include statement, it gets ignored.
     *   But if there is a !include statement inside a conditional (which should fail) the include statement is still processed.

Conditional statement in top-level fdf is:

!ifdef $(BUILD_PLATFORM_XYZ)
  !include Platform/NVIDIA/XYZ.fdf.inc
!endif

When we do not pass in -D BUILD_PLATFORM_XYZ during build, Platform/NVIDIA/XYZ.fdf.inc file should not be included as it could be totally absent as well. However, the build system tries to include the file and fails with the following log.

(Python 3.5.2 on linux) Traceback (most recent call last):
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 2586, in Main
    MyBuild.Launch()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 2381, in Launch
    self._MultiThreadBuildPlatform()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 2231, in _MultiThreadBuildPlatform
    Wa, self.BuildModules = self.PerformAutoGen(BuildTarget,ToolChain)
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/BinWrappers/PosixLike/../../Source/Python/build/build.py", line 2096, in PerformAutoGen
    self.Progress
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py", line 43, in __init__
    self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py", line 112, in _InitWorker
    self.ProcessModuleFromPdf()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py", line 188, in ProcessModuleFromPdf
    if self.FdfProfile:
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/Common/caching.py", line 28, in __get__
    Value = obj.__dict__[self._function.__name__] = self._function(obj)
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py", line 164, in FdfProfile
    Fdf.ParseFile()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/GenFds/FdfParser.py", line 1312, in ParseFile
    self.Preprocess()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/GenFds/FdfParser.py", line 1291, in Preprocess
    self.PreprocessIncludeFile()
  File "/media/ashishsingha/Workspace/UEFI/out/nvidia/bootloader/uefi/BaseTools/Source/Python/GenFds/FdfParser.py", line 625, in PreprocessIncludeFile
    self.FileName, self.CurrentLineNumber)
GenFds.FdfParser.Warning: The include file does not exist under below directories:
<Here it lists the root diectories included in the build>.
<Here it lists the line and column number of top level fdf file which has include statement for Platform/NVIDIA/XYZ.fdf.inc but under a conditional as mentioned above.

Any help getting around this if you think I am checking for the conditional incorrectly or checking the build script for a potential bug would be highly appreciated.

Thanks
Ashish




-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

[-- Attachment #2: Type: text/html, Size: 8603 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] Conditionally Include FDF File
  2020-04-20  5:25 Conditionally Include FDF File Ashish Singhal
@ 2020-04-20  6:16 ` Lin, Derek (HPS SW)
  2020-04-20  7:07   ` Ashish Singhal
  2020-04-20 12:05 ` Laszlo Ersek
  1 sibling, 1 reply; 6+ messages in thread
From: Lin, Derek (HPS SW) @ 2020-04-20  6:16 UTC (permalink / raw)
  To: Ashish Singhal, devel

[-- Attachment #1: Type: text/plain, Size: 152 bytes --]

I saw this issue too.

The included file is always included no matter the condition is TRUE or FALSE.
```
!if FALSE
!include abc.fdf
!endif
```

[-- Attachment #2: Type: text/html, Size: 617 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] Conditionally Include FDF File
  2020-04-20  6:16 ` [edk2-devel] " Lin, Derek (HPS SW)
@ 2020-04-20  7:07   ` Ashish Singhal
  2020-04-20  7:42     ` Ashish Singhal
  0 siblings, 1 reply; 6+ messages in thread
From: Ashish Singhal @ 2020-04-20  7:07 UTC (permalink / raw)
  To: Lin, Derek (HPS SW), devel@edk2.groups.io, Bob Feng, Gao, Liming

[-- Attachment #1: Type: text/plain, Size: 1786 bytes --]

It seems like this is happening because in FdfParser.py, include files are processed before processing the conditional statements. I think this is being done so that all defines (even from the included files) can be accounted for before processing any conditionals. This seems to be a valid flow from pre-processing perspective, although this leaves out the use case where a file may be conditionally included.

Bob/Liming,

For now, I have fixed the issue by changing my conditional include to be the following:

In top-level FDF:
!ifdef $(BUILD_PLATFORM_XYZ)
  $(INCLUDE_XYZ_FDF)
!endif

In top-level DSC:
!ifdef $(BUILD_PLATFORM_XYZ)
  INCLUDE_XYZ_FDF = !include Platform/NVIDIA/XYZ.fdf.inc
!endif

Please suggest me if there is a batter way of working around this issue.

Thanks
Ashish
________________________________
From: Lin, Derek (HPS SW) <derek.lin2@hpe.com>
Sent: Monday, April 20, 2020 12:16 AM
To: Ashish Singhal <ashishsingha@nvidia.com>; devel@edk2.groups.io <devel@edk2.groups.io>
Subject: Re: [edk2-devel] Conditionally Include FDF File

External email: Use caution opening links or attachments

I saw this issue too.

The included file is always included no matter the condition is TRUE or FALSE.
```
!if FALSE
  !include abc.fdf
!endif
```


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

[-- Attachment #2: Type: text/html, Size: 5321 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] Conditionally Include FDF File
  2020-04-20  7:07   ` Ashish Singhal
@ 2020-04-20  7:42     ` Ashish Singhal
  0 siblings, 0 replies; 6+ messages in thread
From: Ashish Singhal @ 2020-04-20  7:42 UTC (permalink / raw)
  To: Lin, Derek (HPS SW), devel@edk2.groups.io, Bob Feng, Gao, Liming

[-- Attachment #1: Type: text/plain, Size: 2356 bytes --]

Spoke to soon. My change works for the case where BUILD_PLATFORM_XYZ is not defined but the case where it is defined I guess INCLUDE_XYZ_FDF needs to be defined in a different way with proper escape characters.

Thanks
Ashish
________________________________
From: Ashish Singhal <ashishsingha@nvidia.com>
Sent: Monday, April 20, 2020 1:07 AM
To: Lin, Derek (HPS SW) <derek.lin2@hpe.com>; devel@edk2.groups.io <devel@edk2.groups.io>; Bob Feng <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: Re: [edk2-devel] Conditionally Include FDF File

It seems like this is happening because in FdfParser.py, include files are processed before processing the conditional statements. I think this is being done so that all defines (even from the included files) can be accounted for before processing any conditionals. This seems to be a valid flow from pre-processing perspective, although this leaves out the use case where a file may be conditionally included.

Bob/Liming,

For now, I have fixed the issue by changing my conditional include to be the following:

In top-level FDF:
!ifdef $(BUILD_PLATFORM_XYZ)
  $(INCLUDE_XYZ_FDF)
!endif

In top-level DSC:
!ifdef $(BUILD_PLATFORM_XYZ)
  INCLUDE_XYZ_FDF = !include Platform/NVIDIA/XYZ.fdf.inc
!endif

Please suggest me if there is a batter way of working around this issue.

Thanks
Ashish
________________________________
From: Lin, Derek (HPS SW) <derek.lin2@hpe.com>
Sent: Monday, April 20, 2020 12:16 AM
To: Ashish Singhal <ashishsingha@nvidia.com>; devel@edk2.groups.io <devel@edk2.groups.io>
Subject: Re: [edk2-devel] Conditionally Include FDF File

External email: Use caution opening links or attachments

I saw this issue too.

The included file is always included no matter the condition is TRUE or FALSE.
```
!if FALSE
  !include abc.fdf
!endif
```


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

[-- Attachment #2: Type: text/html, Size: 7680 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] Conditionally Include FDF File
  2020-04-20  5:25 Conditionally Include FDF File Ashish Singhal
  2020-04-20  6:16 ` [edk2-devel] " Lin, Derek (HPS SW)
@ 2020-04-20 12:05 ` Laszlo Ersek
  2020-04-20 16:33   ` Ashish Singhal
  1 sibling, 1 reply; 6+ messages in thread
From: Laszlo Ersek @ 2020-04-20 12:05 UTC (permalink / raw)
  To: devel, ashishsingha, Bob Feng, Gao, Liming

On 04/20/20 07:25, Ashish Singhal wrote:

> I am trying to change my top-level FDF file layout by conditionally including an FDF depending on a build time define being passed or not.

> Any help getting around this

Try including unconditionally, and pushing down the !if into the includee.

This is known to work; see for example "NetworkPkg/Network.fdf.inc".

(The outermost "NETWORK_ENABLE" flag in "Network.fdf.inc" parallels your
use case.)

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] Conditionally Include FDF File
  2020-04-20 12:05 ` Laszlo Ersek
@ 2020-04-20 16:33   ` Ashish Singhal
  0 siblings, 0 replies; 6+ messages in thread
From: Ashish Singhal @ 2020-04-20 16:33 UTC (permalink / raw)
  To: Laszlo Ersek, devel@edk2.groups.io, Bob Feng, Gao, Liming

[-- Attachment #1: Type: text/plain, Size: 1726 bytes --]

That is not the same use case. You are always including NetworkPkg/Network.fdf.inc and then inside of it you are using NETWORK_ENABLE flag to include the associated drivers or not include anything at all but the file exists. My use case differs where the file may not exist and that is why I have a conditional flag outside the include directive.

Thanks
Ashish
________________________________
From: Laszlo Ersek <lersek@redhat.com>
Sent: Monday, April 20, 2020 6:05 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>; Ashish Singhal <ashishsingha@nvidia.com>; Bob Feng <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: Re: [edk2-devel] Conditionally Include FDF File

External email: Use caution opening links or attachments


On 04/20/20 07:25, Ashish Singhal wrote:

> I am trying to change my top-level FDF file layout by conditionally including an FDF depending on a build time define being passed or not.

> Any help getting around this

Try including unconditionally, and pushing down the !if into the includee.

This is known to work; see for example "NetworkPkg/Network.fdf.inc".

(The outermost "NETWORK_ENABLE" flag in "Network.fdf.inc" parallels your
use case.)

Thanks
Laszlo


-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

[-- Attachment #2: Type: text/html, Size: 5046 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-20 16:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-20  5:25 Conditionally Include FDF File Ashish Singhal
2020-04-20  6:16 ` [edk2-devel] " Lin, Derek (HPS SW)
2020-04-20  7:07   ` Ashish Singhal
2020-04-20  7:42     ` Ashish Singhal
2020-04-20 12:05 ` Laszlo Ersek
2020-04-20 16:33   ` Ashish Singhal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox