From ae04ee82dce191a3823cd35427ac928a7e14298f Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Thu, 22 May 2014 16:07:45 +0000
Subject: [PATCH] Support absolute and local build_dir. Added
 create_lib_order_files().

---
 tools/oneclick/base/hdl_config.py | 44 ++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/tools/oneclick/base/hdl_config.py b/tools/oneclick/base/hdl_config.py
index f342ecf6e4..e3457bd43c 100644
--- a/tools/oneclick/base/hdl_config.py
+++ b/tools/oneclick/base/hdl_config.py
@@ -55,8 +55,10 @@ import os.path
 
 class HdlConfig:
 
-    def __init__(self, libRootDir, toolRootDir='', libFileName='hdllib.cfg', toolFileName='hdltool.cfg'):
+    def __init__(self, libRootDir, toolRootDir, libFileName='hdllib.cfg', toolFileName='hdltool.cfg'):
         """Get tool dictionary info from toolRootDir and all HDL library dictionary info from libRootDir."""
+        self.libRootDir = libRootDir
+        self.toolRootDir = toolRootDir
         # HDL tool config file
         self.tool = common_dict_file.CommonDictFile(toolRootDir, toolFileName)      # tool dict file
         if self.tool.nof_dicts==0: sys.exit('Error : No HDL tool config file found')
@@ -86,7 +88,7 @@ class HdlConfig:
         if lib_names==None: lib_names=self.lib_names
         lib_dicts = self.libs.get_dicts('hdl_lib_name', lib_names)
         lib_order = []
-        for lib_dict in lib_dicts:
+        for lib_dict in cm.listify(lib_dicts):
             lib_name = lib_dict['hdl_lib_name']
             if not lib_name in lib_order:
                 lib_order.append(lib_name)                                        # append this lib
@@ -102,22 +104,46 @@ class HdlConfig:
         return lib_order
 
     def get_lib_build_sim_dirs(self, lib_dicts=None):
-        """Get the simulation build directory for all HDL libraries in the specified list of lib_dicts."""
+        """Get the simulation build directory for all HDL libraries in the specified list of lib_dicts.
+        
+        If key 'build_dir' in HDL library config file is '' then
+            define build dir by 'sim_tool_name' local to current HDL library directory.
+        else
+            define build dir by 'sim_tool_name' local to 'build_dir' directory.
+        """
         if lib_dicts==None: lib_dicts=self.libs.dicts
         sim_dirs = []
         for lib_dict in cm.listify(lib_dicts):
             lib_path = self.libs.get_filePath(lib_dict)
-            build_dir = self.libs.get_key_values('build_dir', lib_dict)
-            sim_tool = self.tool.get_key_values('sim_tool')
-            sim_dirs.append(os.path.join(lib_path, build_dir, sim_tool))
+            build_dir = os.path.expandvars(self.libs.get_key_values('build_dir', lib_dict))
+            sim_tool_name = self.tool.get_key_values('sim_tool_name')
+            if build_dir=='':
+                sim_dirs.append(os.path.join(lib_path, build_dir, sim_tool_name))
+            else:
+                sim_dirs.append(os.path.join(lib_path, build_dir, sim_tool_name))
         return cm.unlistify(sim_dirs)
 
+    def create_lib_order_files(self, lib_names=None):
+        """Create the Modelsim project file for all HDL libraries in the specified list of lib_names."""
+        if lib_names==None: lib_names=self.lib_names
+        lib_dicts = self.libs.get_dicts('hdl_lib_name', lib_names)
+        for lib_dict in cm.listify(lib_dicts):
+            lib_name = lib_dict['hdl_lib_name']
+            use_libs = self.derive_all_use_libs(lib_name)
+            lib_order = self.derive_lib_order(use_libs)
+            file_name = 'hdllib_order.txt'
+            file_path = self.get_lib_build_sim_dirs(lib_dict)
+            cm.mkdir(file_path)
+            filePathName = os.path.join(file_path, file_name)
+            with open(filePathName, 'w') as fp:
+            	  for lib in lib_order:
+                    fp.write('%s\n' % lib)
 
 if __name__ == '__main__':
     # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
     libRootDir = 'RADIOHDL'
     #libRootDir = 'UNB'
-    hdl = HdlConfig(libRootDir=os.environ[libRootDir], toolRootDir=os.environ['UNB'], libFileName='hdllib.cfg', toolFileName='hdltool.cfg')
+    hdl = HdlConfig(libRootDir=os.environ[libRootDir], toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool.cfg')
 
     print '#'
     print '# HdlConfig:'
@@ -151,6 +177,10 @@ if __name__ == '__main__':
     for sim_dir in hdl.get_lib_build_sim_dirs():
         print '    ', sim_dir
 
+    print ''
+    print 'create_lib_order_files'
+    hdl.create_lib_order_files()
+    
     print ''    
     if libRootDir=='RADIOHDL':
         print 'derive_all_use_libs = ', hdl.derive_lib_order(hdl.derive_all_use_libs('technology_memory'))
-- 
GitLab