]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/MultipleWorkspace.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / Common / MultipleWorkspace.py
index 8088404f30eb2941e50409946f71123225cd3aea..81594e22cd9feaf746950101148446aec43bd816 100644 (file)
@@ -4,7 +4,7 @@
 # This file is required to make Python interpreter treat the directory\r
 # as containing package.\r
 #\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,16 +20,16 @@ from Common.DataType import TAB_WORKSPACE
 ## MultipleWorkspace\r
 #\r
 # This class manage multiple workspace behavior\r
-# \r
+#\r
 # @param class:\r
 #\r
 # @var WORKSPACE:      defined the current WORKSPACE\r
 # @var PACKAGES_PATH:  defined the other WORKSAPCE, if current WORKSPACE is invalid, search valid WORKSPACE from PACKAGES_PATH\r
-# \r
+#\r
 class MultipleWorkspace(object):\r
     WORKSPACE = ''\r
     PACKAGES_PATH = None\r
-    \r
+\r
     ## convertPackagePath()\r
     #\r
     #   Convert path to match workspace.\r
@@ -41,7 +41,7 @@ class MultipleWorkspace(object):
     @classmethod\r
     def convertPackagePath(cls, Ws, Path):\r
         if str(os.path.normcase (Path)).startswith(Ws):\r
-            return os.path.join(Ws, Path[len(Ws) + 1:])\r
+            return os.path.join(Ws, os.path.relpath(Path, Ws))\r
         return Path\r
 \r
     ## setWs()\r
@@ -59,7 +59,7 @@ class MultipleWorkspace(object):
             cls.PACKAGES_PATH = [cls.convertPackagePath (Ws, os.path.normpath(Path.strip())) for Path in PackagesPath.split(os.pathsep)]\r
         else:\r
             cls.PACKAGES_PATH = []\r
-    \r
+\r
     ## join()\r
     #\r
     #   rewrite os.path.join function\r
@@ -79,7 +79,7 @@ class MultipleWorkspace(object):
                     return Path\r
             Path = os.path.join(Ws, *p)\r
         return Path\r
-    \r
+\r
     ## relpath()\r
     #\r
     #   rewrite os.path.relpath function\r
@@ -98,7 +98,7 @@ class MultipleWorkspace(object):
         if Path.lower().startswith(Ws.lower()):\r
             Path = os.path.relpath(Path, Ws)\r
         return Path\r
-    \r
+\r
     ## getWs()\r
     #\r
     #   get valid workspace for the path\r
@@ -117,7 +117,7 @@ class MultipleWorkspace(object):
                 if os.path.exists(absPath):\r
                     return Pkg\r
         return Ws\r
-    \r
+\r
     ## handleWsMacro()\r
     #\r
     #   handle the $(WORKSPACE) tag, if current workspace is invalid path relative the tool, replace it.\r
@@ -128,14 +128,22 @@ class MultipleWorkspace(object):
     @classmethod\r
     def handleWsMacro(cls, PathStr):\r
         if TAB_WORKSPACE in PathStr:\r
-            Path = PathStr.replace(TAB_WORKSPACE, cls.WORKSPACE).strip()\r
-            if not os.path.exists(Path):\r
-                for Pkg in cls.PACKAGES_PATH:\r
-                    Path = PathStr.replace(TAB_WORKSPACE, Pkg).strip()\r
-                    if os.path.exists(Path):\r
-                        return Path\r
+            PathList = PathStr.split()\r
+            if PathList:\r
+                for i, str in enumerate(PathList):\r
+                    MacroStartPos = str.find(TAB_WORKSPACE)\r
+                    if MacroStartPos != -1:\r
+                        Substr = str[MacroStartPos:]\r
+                        Path = Substr.replace(TAB_WORKSPACE, cls.WORKSPACE).strip()\r
+                        if not os.path.exists(Path):\r
+                            for Pkg in cls.PACKAGES_PATH:\r
+                                Path = Substr.replace(TAB_WORKSPACE, Pkg).strip()\r
+                                if os.path.exists(Path):\r
+                                    break\r
+                        PathList[i] = str[0:MacroStartPos] + Path\r
+            PathStr = ' '.join(PathList)\r
         return PathStr\r
-    \r
+\r
     ## getPkgPath()\r
     #\r
     #   get all package pathes.\r
@@ -145,4 +153,4 @@ class MultipleWorkspace(object):
     @classmethod\r
     def getPkgPath(cls):\r
         return cls.PACKAGES_PATH\r
-            
\ No newline at end of file
+\r