ソースを参照

[Tools] Fix the walk_children issue

bernard 7 年 前
コミット
3802754f05
4 ファイル変更44 行追加17 行削除
  1. 9 6
      tools/codeblocks.py
  2. 21 0
      tools/utils.py
  3. 7 6
      tools/vs.py
  4. 7 5
      tools/vs2012.py

+ 9 - 6
tools/codeblocks.py

@@ -31,17 +31,20 @@ import xml.etree.ElementTree as etree
 from xml.etree.ElementTree import SubElement
 from utils import _make_path_relative
 from utils import xml_indent
+
+import utils
+
 fs_encoding = sys.getfilesystemencoding()
 
 def CB_AddHeadFiles(program, elem, project_path):
-    building.source_ext = []
-    building.source_ext = ["h"]
+    utils.source_ext = []
+    utils.source_ext = ["h"]
     for item in program:
-        building.walk_children(item)    
-    building.source_list.sort()
-    # print building.source_list
+        utils.walk_children(item)    
+    utils.source_list.sort()
+    # print utils.source_list
     
-    for f in building.source_list:
+    for f in utils.source_list:
         path = _make_path_relative(project_path, f)
         Unit = SubElement(elem, 'Unit')
         Unit.set('filename', path.decode(fs_encoding))

+ 21 - 0
tools/utils.py

@@ -103,3 +103,24 @@ def xml_indent(elem, level=0):
     else:
         if level and (not elem.tail or not elem.tail.strip()):
             elem.tail = i
+
+
+source_ext = ["c", "h", "s", "S", "cpp", "xpm"]
+source_list = []
+
+def walk_children(child):
+    global source_list
+    global source_ext
+
+    # print child
+    full_path = child.rfile().abspath
+    file_type  = full_path.rsplit('.',1)[1]
+    #print file_type
+    if file_type in source_ext:
+        if full_path not in source_list:
+            source_list.append(full_path)
+
+    children = child.all_children()
+    if children != []:
+        for item in children:
+            walk_children(item)

+ 7 - 6
tools/vs.py

@@ -26,6 +26,7 @@ import os
 import sys
 import string
 import building
+import utils
 
 import xml.etree.ElementTree as etree
 from xml.etree.ElementTree import SubElement
@@ -59,14 +60,14 @@ def VS_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
         File.set('RelativePath', path.decode(fs_encoding))
 
 def VS_AddHeadFilesGroup(program, elem, project_path):
-    building.source_ext = []
-    building.source_ext = ["h"]
+    utils.source_ext = []
+    utils.source_ext = ["h"]
     for item in program:
-        building.walk_children(item)    
-    building.source_list.sort()
-    # print building.source_list
+        utils.walk_children(item)    
+    utils.source_list.sort()
+    # print utils.source_list
     
-    for f in building.source_list:
+    for f in utils.source_list:
         path = _make_path_relative(project_path, f)
         File = SubElement(elem, 'File')
         File.set('RelativePath', path.decode(fs_encoding))

+ 7 - 5
tools/vs2012.py

@@ -32,6 +32,8 @@ import xml.etree.ElementTree as etree
 from xml.etree.ElementTree import SubElement
 from utils import _make_path_relative
 from utils import xml_indent
+import utils
+
 fs_encoding = sys.getfilesystemencoding()
 
 #reference
@@ -123,12 +125,12 @@ def VS_add_ItemGroup(parent, file_type, files, project_path):
             ObjName.text = ''.join('$(IntDir)'+objpath+'\\')
 
 def VS_add_HeadFiles(program, elem, project_path):
-    building.source_ext = []
-    building.source_ext = ["h"]
+    utils.source_ext = []
+    utils.source_ext = ["h"]
     for item in program:
-        building.walk_children(item)    
-    building.source_list.sort()
-    # print building.source_list
+        utils.walk_children(item)    
+    utils.source_list.sort()
+    # print utils.source_list
     ItemGroup = SubElement(elem, 'ItemGroup')
 
     filter_h_ItemGroup = SubElement(filter_project, 'ItemGroup')