BaseTools: Generate multiple rules when multiple output files

This patch modifies the Makefile generation not to stop
adding Makfile rules when the first final target is found.
E.g.:
If the following rules are described in build_rule.txt:
 -[Rule1]: .X files generate .Y and .Z files;
 -[Rule2]: .Z files generate .Z1 files.
Currently, if a File1.X file was part of the sources of a
module, only [Rule1] would be generated in the Makefile.
Indeed, there are no rules to apply to .Y files: .Y files
are a final target. However, there is still [Rule2] to
apply to .Z files.

This patch also adds a dependency between the first
ouput file of a rule and the other output files.
For instance, with the same example as above, File1.Y
and File1.Z are generated by the following rule:
File1.Y: File1.X
    <Generate File1.Y>
    <Generate File1.Z>

and the new dependency is:
File1.Z: File1.Y

This is necessary to keep a dependency order during the
execution of the Makefile. Indeed, .Y and .Z files are
generated by the execution of a common set of commands,
and without this rule, there is no explicit dependency
relation between them.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Suggested-by: Tomas Pilar <Tomas.Pilar@arm.com>

Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Pierre Gondois 2020-07-01 22:06:01 +08:00 committed by mergify[bot]
parent 01356d2963
commit 6511277827
2 changed files with 27 additions and 17 deletions

View File

@ -1054,6 +1054,12 @@ cleanlib:
TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps} TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}
self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict)) self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
# Add a Makefile rule for targets generating multiple files.
# The main output is a prerequisite for the other output files.
for i in T.Outputs[1:]:
AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}
self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))
def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict): def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):
if not CmdSumDict: if not CmdSumDict:
for item in self._AutoGenObject.Targets[Type]: for item in self._AutoGenObject.Targets[Type]:

View File

@ -860,7 +860,8 @@ class ModuleAutoGen(AutoGen):
SubDirectory = os.path.join(self.OutputDir, File.SubDir) SubDirectory = os.path.join(self.OutputDir, File.SubDir)
if not os.path.exists(SubDirectory): if not os.path.exists(SubDirectory):
CreateDirectory(SubDirectory) CreateDirectory(SubDirectory)
LastTarget = None TargetList = set()
FinalTargetName = set()
RuleChain = set() RuleChain = set()
SourceList = [File] SourceList = [File]
Index = 0 Index = 0
@ -870,6 +871,9 @@ class ModuleAutoGen(AutoGen):
self.BuildOption self.BuildOption
while Index < len(SourceList): while Index < len(SourceList):
# Reset the FileType if not the first iteration.
if Index > 0:
FileType = TAB_UNKNOWN_FILE
Source = SourceList[Index] Source = SourceList[Index]
Index = Index + 1 Index = Index + 1
@ -886,29 +890,25 @@ class ModuleAutoGen(AutoGen):
elif Source.Ext in self.BuildRules: elif Source.Ext in self.BuildRules:
RuleObject = self.BuildRules[Source.Ext] RuleObject = self.BuildRules[Source.Ext]
else: else:
# stop at no more rules # No more rule to apply: Source is a final target.
if LastTarget: FinalTargetName.add(Source)
self._FinalBuildTargetList.add(LastTarget) continue
break
FileType = RuleObject.SourceFileType FileType = RuleObject.SourceFileType
self._FileTypes[FileType].add(Source) self._FileTypes[FileType].add(Source)
# stop at STATIC_LIBRARY for library # stop at STATIC_LIBRARY for library
if self.IsLibrary and FileType == TAB_STATIC_LIBRARY: if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
if LastTarget: FinalTargetName.add(Source)
self._FinalBuildTargetList.add(LastTarget) continue
break
Target = RuleObject.Apply(Source, self.BuildRuleOrder) Target = RuleObject.Apply(Source, self.BuildRuleOrder)
if not Target: if not Target:
if LastTarget: # No Target: Source is a final target.
self._FinalBuildTargetList.add(LastTarget) FinalTargetName.add(Source)
break continue
elif not Target.Outputs:
# Only do build for target with outputs
self._FinalBuildTargetList.add(Target)
TargetList.add(Target)
self._BuildTargets[FileType].add(Target) self._BuildTargets[FileType].add(Target)
if not Source.IsBinary and Source == File: if not Source.IsBinary and Source == File:
@ -916,12 +916,16 @@ class ModuleAutoGen(AutoGen):
# to avoid cyclic rule # to avoid cyclic rule
if FileType in RuleChain: if FileType in RuleChain:
break EdkLogger.error("build", ERROR_STATEMENT, "Cyclic dependency detected while generating rule for %s" % str(Source))
RuleChain.add(FileType) RuleChain.add(FileType)
SourceList.extend(Target.Outputs) SourceList.extend(Target.Outputs)
LastTarget = Target
FileType = TAB_UNKNOWN_FILE # For each final target name, retrieve the corresponding TargetDescBlock instance.
for FTargetName in FinalTargetName:
for Target in TargetList:
if FTargetName == Target.Target:
self._FinalBuildTargetList.add(Target)
@cached_property @cached_property
def Targets(self): def Targets(self):