Răsfoiți Sursa

Merge pull request #1558 from armink/fix_scons

Fix scons
Bernard Xiong 6 ani în urmă
părinte
comite
fdc350b763
2 a modificat fișierele cu 62 adăugiri și 20 ștergeri
  1. 59 17
      tools/building.py
  2. 3 3
      tools/iar.py

+ 59 - 17
tools/building.py

@@ -112,6 +112,35 @@ class Win32Spawn:
 
         return proc.wait()
 
+# auto fix the 'RTT_CC' and 'RTT_EXEC_PATH'
+# when using 'scons --target=cc' the 'RTT_CC' will set to 'cc'
+# it will fix the the 'rtconfig.EXEC_PATH' when get it failed.
+# NOTE: this function will changed your env. Please backup the env before used it.
+def AutoFixRttCCAndExecPath():
+    import rtconfig
+    target_option = None
+
+    # get --target=cc option
+    if len(sys.argv) > 1:
+        option = sys.argv[1].split('=')
+        if len(option) > 1 and option[0] == '--target':
+            target_option = option[1]
+
+    # force change the 'RTT_CC' when using 'scons --target=cc'
+    if target_option:
+        if target_option == 'mdk' or target_option == 'mdk4' or target_option == 'mdk5':
+            os.environ['RTT_CC'] = 'keil'
+        elif target_option == 'iar':
+            os.environ['RTT_CC'] = 'iar'
+
+    # auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed
+    reload(rtconfig)
+    if not os.path.exists(rtconfig.EXEC_PATH):
+        if os.environ['RTT_EXEC_PATH']:
+            # del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
+            del os.environ['RTT_EXEC_PATH']
+            reload(rtconfig)
+
 def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
     import SCons.cpp
     import rtconfig
@@ -130,6 +159,9 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
 
     sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
 
+    # auto fix the 'RTT_CC' and 'RTT_EXEC_PATH'
+    AutoFixRttCCAndExecPath()
+
     # add compability with Keil MDK 4.6 which changes the directory of armcc.exe
     if rtconfig.PLATFORM == 'armcc':
         if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
@@ -709,18 +741,8 @@ def DoBuilding(target, objects):
         program = Env.Program(target, objects)
 
     EndBuilding(target, program)
-
-def EndBuilding(target, program = None):
-    import rtconfig
-
-    Env['target']  = program
-    Env['project'] = Projects
-
-    Env.AddPostAction(target, rtconfig.POST_ACTION)
-    # Add addition clean files
-    Clean(target, 'cconfig.h')
-    Clean(target, 'rtua.py')
-    Clean(target, 'rtua.pyc')
+        
+def GenTargetProject(program = None):
 
     if GetOption('target') == 'mdk':
         from keil import MDKProject
@@ -777,27 +799,47 @@ def EndBuilding(target, program = None):
         from cdk import CDKProject
         CDKProject('project.cdkproj', Projects)
 
+def EndBuilding(target, program = None):
+    import rtconfig
+
+    need_exit = False
+
+    Env['target']  = program
+    Env['project'] = Projects
+
+    Env.AddPostAction(target, rtconfig.POST_ACTION)
+    # Add addition clean files
+    Clean(target, 'cconfig.h')
+    Clean(target, 'rtua.py')
+    Clean(target, 'rtua.pyc')
+
+    if GetOption('target'):
+        GenTargetProject(program)
+
     BSP_ROOT = Dir('#').abspath
     if GetOption('copy') and program != None:
         from mkdist import MakeCopy
         MakeCopy(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('copy-header') and program != None:
         from mkdist import MakeCopyHeader
         MakeCopyHeader(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('make-dist') and program != None:
         from mkdist import MkDist
         MkDist(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('cscope'):
         from cscope import CscopeDatabase
         CscopeDatabase(Projects)
 
     if not GetOption('help') and not GetOption('target'):
         if not os.path.exists(rtconfig.EXEC_PATH):
-            print "Error: Toolchain path (%s) is not exist, please check 'EXEC_PATH' in path or rtconfig.py." % rtconfig.EXEC_PATH
-            sys.exit(1)
+            print "Error: the toolchain path (%s) is not exist, please check 'EXEC_PATH' in path or rtconfig.py." % rtconfig.EXEC_PATH
+            need_exit = True
+
+    if need_exit:
+        exit(0)
 
 def SrcRemove(src, remove):
     if not src:

+ 3 - 3
tools/iar.py

@@ -164,7 +164,7 @@ def IARVersion():
     def IARPath():
         import rtconfig
 
-        # set environ
+        # backup environ
         old_environ = os.environ
         os.environ['RTT_CC'] = 'iar'
         reload(rtconfig)
@@ -183,11 +183,11 @@ def IARVersion():
     if os.path.exists(path):
         cmd = os.path.join(path, 'iccarm.exe')
     else:
-        print('Get IAR version error. Please update IAR installation path in rtconfig.h!')
+        print('Error: get IAR version failed. Please update the IAR installation path in rtconfig.py!')
         return "0.0"
 
     child = subprocess.Popen([cmd, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
     stdout, stderr = child.communicate()
 
     # example stdout: IAR ANSI C/C++ Compiler V8.20.1.14183/W32 for ARM
-    return re.search('[\d\.]+', stdout).group(0)
+    return re.search('[\d\.]+', stdout).group(0)