Paste Code
Paste Blends
Paste Images
#!/usr/bin/env python

# $Id:
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Contributor(s): Campbell Barton
#
# ***** END GPL LICENSE BLOCK *****

# <pep8 compliant>

import os
from os.path import join, dirname, normpath, abspath, splitext, relpath, exists

base = join(os.path.dirname(__file__), "..", "..")
base = normpath(base)
base = abspath(base)

SIMPLE_PROJECTFILE = False


def source_list(path, filename_check=None):
for dirpath, dirnames, filenames in os.walk(path):

# skip '.svn'
if dirpath.startswith("."):
continue

for filename in filenames:
filepath = join(dirpath, filename)
if filename_check is None or filename_check(filepath):
yield filepath


# extension checking
def is_cmake(filename):
ext = splitext(filename)[1]
return (ext == ".cmake") or (filename == "CMakeLists.txt")


def is_c_header(filename):
ext = splitext(filename)[1]
return (ext in (".h", ".hpp", ".hxx"))


def is_c(filename):
ext = splitext(filename)[1]
return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc"))


def is_c_any(filename):
return is_c(filename) or is_c_header(filename)


def is_svn_file(filename):
dn, fn = os.path.split(filename)
filename_svn = join(dn, ".svn", "text-base", "%s.svn-base" % fn)
return exists(filename_svn)


def is_project_file(filename):
return (is_c_any(filename) or is_cmake(filename)) # and is_svn_file(filename)


def cmake_advanced_info():
""" Extracr includes and defines from cmake.
"""

def create_eclipse_project(cmake_dir):
cmd = 'cmake %r -G"Eclipse CDT4 - Unix Makefiles"' % cmake_dir
os.system(cmd)

includes = []
defines = []

import os
import sys

cmake_dir = sys.argv[-1]

if not os.path.join(cmake_dir, "CMakeCache.txt"):
cmake_dir = os.getcwd()
if not os.path.join(cmake_dir, "CMakeCache.txt"):
print("CMakeCache.txt not found in %r or %r\n Pass CMake build dir as an argument, or run from that dir, abording" % (cmake_dir, os.getcwd()))
sys.exit(1)

# create_eclipse_project(cmake_dir)

from xml.dom.minidom import parse
tree = parse(os.path.join(cmake_dir, ".cproject"))
'''
f = open(".cproject_pretty", 'w')
f.write(tree.toprettyxml(indent=" ", newl=""))
'''
ELEMENT_NODE = tree.ELEMENT_NODE

cproject, = tree.getElementsByTagName("cproject")
for storage in cproject.childNodes:
if storage.nodeType != ELEMENT_NODE:
continue

if storage.attributes["moduleId"].value == "org.eclipse.cdt.core.settings":
cconfig = storage.getElementsByTagName("cconfiguration")[0]
for substorage in cconfig.childNodes:
if substorage.nodeType != ELEMENT_NODE:
continue

moduleId = substorage.attributes["moduleId"].value

# org.eclipse.cdt.core.settings
# org.eclipse.cdt.core.language.mapping
# org.eclipse.cdt.core.externalSettings
# org.eclipse.cdt.core.pathentry
# org.eclipse.cdt.make.core.buildtargets

if moduleId == "org.eclipse.cdt.core.pathentry":
for path in substorage.childNodes:
if path.nodeType != ELEMENT_NODE:
continue
kind = path.attributes["kind"].value

if kind == "mac":
# <pathentry kind="mac" name="PREFIX" path="" value="&quot;/opt/blender25&quot;"/>
defines.append((path.attributes["name"].value, path.attributes["value"].value))
elif kind == "inc":
# <pathentry include="/data/src/blender/blender/source/blender/editors/include" kind="inc" path="" system="true"/>
includes.append(path.attributes["include"].value)
else:
pass

return includes, defines


def main():
files = list(source_list(base, filename_check=is_project_file))
files_rel = [relpath(f, start=base) for f in files]
files_rel.sort()

# --- qtcreator spesific, simple format
if SIMPLE_PROJECTFILE:
# --- qtcreator spesific, simple format
PROJECT_NAME = "Blender"
f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
f.write("\n".join(files_rel))

f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
f.write("\n".join(sorted(list(set(dirname(f) for f in files_rel if is_c_header(f))))))

qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
f = open(qtc_prj, 'w')
f.write("[General]\n")

qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
if not exists(qtc_cfg):
f = open(qtc_cfg, 'w')
f.write("// ADD PREDEFINED MACROS HERE!\n")
else:
includes, defines = cmake_advanced_info()

# for some reason it doesnt give all internal includes
includes = list(set(includes) | set(dirname(f) for f in files_rel if is_c_header(f)))
includes.sort()


PROJECT_NAME = "Blender"
f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
f.write("\n".join(files_rel))

f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
f.write("\n".join(sorted(includes)))

qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
f = open(qtc_prj, 'w')
f.write("[General]\n")

qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
f = open(qtc_cfg, 'w')
f.write("// ADD PREDEFINED MACROS HERE!\n")
f.write("\n".join([("#define %s %s" % item) for item in defines]))

print("Project file written to: %s" % qtc_prj)
# --- end

if __name__ == "__main__":
main()
  1. #!/usr/bin/env python
  2.  
  3. # $Id:
  4. # ***** BEGIN GPL LICENSE BLOCK *****
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. #
  20. # Contributor(s): Campbell Barton
  21. #
  22. # ***** END GPL LICENSE BLOCK *****
  23.  
  24. # <pep8 compliant>
  25.  
  26. import os
  27. from os.path import join, dirname, normpath, abspath, splitext, relpath, exists
  28.  
  29. base = join(os.path.dirname(__file__), "..", "..")
  30. base = normpath(base)
  31. base = abspath(base)
  32.  
  33. SIMPLE_PROJECTFILE = False
  34.  
  35.  
  36. def source_list(path, filename_check=None):
  37.     for dirpath, dirnames, filenames in os.walk(path):
  38.  
  39.         # skip '.svn'
  40.         if dirpath.startswith("."):
  41.             continue
  42.  
  43.         for filename in filenames:
  44.             filepath = join(dirpath, filename)
  45.             if filename_check is None or filename_check(filepath):
  46.                 yield filepath
  47.  
  48.  
  49. # extension checking
  50. def is_cmake(filename):
  51.     ext = splitext(filename)[1]
  52.     return (ext == ".cmake") or (filename == "CMakeLists.txt")
  53.  
  54.  
  55. def is_c_header(filename):
  56.     ext = splitext(filename)[1]
  57.     return (ext in (".h", ".hpp", ".hxx"))
  58.  
  59.  
  60. def is_c(filename):
  61.     ext = splitext(filename)[1]
  62.     return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc"))
  63.  
  64.  
  65. def is_c_any(filename):
  66.     return is_c(filename) or is_c_header(filename)
  67.  
  68.  
  69. def is_svn_file(filename):
  70.     dn, fn = os.path.split(filename)
  71.     filename_svn = join(dn, ".svn", "text-base", "%s.svn-base" % fn)
  72.     return exists(filename_svn)
  73.  
  74.  
  75. def is_project_file(filename):
  76.     return (is_c_any(filename) or is_cmake(filename)) # and is_svn_file(filename)
  77.  
  78.  
  79. def cmake_advanced_info():
  80.     """ Extracr includes and defines from cmake.
  81.    """
  82.  
  83.     def create_eclipse_project(cmake_dir):
  84.         cmd = 'cmake %r -G"Eclipse CDT4 - Unix Makefiles"' % cmake_dir
  85.         os.system(cmd)
  86.  
  87.     includes = []
  88.     defines = []
  89.  
  90.     import os
  91.     import sys
  92.  
  93.     cmake_dir = sys.argv[-1]
  94.  
  95.     if not os.path.join(cmake_dir, "CMakeCache.txt"):
  96.         cmake_dir = os.getcwd()
  97.     if not os.path.join(cmake_dir, "CMakeCache.txt"):
  98.         print("CMakeCache.txt not found in %r or %r\n    Pass CMake build dir as an argument, or run from that dir, abording" % (cmake_dir, os.getcwd()))
  99.         sys.exit(1)
  100.  
  101.     # create_eclipse_project(cmake_dir)
  102.  
  103.     from xml.dom.minidom import parse
  104.     tree = parse(os.path.join(cmake_dir, ".cproject"))
  105.     '''
  106.    f = open(".cproject_pretty", 'w')
  107.    f.write(tree.toprettyxml(indent="    ", newl=""))
  108.    '''
  109.     ELEMENT_NODE = tree.ELEMENT_NODE
  110.  
  111.     cproject, = tree.getElementsByTagName("cproject")
  112.     for storage in cproject.childNodes:
  113.         if storage.nodeType != ELEMENT_NODE:
  114.             continue
  115.  
  116.         if storage.attributes["moduleId"].value == "org.eclipse.cdt.core.settings":
  117.             cconfig = storage.getElementsByTagName("cconfiguration")[0]
  118.             for substorage in cconfig.childNodes:
  119.                 if substorage.nodeType != ELEMENT_NODE:
  120.                     continue
  121.  
  122.                 moduleId = substorage.attributes["moduleId"].value
  123.  
  124.                 # org.eclipse.cdt.core.settings
  125.                 # org.eclipse.cdt.core.language.mapping
  126.                 # org.eclipse.cdt.core.externalSettings
  127.                 # org.eclipse.cdt.core.pathentry
  128.                 # org.eclipse.cdt.make.core.buildtargets
  129.  
  130.                 if moduleId == "org.eclipse.cdt.core.pathentry":
  131.                     for path in substorage.childNodes:
  132.                         if path.nodeType != ELEMENT_NODE:
  133.                             continue
  134.                         kind = path.attributes["kind"].value
  135.  
  136.                         if kind == "mac":
  137.                             # <pathentry kind="mac" name="PREFIX" path="" value="&quot;/opt/blender25&quot;"/>
  138.                             defines.append((path.attributes["name"].value, path.attributes["value"].value))
  139.                         elif kind == "inc":
  140.                             # <pathentry include="/data/src/blender/blender/source/blender/editors/include" kind="inc" path="" system="true"/>
  141.                             includes.append(path.attributes["include"].value)
  142.                         else:
  143.                             pass
  144.  
  145.     return includes, defines
  146.  
  147.  
  148. def main():
  149.     files = list(source_list(base, filename_check=is_project_file))
  150.     files_rel = [relpath(f, start=base) for f in files]
  151.     files_rel.sort()
  152.  
  153.     # --- qtcreator spesific, simple format
  154.     if SIMPLE_PROJECTFILE:
  155.         # --- qtcreator spesific, simple format
  156.         PROJECT_NAME = "Blender"
  157.         f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
  158.         f.write("\n".join(files_rel))
  159.  
  160.         f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
  161.         f.write("\n".join(sorted(list(set(dirname(f) for f in files_rel if is_c_header(f))))))
  162.  
  163.         qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
  164.         f = open(qtc_prj, 'w')
  165.         f.write("[General]\n")
  166.  
  167.         qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
  168.         if not exists(qtc_cfg):
  169.             f = open(qtc_cfg, 'w')
  170.             f.write("// ADD PREDEFINED MACROS HERE!\n")
  171.     else:
  172.         includes, defines = cmake_advanced_info()
  173.  
  174.         # for some reason it doesnt give all internal includes
  175.         includes = list(set(includes) | set(dirname(f) for f in files_rel if is_c_header(f)))
  176.         includes.sort()
  177.  
  178.  
  179.         PROJECT_NAME = "Blender"
  180.         f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
  181.         f.write("\n".join(files_rel))
  182.  
  183.         f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
  184.         f.write("\n".join(sorted(includes)))
  185.  
  186.         qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
  187.         f = open(qtc_prj, 'w')
  188.         f.write("[General]\n")
  189.  
  190.         qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
  191.         f = open(qtc_cfg, 'w')
  192.         f.write("// ADD PREDEFINED MACROS HERE!\n")
  193.         f.write("\n".join([("#define %s %s" % item) for item in defines]))
  194.  
  195.     print("Project file written to: %s" % qtc_prj)
  196.     # --- end
  197.  
  198. if __name__ == "__main__":
  199.     main()
  200.  
go to heaven