From 742a08244c87b18050bfcd4560b2c50737e76206 Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Tue, 19 Apr 2016 10:23:28 +0000
Subject: [PATCH] Moved arg parser before mode selection. Rename
 arg_toolFileName.

---
 tools/oneclick/base/hdl_config.py      | 46 +++++++++++++-------------
 tools/oneclick/base/modelsim_config.py | 38 ++++++++++-----------
 tools/oneclick/base/quartus_config.py  |  4 +--
 3 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/tools/oneclick/base/hdl_config.py b/tools/oneclick/base/hdl_config.py
index c4536ea986..fa984a4856 100644
--- a/tools/oneclick/base/hdl_config.py
+++ b/tools/oneclick/base/hdl_config.py
@@ -337,26 +337,26 @@ if __name__ == '__main__':
     # 5 = Remove a new key = value pair from all hdllib.cfg dict files
     mode = 0
     
-    if mode==0:   
-        # Parse command line arguments
-        toolsetSelect = ['unb1', 'unb2', 'unb2a']
+    # Parse command line arguments
+    toolsetSelect = ['unb1', 'unb2', 'unb2a']
 
-        argparser = argparse.ArgumentParser(description='Derive HDL library dictionary from hdllib.cfg')
-        argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False)
-        argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False)
-        args = vars(argparser.parse_args())
+    argparser = argparse.ArgumentParser(description='Derive HDL library dictionary from hdllib.cfg')
+    argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False)
+    argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False)
+    args = vars(argparser.parse_args())
 
-        arg_toolset   = args['toolset']
-        if arg_toolset not in toolsetSelect:
-            print 'Toolset %s is not supported' % arg_toolset
-            print 'Hint: give argument -h for possible options'
-            sys.exit(1)
-        toolFileName = 'hdltool_' + arg_toolset + '.cfg'
+    arg_toolset   = args['toolset']
+    if arg_toolset not in toolsetSelect:
+        print 'Toolset %s is not supported' % arg_toolset
+        print 'Hint: give argument -h for possible options'
+        sys.exit(1)
+    arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg'
 
-        arg_verbosity = args['verbosity']
-        
+    arg_verbosity = args['verbosity']
+    
+    if mode==0:   
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=toolFileName)
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         print '#'
         print '# HdlConfig:'
         print '#'
@@ -423,7 +423,7 @@ if __name__ == '__main__':
         key = 'build_dir'
         new_value = '$HDL_BUILD_DIR'
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool_unb1.cfg')
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         for p in hdl.libs.filePathNames:
              hdl.libs.change_key_value_in_dict_file(p, key, new_value)
 
@@ -432,16 +432,16 @@ if __name__ == '__main__':
         insert_value = ''
         insertLineNr = 4
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool_unb1.cfg')
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         for p in hdl.libs.filePathNames:
              hdl.libs.insert_key_in_dict_file_at_line_number(p, insert_key, insert_value, insertLineNr)
 
     if mode==3:
-        insert_key = 'hdl_lib_uses_sim'
+        insert_key = '[quartus_project_file]'
         insert_value = '\n'
-        insert_beforeKey = 'hdl_lib_technology'
+        insert_beforeKey = 'synth_files'
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool_unb1.cfg')
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         for p in hdl.libs.filePathNames:
              hdl.libs.insert_key_in_dict_file_before_another_key(p, insert_key, insert_value, insert_beforeKey)
 
@@ -449,13 +449,13 @@ if __name__ == '__main__':
         old_key = 'hdl_lib_uses'
         new_key = 'hdl_lib_uses_synth'
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool_unb1.cfg')
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         for p in hdl.libs.filePathNames:
              hdl.libs.rename_key_in_dict_file(p, old_key, new_key)
              
     if mode==5:
         remove_key = 'modelsim_search_libraries'
         # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName='hdltool_unb1.cfg')
+        hdl = HdlConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         for p in hdl.libs.filePathNames:
              hdl.libs.remove_key_from_dict_file(p, remove_key)
diff --git a/tools/oneclick/base/modelsim_config.py b/tools/oneclick/base/modelsim_config.py
index 0aa945dee8..f18c830308 100755
--- a/tools/oneclick/base/modelsim_config.py
+++ b/tools/oneclick/base/modelsim_config.py
@@ -210,7 +210,7 @@ class ModelsimConfig(hdl_config.HdlConfig):
                         elif file_ext=='v':
                              project_file_p_defaults_file_specific = project_file_p_defaults_verilog
                         else:
-                             print '\nERROR - Undefined file extension in synth_files:', synth_files[i]
+                             print '\nERROR - Undefined file extension in synth_files:', lib_name, synth_files[i]
                              sys.exit()
 
                         fp.write('Project_File_P_%d = folder %s compile_order %d %s\n' % (offset+i, project_folders[-1], offset+i, project_file_p_defaults_hdl+' '+project_file_p_defaults_file_specific))
@@ -228,7 +228,7 @@ class ModelsimConfig(hdl_config.HdlConfig):
                         elif file_ext=='v':
                              project_file_p_defaults_file_specific = project_file_p_defaults_verilog
                         else:
-                             print '\nERROR - Undefined file extension in test_bench_files:', test_bench_files[i]
+                             print '\nERROR - Undefined file extension in test_bench_files:', lib_name, test_bench_files[i]
                              sys.exit()
 
                         fp.write('Project_File_P_%d = folder %s compile_order %d %s\n' % (offset+i, project_folders[-1], offset+i, project_file_p_defaults_hdl+' '+project_file_p_defaults_file_specific))
@@ -308,28 +308,28 @@ if __name__ == '__main__':
     #     hdllib.cfg. The hdllib.cfg still does need some manual editing to set the proper key and paths.
     mode = 0
     
-    if mode==0:   
-        # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
-
-        # Parse command line arguments
-        toolsetSelect = ['unb1', 'unb2', 'unb2a']
+    # Parse command line arguments
+    toolsetSelect = ['unb1', 'unb2', 'unb2a']
 
-        argparser = argparse.ArgumentParser(description='Create Modelsim mpf files for all hdllib.cfg')
-        argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False)
-        argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False)
-        args = vars(argparser.parse_args())
+    argparser = argparse.ArgumentParser(description='Create Modelsim mpf files for all hdllib.cfg')
+    argparser.add_argument('-t','--toolset', help='choose toolset %s (default: %s)' % (toolsetSelect,toolsetSelect[0]), default=toolsetSelect[0], required=False)
+    argparser.add_argument('-v','--verbosity', help='verbosity >= 0 for more info', type=int, default=0, required=False)
+    args = vars(argparser.parse_args())
 
-        arg_toolset   = args['toolset']
-        if arg_toolset not in toolsetSelect:
-            print 'Toolset %s is not supported' % arg_toolset
-            print 'Hint: give argument -h for possible options'
-            sys.exit(1)
-        toolFileName = 'hdltool_' + arg_toolset + '.cfg'
+    arg_toolset   = args['toolset']
+    if arg_toolset not in toolsetSelect:
+        print 'Toolset %s is not supported' % arg_toolset
+        print 'Hint: give argument -h for possible options'
+        sys.exit(1)
+    arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg'
 
-        arg_verbosity = args['verbosity']
+    arg_verbosity = args['verbosity']
         
+    if mode==0:   
+        # Read the dictionary info from all HDL tool and library configuration files in the current directory and the sub directories
+
         # Create and use msim object
-        msim = ModelsimConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=toolFileName)
+        msim = ModelsimConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         
         if arg_verbosity>=2:
             print '#'
diff --git a/tools/oneclick/base/quartus_config.py b/tools/oneclick/base/quartus_config.py
index 9a46ad5332..8a42c42744 100755
--- a/tools/oneclick/base/quartus_config.py
+++ b/tools/oneclick/base/quartus_config.py
@@ -243,12 +243,12 @@ if __name__ == '__main__':
         print 'Toolset %s is not supported' % arg_toolset
         print 'Hint: give argument -h for possible options'
         sys.exit(1)
-    toolFileName = 'hdltool_' + arg_toolset + '.cfg'
+    arg_toolFileName = 'hdltool_' + arg_toolset + '.cfg'
  
     arg_verbosity = args['verbosity']
       
     # Create and use qsyn object
-    qsyn = QuartusConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=toolFileName)
+    qsyn = QuartusConfig(toolRootDir=os.path.expandvars('$RADIOHDL/tools'), libFileName='hdllib.cfg', toolFileName=arg_toolFileName)
         
     if arg_verbosity>=2:
         print '#'
-- 
GitLab