* [PATCH v1 0/3] BaseTools: refactor and cleanup
@ 2018-04-04 20:56 Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 1/3] BaseTools: move RegEx to root of file and share it Jaben Carsey
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jaben Carsey @ 2018-04-04 20:56 UTC (permalink / raw)
To: edk2-devel
no real functional change. just code cleanup.
Jaben Carsey (3):
BaseTools: move RegEx to root of file and share it
BaseTools: Autogen - change from list to set
BaseTools: small cleanup
BaseTools/Source/Python/AutoGen/AutoGen.py | 51 ++++++--------------
BaseTools/Source/Python/Common/Expression.py | 4 +-
BaseTools/Source/Python/Common/RangeExpression.py | 5 +-
3 files changed, 19 insertions(+), 41 deletions(-)
--
2.16.2.windows.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/3] BaseTools: move RegEx to root of file and share it
2018-04-04 20:56 [PATCH v1 0/3] BaseTools: refactor and cleanup Jaben Carsey
@ 2018-04-04 20:56 ` Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 2/3] BaseTools: Autogen - change from list to set Jaben Carsey
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jaben Carsey @ 2018-04-04 20:56 UTC (permalink / raw)
To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu
make it easy to import and use by others
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/Common/Expression.py | 4 ++--
BaseTools/Source/Python/Common/RangeExpression.py | 5 ++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index 320f0015009b..462e8f93f883 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -43,6 +43,7 @@ ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARC
__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
_ReLabel = re.compile('LABEL\((\w+)\)')
_ReOffset = re.compile('OFFSET_OF\((\w+)\)')
+PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
## SplitString
# Split string to list according double quote
@@ -214,7 +215,6 @@ class ValueExpression(object):
NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']
- PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
SymbolPattern = re.compile("("
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
@@ -616,7 +616,7 @@ class ValueExpression(object):
raise BadExpression(ERR_EMPTY_TOKEN)
# PCD token
- if self.PcdPattern.match(self._Token):
+ if PcdPattern.match(self._Token):
if self._Token not in self._Symb:
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
Ex.Pcd = self._Token
diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py
index 5fcc8a432a56..5ee59184e66e 100644
--- a/BaseTools/Source/Python/Common/RangeExpression.py
+++ b/BaseTools/Source/Python/Common/RangeExpression.py
@@ -16,6 +16,7 @@ from Common.GlobalData import *
from CommonDataClass.Exceptions import BadExpression
from CommonDataClass.Exceptions import WrnExpression
import uuid
+from Common.Expression import PcdPattern
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@@ -209,8 +210,6 @@ class RangeExpression(object):
NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<']
- PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
-
RangePattern = re.compile(r'[0-9]+ - [0-9]+')
def preProcessRangeExpr(self, expr):
@@ -573,7 +572,7 @@ class RangeExpression(object):
raise BadExpression(ERR_EMPTY_TOKEN)
# PCD token
- if self.PcdPattern.match(self._Token):
+ if PcdPattern.match(self._Token):
if self._Token not in self._Symb:
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
Ex.Pcd = self._Token
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 2/3] BaseTools: Autogen - change from list to set
2018-04-04 20:56 [PATCH v1 0/3] BaseTools: refactor and cleanup Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 1/3] BaseTools: move RegEx to root of file and share it Jaben Carsey
@ 2018-04-04 20:56 ` Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 3/3] BaseTools: small cleanup Jaben Carsey
2018-04-08 8:20 ` [PATCH v1 0/3] BaseTools: refactor and cleanup Zhu, Yonghong
3 siblings, 0 replies; 5+ messages in thread
From: Jaben Carsey @ 2018-04-04 20:56 UTC (permalink / raw)
To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu
by changing from list to set(), we can skip all the preprocessing
to prevent duplication and we dont need to convert to a set() later
on for each use
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/AutoGen/AutoGen.py | 36 ++++++++------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index 3384fdb70b7e..b4575bcb8436 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -404,8 +404,8 @@ class WorkspaceAutoGen(AutoGen):
- SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
- BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}
+ SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}
+ BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}
SourcePcdDict_Keys = SourcePcdDict.keys()
BinaryPcdDict_Keys = BinaryPcdDict.keys()
@@ -431,27 +431,21 @@ class WorkspaceAutoGen(AutoGen):
if 'DynamicEx' in BuildData.Pcds[key].Type:
if BuildData.IsBinaryModule:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:
- BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ BinaryPcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
else:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:
- SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ SourcePcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
elif 'PatchableInModule' in BuildData.Pcds[key].Type:
if BuildData.MetaFile.Ext == '.inf':
if BuildData.IsBinaryModule:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:
- BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ BinaryPcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
else:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:
- SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ SourcePcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
elif 'Dynamic' in BuildData.Pcds[key].Type:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:
- SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ SourcePcdDict['Dynamic'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
elif 'FixedAtBuild' in BuildData.Pcds[key].Type:
- if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:
- SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
+ SourcePcdDict['FixedAtBuild'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
else:
pass
#
@@ -460,13 +454,13 @@ class WorkspaceAutoGen(AutoGen):
for i in SourcePcdDict_Keys:
for j in SourcePcdDict_Keys:
if i != j:
- IntersectionList = list(set(SourcePcdDict[i]).intersection(set(SourcePcdDict[j])))
- if len(IntersectionList) > 0:
+ Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j])
+ if len(Intersections) > 0:
EdkLogger.error(
'build',
FORMAT_INVALID,
"Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),
- ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in IntersectionList])
+ ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections])
)
else:
pass
@@ -477,8 +471,8 @@ class WorkspaceAutoGen(AutoGen):
for i in BinaryPcdDict_Keys:
for j in BinaryPcdDict_Keys:
if i != j:
- IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))
- for item in IntersectionList:
+ Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j])
+ for item in Intersections:
NewPcd1 = (item[0] + '_' + i, item[1])
NewPcd2 = (item[0] + '_' + j, item[1])
if item not in GlobalData.MixedPcd:
@@ -497,8 +491,8 @@ class WorkspaceAutoGen(AutoGen):
for i in SourcePcdDict_Keys:
for j in BinaryPcdDict_Keys:
if i != j:
- IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))
- for item in IntersectionList:
+ Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j])
+ for item in Intersections:
NewPcd1 = (item[0] + '_' + i, item[1])
NewPcd2 = (item[0] + '_' + j, item[1])
if item not in GlobalData.MixedPcd:
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 3/3] BaseTools: small cleanup
2018-04-04 20:56 [PATCH v1 0/3] BaseTools: refactor and cleanup Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 1/3] BaseTools: move RegEx to root of file and share it Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 2/3] BaseTools: Autogen - change from list to set Jaben Carsey
@ 2018-04-04 20:56 ` Jaben Carsey
2018-04-08 8:20 ` [PATCH v1 0/3] BaseTools: refactor and cleanup Zhu, Yonghong
3 siblings, 0 replies; 5+ messages in thread
From: Jaben Carsey @ 2018-04-04 20:56 UTC (permalink / raw)
To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu
just deleting else: then pass as they have no effect.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/AutoGen/AutoGen.py | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index b4575bcb8436..82bca531a178 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -399,11 +399,6 @@ class WorkspaceAutoGen(AutoGen):
for Arch in self.ArchList:
Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
-
-
-
-
-
SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}
BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}
SourcePcdDict_Keys = SourcePcdDict.keys()
@@ -462,8 +457,6 @@ class WorkspaceAutoGen(AutoGen):
"Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),
ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections])
)
- else:
- pass
#
# intersection the BinaryPCD for Mixed PCD
@@ -482,8 +475,6 @@ class WorkspaceAutoGen(AutoGen):
GlobalData.MixedPcd[item].append(NewPcd1)
if NewPcd2 not in GlobalData.MixedPcd[item]:
GlobalData.MixedPcd[item].append(NewPcd2)
- else:
- pass
#
# intersection the SourcePCD and BinaryPCD for Mixed PCD
@@ -502,8 +493,6 @@ class WorkspaceAutoGen(AutoGen):
GlobalData.MixedPcd[item].append(NewPcd1)
if NewPcd2 not in GlobalData.MixedPcd[item]:
GlobalData.MixedPcd[item].append(NewPcd2)
- else:
- pass
for BuildData in PGen.BuildDatabase._CACHE_.values():
if BuildData.Arch != Arch:
@@ -524,11 +513,7 @@ class WorkspaceAutoGen(AutoGen):
del BuildData.Pcds[key]
BuildData.Pcds[newkey] = Value
break
- else:
- pass
break
- else:
- pass
# handle the mixed pcd in FDF file
for key in PcdSet:
--
2.16.2.windows.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 0/3] BaseTools: refactor and cleanup
2018-04-04 20:56 [PATCH v1 0/3] BaseTools: refactor and cleanup Jaben Carsey
` (2 preceding siblings ...)
2018-04-04 20:56 ` [PATCH v1 3/3] BaseTools: small cleanup Jaben Carsey
@ 2018-04-08 8:20 ` Zhu, Yonghong
3 siblings, 0 replies; 5+ messages in thread
From: Zhu, Yonghong @ 2018-04-08 8:20 UTC (permalink / raw)
To: Carsey, Jaben, edk2-devel@lists.01.org
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Best Regards,
Zhu Yonghong
-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Thursday, April 05, 2018 4:57 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 0/3] BaseTools: refactor and cleanup
no real functional change. just code cleanup.
Jaben Carsey (3):
BaseTools: move RegEx to root of file and share it
BaseTools: Autogen - change from list to set
BaseTools: small cleanup
BaseTools/Source/Python/AutoGen/AutoGen.py | 51 ++++++--------------
BaseTools/Source/Python/Common/Expression.py | 4 +-
BaseTools/Source/Python/Common/RangeExpression.py | 5 +-
3 files changed, 19 insertions(+), 41 deletions(-)
--
2.16.2.windows.1
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-08 8:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-04 20:56 [PATCH v1 0/3] BaseTools: refactor and cleanup Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 1/3] BaseTools: move RegEx to root of file and share it Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 2/3] BaseTools: Autogen - change from list to set Jaben Carsey
2018-04-04 20:56 ` [PATCH v1 3/3] BaseTools: small cleanup Jaben Carsey
2018-04-08 8:20 ` [PATCH v1 0/3] BaseTools: refactor and cleanup Zhu, Yonghong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox