From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AC8BF2194D3B8 for ; Sat, 2 Feb 2019 21:55:26 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Feb 2019 21:55:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,555,1539673200"; d="scan'208";a="296864409" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.47]) by orsmga005.jf.intel.com with ESMTP; 02 Feb 2019 21:55:25 -0800 From: "Feng, Bob C" To: edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao Date: Sun, 3 Feb 2019 13:55:13 +0800 Message-Id: <20190203055515.18336-2-bob.c.feng@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 In-Reply-To: <20190203055515.18336-1-bob.c.feng@intel.com> References: <20190203055515.18336-1-bob.c.feng@intel.com> MIME-Version: 1.0 Subject: [Patch 1/3] BaseTools: Implement splitquoted function in Build tool X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Feb 2019 05:55:26 -0000 Content-Transfer-Encoding: 8bit https://bugzilla.tianocore.org/show_bug.cgi?id=1509 On some Linux environment, there may be no distutils.util library for python3 that will cause build tool crash. This patch implement distutils.util.split_quoted in BaseTools so that the build tool will be independent with distutils.util library. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- BaseTools/Source/Python/AutoGen/UniClassObject.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index d162387cc5..c4b39d25d4 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -16,11 +16,10 @@ ## # Import Modules # from __future__ import print_function import Common.LongFilePathOs as os, codecs, re -import distutils.util import Common.EdkLogger as EdkLogger from io import BytesIO from Common.BuildToolError import * from Common.StringUtils import GetLineNo from Common.Misc import PathClass @@ -41,11 +40,11 @@ NON_BREAKING_CHAR = u'\uFFF2' CR = u'\u000D' LF = u'\u000A' NULL = u'\u0000' TAB = u'\t' BACK_SLASH_PLACEHOLDER = u'\u0006' - +WHITESPACE = ' \t\n\r\v\f' gIncludePattern = re.compile("^#include +[\"<]+([^\"< >]+)[>\"]+$", re.MULTILINE | re.UNICODE) ## Convert a unicode string to a Hex list # # Convert a unicode string to a Hex list @@ -216,10 +215,54 @@ def StripComments(Line): CommentPos = Line.find (Comment, CommentPos + 1) else: return Line[:CommentPos].strip() return Line.strip() +# +# This function implement distutils.util.split_quoted in another way. +# +def splitquoted(s): + words = [] + word = [] + InQuoted = False + escaped = False + CurrentQ = "" + s = s.strip() + for ch in s: + if escaped: + # preserve whatever is escaped; + # This char will become part of the current word + word.append(ch) + escaped = False + continue + + if ch in WHITESPACE and not InQuoted: + # unescaped, unquoted whitespace: now + # we definitely have a word delimiter + if "".join(word): + words.append("".join(word)) + word = [] + continue + elif ch == "\\": + escaped = True + if not InQuoted: + continue + else: + # handle singly-quoted string or doubly-quoted string + if ch =='"' or ch == "'": + if not InQuoted: + InQuoted = True + CurrentQ = ch + continue + elif ch == CurrentQ: + InQuoted = False + continue + word.append(ch) + if word: + words.append("".join(word)) + return words + ## UniFileClassObject # # A structure for .uni file definition # class UniFileClassObject(object): @@ -232,16 +275,15 @@ class UniFileClassObject(object): self.OrderedStringListByToken = {} #{ u'LanguageIdentifier' : {Token: StringDefClassObject} } self.IsCompatibleMode = IsCompatibleMode self.IncludePathList = IncludePathList if len(self.FileList) > 0: self.LoadUniFiles(FileList) - # # Get Language definition # def GetLangDef(self, File, Line): - Lang = distutils.util.split_quoted((Line.split(u"//")[0])) + Lang = splitquoted((Line.split(u"//")[0])) if len(Lang) != 3: try: FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError as X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File); -- 2.20.1.windows.1