Ejemplo n.º 1
0
def PrepareUA(project, RTT_ROOT, BSP_ROOT):
    with open('rtua.py', 'w') as ua:
        # ua.write('import os\n')
        # ua.write('import sys\n')
        ua.write('\n')
        
        print RTT_ROOT
        
        CPPPATH = []
        CPPDEFINES = []

        for group in project:
            # get each include path
            if group.has_key('CPPPATH') and group['CPPPATH']:
                CPPPATH += group['CPPPATH']

            # get each group's definitions
            if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
                CPPDEFINES += group['CPPDEFINES']

        if len(CPPPATH):
            # use absolute path 
            for i in range(len(CPPPATH)):
                CPPPATH[i] = os.path.abspath(CPPPATH[i])

            # remove repeat path
            paths = [i for i in set(CPPPATH)]
            CPPPATH = []
            for path in paths:
                if PrefixPath(RTT_ROOT, path):
                    CPPPATH += ['RTT_ROOT + "/%s",' % _make_path_relative(RTT_ROOT, path).replace('\\', '/')]
                
                elif PrefixPath(BSP_ROOT, path):
                    CPPPATH += ['BSP_ROOT + "/%s",' % _make_path_relative(BSP_ROOT, path).replace('\\', '/')]
                else:
                    CPPPATH += ['"%s",' % path.replace('\\', '/')]

            CPPPATH.sort()
            ua.write('def GetCPPPATH(BSP_ROOT, RTT_ROOT):\n')
            ua.write('\tCPPPATH=[\n')
            for path in CPPPATH:
                ua.write('\t\t%s\n' % path)
            ua.write('\t]\n\n')
            ua.write('\treturn CPPPATH\n\n')
        else:
            ua.write('def GetCPPPATH(BSP_ROOT, RTT_ROOT):\n')
            ua.write('\tCPPPATH=[]\n\n')
            ua.write('\treturn CPPPATH\n\n')

        if len(CPPDEFINES):
            CPPDEFINES = [i for i in set(CPPDEFINES)]

            ua.write('def GetCPPDEFINES():\n')
            ua.write('\tCPPDEFINES=%s\n' % str(CPPDEFINES))
            ua.write('\treturn CPPDEFINES\n\n')

        else:
            ua.write('def GetCPPDEFINES():\n')
            ua.write('\tCPPDEFINES=""\n\n')
            ua.write('\treturn CPPDEFINES\n\n')
Ejemplo n.º 2
0
def VS_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
    Filter = SubElement(parent, 'Filter')
    Filter.set('Name', name)  #set group name to group

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)
        try:
            path = path.decode(fs_encoding)
        except:
            path = path
        File = SubElement(Filter, 'File')
        File.set('RelativePath', path)

    for lib in libs:
        name = os.path.basename(lib)
        path = os.path.dirname(lib)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(Filter, 'File')
        try:
            path = path.decode(fs_encoding)
        except:
            path = path
        File.set('RelativePath', path)
Ejemplo n.º 3
0
def Qt_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
    #Filter = SubElement(parent, 'Filter')
    #Filter.set('Name', name) #set group name to group
    
    elem = parent

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        #File = SubElement(Filter, 'File')
        #File.set('RelativePath', path.decode(fs_encoding))
        path = path.decode(fs_encoding)
        elem.write('SOURCES += ' + path + '\r\n')

    for lib in libs:
        name = os.path.basename(lib)
        path = os.path.dirname(lib)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        path = path.decode(fs_encoding)
        elem.write('LIBS += ' + path + '\r\n')
Ejemplo n.º 4
0
 def set_target_config(self):
     info = utils.ProjectInfo(self.env)
     # 1. config src path
     for group in self.project:
         for f in group['src']:
             # use relative path
             path = _make_path_relative(os.getcwd(),
                                        os.path.normpath(f.rfile().abspath))
             self.src_path += "\t\"{0}\",\n".format(path.replace("\\", "/"))
     self.src_path = self.src_path[:-2]
     # 2. config dir path
     for i in info['CPPPATH']:
         # use relative path
         path = _make_path_relative(os.getcwd(), i)
         self.inc_path += "\t\"{0}\",\n".format(path.replace("\\", "/"))
     self.inc_path = self.inc_path[:-2]
     # 3. config cflags
     self.cflags = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
     # 4. config cxxflags
     if 'CXXFLAGS' in dir(rtconfig):
         self.cxxflags = rtconfig.CXXFLAGS.replace('\\', "/").replace(
             '\"', "\\\"")
     else:
         self.cxxflags = self.cflags
     # 5. config asflags
     self.asflags = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
     # 6. config lflags
     self.ldflags = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")
     # 7. config define
     for i in info['CPPDEFINES']:
         self.define += "\t\"{0}\",\n".format(i)
     self.define = self.define[:-2]
Ejemplo n.º 5
0
def RelativeProjectPath(env, path):
    project_root = os.path.abspath(env['BSP_ROOT'])
    rtt_root = os.path.abspath(env['RTT_ROOT'])
    
    if path.startswith(project_root):
        return _make_path_relative(project_root, path)
    
    if path.startswith(rtt_root):
        return 'rt-thread/' + _make_path_relative(rtt_root, path)

    # TODO add others folder
    print('ERROR: the ' + path + 'not support')

    return path
Ejemplo n.º 6
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    from building import Rtt_Root
    RTT_ROOT = os.path.normpath(Rtt_Root)

    file_dict = {'C':"ClCompile", 'H':'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        objpath = path.lower()
        if len(project_path) >= len(RTT_ROOT) :
            if objpath.startswith(project_path.lower()) :
                objpath = ''.join('bsp'+objpath[len(project_path):])
            else :
                objpath = ''.join('kernel'+objpath[len(RTT_ROOT):])
        else :
            if objpath.startswith(RTT_ROOT.lower()) :
                objpath = ''.join('kernel'+objpath[len(RTT_ROOT):])
            else :
                objpath = ''.join('bsp'+objpath[len(project_path):])
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
        if file_type == 'C' :
            ObjName = SubElement(File, 'ObjectFileName')
            ObjName.text = ''.join('$(IntDir)'+objpath+'\\')
Ejemplo n.º 7
0
def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
    group = SubElement(parent, 'Group')
    group_name = SubElement(group, 'GroupName')
    group_name.text = name

    name = os.path.basename(filename)
    path = os.path.dirname (filename)

    basename = os.path.basename(path)
    path = _make_path_relative(project_path, path)
    path = os.path.join(path, name)
    files = SubElement(group, 'Files')
    file = SubElement(files, 'File')
    file_name = SubElement(file, 'FileName')
    name = os.path.basename(path)

    if name.find('.cpp') != -1:
        obj_name = name.replace('.cpp', '.o')
    elif name.find('.c') != -1:
        obj_name = name.replace('.c', '.o')
    elif name.find('.s') != -1:
        obj_name = name.replace('.s', '.o')
    elif name.find('.S') != -1:
        obj_name = name.replace('.s', '.o')

    if ProjectFiles.count(obj_name):
        name = basename + '_' + name
    ProjectFiles.append(obj_name)
    file_name.text = name.decode(fs_encoding)
    file_type = SubElement(file, 'FileType')
    file_type.text = '%d' % _get_filetype(name)
    file_path = SubElement(file, 'FilePath')

    file_path.text = path.decode(fs_encoding)
Ejemplo n.º 8
0
def MDK4AddGroup(ProjectFiles, parent, name, files, project_path):
    # don't add an empty group
    if len(files) == 0:
        return

    group = SubElement(parent, 'Group')
    group_name = SubElement(group, 'GroupName')
    group_name.text = name

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        files = SubElement(group, 'Files')
        file = SubElement(files, 'File')
        file_name = SubElement(file, 'FileName')
        name = os.path.basename(path)
        if ProjectFiles.count(name):
            name = basename + '_' + name
        ProjectFiles.append(name)
        file_name.text = name.decode(fs_encoding)
        file_type = SubElement(file, 'FileType')
        file_type.text = '%d' % _get_filetype(name)
        file_path = SubElement(file, 'FilePath')

        file_path.text = path.decode(fs_encoding)
Ejemplo n.º 9
0
def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
    group = SubElement(parent, "Group")
    group_name = SubElement(group, "GroupName")
    group_name.text = name

    name = os.path.basename(filename)
    path = os.path.dirname(filename)

    basename = os.path.basename(path)
    path = _make_path_relative(project_path, path)
    path = os.path.join(path, name)
    files = SubElement(group, "Files")
    file = SubElement(files, "File")
    file_name = SubElement(file, "FileName")
    name = os.path.basename(path)

    if name.find(".cpp") != -1:
        obj_name = name.replace(".cpp", ".o")
    elif name.find(".c") != -1:
        obj_name = name.replace(".c", ".o")
    elif name.find(".s") != -1:
        obj_name = name.replace(".s", ".o")
    elif name.find(".S") != -1:
        obj_name = name.replace(".s", ".o")

    if ProjectFiles.count(obj_name):
        name = basename + "_" + name
    ProjectFiles.append(obj_name)
    file_name.text = name.decode(fs_encoding)
    file_type = SubElement(file, "FileType")
    file_type.text = "%d" % _get_filetype(name)
    file_path = SubElement(file, "FilePath")

    file_path.text = path.decode(fs_encoding)
Ejemplo n.º 10
0
def MDK4AddGroup(ProjectFiles, parent, name, files, project_path):
    # don't add an empty group 
    if len(files) == 0:
        return

    group = SubElement(parent, 'Group')
    group_name = SubElement(group, 'GroupName')
    group_name.text = name

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)
        
        files = SubElement(group, 'Files')
        file = SubElement(files, 'File')
        file_name = SubElement(file, 'FileName')
        name = os.path.basename(path)
        if ProjectFiles.count(name):
            name = basename + '_' + name
        ProjectFiles.append(name)
        file_name.text = name.decode(fs_encoding)
        file_type = SubElement(file, 'FileType')
        file_type.text = '%d' % _get_filetype(name)
        file_path = SubElement(file, 'FilePath')
        
        file_path.text = path.decode(fs_encoding)
Ejemplo n.º 11
0
def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
    group = SubElement(parent, 'Group')
    group_name = SubElement(group, 'GroupName')
    group_name.text = name

    name = os.path.basename(filename)
    path = os.path.dirname(filename)

    basename = os.path.basename(path)
    path = _make_path_relative(project_path, path)
    path = os.path.join(path, name)
    files = SubElement(group, 'Files')
    file = SubElement(files, 'File')
    file_name = SubElement(file, 'FileName')
    name = os.path.basename(path)

    if name.find('.cpp') != -1:
        obj_name = name.replace('.cpp', '.o')
    elif name.find('.c') != -1:
        obj_name = name.replace('.c', '.o')
    elif name.find('.s') != -1:
        obj_name = name.replace('.s', '.o')
    elif name.find('.S') != -1:
        obj_name = name.replace('.s', '.o')

    if ProjectFiles.count(obj_name):
        name = basename + '_' + name
    ProjectFiles.append(obj_name)
    file_name.text = name.decode(fs_encoding)
    file_type = SubElement(file, 'FileType')
    file_type.text = '%d' % _get_filetype(name)
    file_path = SubElement(file, 'FilePath')

    file_path.text = path.decode(fs_encoding)
Ejemplo n.º 12
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    from building import Rtt_Root
    RTT_ROOT = os.path.normpath(Rtt_Root)

    file_dict = {'C': "ClCompile", 'H': 'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        objpath = path.lower()
        if len(project_path) >= len(RTT_ROOT):
            if objpath.startswith(project_path.lower()):
                objpath = ''.join('bsp' + objpath[len(project_path):])
            else:
                objpath = ''.join('kernel' + objpath[len(RTT_ROOT):])
        else:
            if objpath.startswith(RTT_ROOT.lower()):
                objpath = ''.join('kernel' + objpath[len(RTT_ROOT):])
            else:
                objpath = ''.join('bsp' + objpath[len(project_path):])
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
        if file_type == 'C':
            ObjName = SubElement(File, 'ObjectFileName')
            ObjName.text = ''.join('$(IntDir)' + objpath + '\\')
Ejemplo n.º 13
0
def VS_add_HeadFiles(program, elem, project_path):
    utils.source_ext = []
    utils.source_ext = ["h"]
    for item in program:
        utils.walk_children(item)
    utils.source_list.sort()
    # print utils.source_list
    ItemGroup = SubElement(elem, 'ItemGroup')

    filter_h_ItemGroup = SubElement(filter_project, 'ItemGroup')
    for f in utils.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(ItemGroup, 'ClInclude')

        if sys.version > '3':
            File.set('Include', path)
        else:
            # python3 is no decode function
            File.set('Include', path.decode(fs_encoding))

        # add project.vcxproj.filter
        ClInclude = SubElement(filter_h_ItemGroup, 'ClInclude')

        if sys.version > '3':
            ClInclude.set('Include', path)
        else:
            # python3 is no decode function
            ClInclude.set('Include', path.decode(fs_encoding))

        Filter = SubElement(ClInclude, 'Filter')
        Filter.text = 'Header Files'
Ejemplo n.º 14
0
def IARProject(target, script):
    project_path = os.path.dirname(os.path.abspath(target))

    tree = etree.parse('template.ewp')
    root = tree.getroot()

    out = file(target, 'wb')

    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''

    # add group
    for group in script:
        IARAddGroup(root, group['name'], group['src'], project_path)

        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            CPPPATH += group['CPPPATH']

        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            CPPDEFINES += group['CPPDEFINES']

        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            LINKFLAGS += group['LINKFLAGS']

    # make relative path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc)  #.replace('\\', '/')

    # setting options
    options = tree.findall('configuration/settings/data/option')
    for option in options:
        # print option.text
        name = option.find('name')

        if name.text == 'CCIncludePath2' or name.text == 'newCCIncludePaths':
            for path in paths:
                state = SubElement(option, 'state')
                if os.path.isabs(path) or path.startswith('$'):
                    state.text = path
                else:
                    state.text = '$PROJ_DIR$\\' + path

        if name.text == 'CCDefines':
            for define in CPPDEFINES:
                state = SubElement(option, 'state')
                state.text = define

    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()

    IARWorkspace(target)
Ejemplo n.º 15
0
def IARProject(target, script):
    project_path = os.path.dirname(os.path.abspath(target))

    tree = etree.parse('template.ewp')
    root = tree.getroot()

    out = file(target, 'wb')

    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''
    
    # add group
    for group in script:
        IARAddGroup(root, group['name'], group['src'], project_path)

        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            CPPPATH += group['CPPPATH']
        
        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            CPPDEFINES += group['CPPDEFINES']
        
        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            LINKFLAGS += group['LINKFLAGS']
    
    # make relative path 
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc) #.replace('\\', '/')
    
    # setting options
    options = tree.findall('configuration/settings/data/option')
    for option in options:
        # print option.text
        name = option.find('name')
        
        if name.text == 'CCIncludePath2' or name.text == 'newCCIncludePaths':
            for path in paths:
                state = SubElement(option, 'state')
                if os.path.isabs(path):
                    state.text = path
                else:
                    state.text = '$PROJ_DIR$\\' + path

        if name.text == 'CCDefines':
            for define in CPPDEFINES:
                state = SubElement(option, 'state')
                state.text = define
    
    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
    
    IARWorkspace(target)
Ejemplo n.º 16
0
def CLAddCFiles(parent, files, project_path):
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)
        CLAddFile(parent, path)
Ejemplo n.º 17
0
def CLAddHeaderFiles(parent, program, project_path):
    utils.source_ext = []
    utils.source_ext = ["h"]
    for item in program:
        utils.walk_children(item)
    utils.source_list.sort()

    for f in utils.source_list:
        path = _make_path_relative(project_path, f)
        CLAddFile(parent, path)
Ejemplo n.º 18
0
def CB_AddHeadFiles(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)    
    building.source_list.sort()
    # print building.source_list
    
    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        Unit = SubElement(elem, 'Unit')
        Unit.set('filename', path.decode(fs_encoding))
Ejemplo n.º 19
0
Archivo: vs.py Proyecto: yygg/rt-thread
def VS_AddHeadFilesGroup(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)
    building.source_list.sort()
    # print building.source_list

    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(elem, "File")
        File.set("RelativePath", path.decode(fs_encoding))
Ejemplo n.º 20
0
def CB_AddHeadFiles(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)
    building.source_list.sort()
    # print building.source_list

    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        Unit = SubElement(elem, 'Unit')
        Unit.set('filename', path.decode(fs_encoding))
Ejemplo n.º 21
0
def VS_AddHeadFilesGroup(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)
    building.source_list.sort()
    # print building.source_list

    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(elem, 'File')
        File.set('RelativePath', path.decode(fs_encoding))
Ejemplo n.º 22
0
def Qt_AddHeadFilesGroup(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)    
    building.source_list.sort()
    # print building.source_list
    
    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        #File = SubElement(elem, 'File')
        path = path.decode(fs_encoding)
        elem.write('HEADERS += ' + path + '\r\n')
Ejemplo n.º 23
0
def GenerateCFiles(env):
    """
    Generate c_cpp_properties files
    """
    if not os.path.exists('.vscode'):
        os.mkdir('.vscode')

    vsc_file = open('.vscode/c_cpp_properties.json', 'w')
    if vsc_file:
        info = utils.ProjectInfo(env)

        cc = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
        cc = os.path.abspath(cc).replace('\\', '/')

        config_obj = {}
        config_obj['name'] = 'Win32'
        config_obj['defines'] = info['CPPDEFINES']
        config_obj['intelliSenseMode'] = 'clang-x64'
        config_obj['compilerPath'] = cc
        config_obj['cStandard'] = "c99"
        config_obj['cppStandard'] = "c++11"

        # format "a/b," to a/b. remove first quotation mark("),and remove end (",)
        includePath = []
        for i in info['CPPPATH']:
            if i[0] == '\"' and i[len(i) - 2:len(i)] == '\",':
                includePath.append(
                    _make_path_relative(os.getcwd(), i[1:len(i) - 2]))
            else:
                includePath.append(_make_path_relative(os.getcwd(), i))
        config_obj['includePath'] = includePath

        json_obj = {}
        json_obj['configurations'] = [config_obj]

        vsc_file.write(json.dumps(json_obj, ensure_ascii=False, indent=4))
        vsc_file.close()

    return
Ejemplo n.º 24
0
def CB_AddCFiles(ProjectFiles, parent, gname, files, project_path):
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        Unit = SubElement(parent, 'Unit')
        Unit.set('filename', path.decode(fs_encoding))
        Option = SubElement(Unit, 'Option')
        Option.set('compilerVar', "CC")
Ejemplo n.º 25
0
def CB_AddCFiles(ProjectFiles, parent, gname, files, project_path):
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        Unit = SubElement(parent, 'Unit')
        Unit.set('filename', path.decode(fs_encoding))
        Option = SubElement(Unit, 'Option')
        Option.set('compilerVar', "CC")
Ejemplo n.º 26
0
Archivo: vs.py Proyecto: yygg/rt-thread
def VS_AddGroup(ProjectFiles, parent, name, files, project_path):
    Filter = SubElement(parent, "Filter")
    Filter.set("Name", name)  # set group name to group

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(Filter, "File")
        File.set("RelativePath", path.decode(fs_encoding))
Ejemplo n.º 27
0
def VS2012_AddGroup(parent, group_name, files, project_path):
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        ClCompile = SubElement(parent, 'ClCompile')
        ClCompile.set('Include', path.decode(fs_encoding))

        Filter = SubElement(ClCompile, 'Filter')
        Filter.text='Source Files\\'+group_name
Ejemplo n.º 28
0
def VS2012_AddGroup(parent, group_name, files, project_path):
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        ClCompile = SubElement(parent, 'ClCompile')
        ClCompile.set('Include', path.decode(fs_encoding))

        Filter = SubElement(ClCompile, 'Filter')
        Filter.text = 'Source Files\\' + group_name
Ejemplo n.º 29
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    file_dict = {'C':"ClCompile", 'H':'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
Ejemplo n.º 30
0
def VS_AddGroup(ProjectFiles, parent, name, files, libs, project_path):
    Filter = SubElement(parent, 'Filter')
    Filter.set('Name', name) #set group name to group

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(Filter, 'File')
        File.set('RelativePath', path.decode(fs_encoding))

    for lib in libs:
        name = os.path.basename(lib)
        path = os.path.dirname(lib)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(Filter, 'File')
        File.set('RelativePath', path.decode(fs_encoding))
Ejemplo n.º 31
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    file_dict = {'C': "ClCompile", 'H': 'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
Ejemplo n.º 32
0
def VS_AddHeadFilesGroup(program, elem, project_path):
    utils.source_ext = []
    utils.source_ext = ["h"]
    for item in program:
        utils.walk_children(item)
    utils.source_list.sort()
    # print utils.source_list

    for f in utils.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(elem, 'File')
        try:
            path = path.decode(fs_encoding)
        except:
            path = path
        File.set('RelativePath', path)
Ejemplo n.º 33
0
def IARAddGroup(parent, name, files, project_path):
    group = SubElement(parent, 'group')
    group_name = SubElement(group, 'name')
    group_name.text = name

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        file = SubElement(group, 'file')
        file_name = SubElement(file, 'name')
        file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding)
Ejemplo n.º 34
0
def IARAddGroup(parent, name, files, project_path):
    group = SubElement(parent, 'group')
    group_name = SubElement(group, 'name')
    group_name.text = name
    
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)
    
        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)
        
        file = SubElement(group, 'file')
        file_name = SubElement(file, 'name')
        file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding)
Ejemplo n.º 35
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    file_dict = {'C': "ClCompile", 'H': 'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        objpath = path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
        if file_type == 'C':
            ObjName = SubElement(File, 'ObjectFileName')
            ObjName.text = ''.join('$(IntDir)' + objpath + '\\')
Ejemplo n.º 36
0
def VS_add_ItemGroup(parent, file_type, files, project_path):
    file_dict = {'C':"ClCompile", 'H':'ClInclude'}
    item_tag = file_dict[file_type]

    ItemGroup = SubElement(parent, 'ItemGroup')
    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        objpath = path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        File = SubElement(ItemGroup, item_tag)
        File.set('Include', path.decode(fs_encoding))
        if file_type == 'C' :
            ObjName = SubElement(File, 'ObjectFileName')
            ObjName.text = ''.join('$(IntDir)'+objpath+'\\')
Ejemplo n.º 37
0
def SDKAddGroup(parent, name, files, project_path):
    # don't add an empty group
    if len(files) == 0:
        return

    group = SubElement(parent, 'folder', attrib={'Name': name})

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        elm_attr_name = os.path.join(path, name)

        file = SubElement(group, 'file', attrib={'file_name': elm_attr_name})

    return group
Ejemplo n.º 38
0
def VS_add_HeadFiles(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)    
    building.source_list.sort()
    # print building.source_list
    ItemGroup = SubElement(elem, 'ItemGroup')

    filter_h_ItemGroup = SubElement(filter_project, 'ItemGroup')
    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(ItemGroup, 'ClInclude')
        File.set('Include', path.decode(fs_encoding))

        # add project.vcxproj.filter
        ClInclude = SubElement(filter_h_ItemGroup, 'ClInclude')
        ClInclude.set('Include', path.decode(fs_encoding))
        Filter = SubElement(ClInclude, 'Filter')
        Filter.text='Header Files'
Ejemplo n.º 39
0
def VS_add_HeadFiles(program, elem, project_path):
    building.source_ext = []
    building.source_ext = ["h"]
    for item in program:
        building.walk_children(item)
    building.source_list.sort()
    # print building.source_list
    ItemGroup = SubElement(elem, 'ItemGroup')

    filter_h_ItemGroup = SubElement(filter_project, 'ItemGroup')
    for f in building.source_list:
        path = _make_path_relative(project_path, f)
        File = SubElement(ItemGroup, 'ClInclude')
        File.set('Include', path.decode(fs_encoding))

        # add project.vcxproj.filter
        ClInclude = SubElement(filter_h_ItemGroup, 'ClInclude')
        ClInclude.set('Include', path.decode(fs_encoding))
        Filter = SubElement(ClInclude, 'Filter')
        Filter.text = 'Header Files'
Ejemplo n.º 40
0
def MDK4AddGroup(ProjectFiles, parent, name, files, project_path):
    # don't add an empty group
    if len(files) == 0:
        return

    group = SubElement(parent, "Group")
    group_name = SubElement(group, "GroupName")
    group_name.text = name

    for f in files:
        fn = f.rfile()
        name = fn.name
        path = os.path.dirname(fn.abspath)

        basename = os.path.basename(path)
        path = _make_path_relative(project_path, path)
        path = os.path.join(path, name)

        files = SubElement(group, "Files")
        file = SubElement(files, "File")
        file_name = SubElement(file, "FileName")
        name = os.path.basename(path)

        if name.find(".cpp") != -1:
            obj_name = name.replace(".cpp", ".o")
        elif name.find(".c") != -1:
            obj_name = name.replace(".c", ".o")
        elif name.find(".s") != -1:
            obj_name = name.replace(".s", ".o")
        elif name.find(".S") != -1:
            obj_name = name.replace(".s", ".o")

        if ProjectFiles.count(obj_name):
            name = basename + "_" + name
        ProjectFiles.append(obj_name)
        file_name.text = name.decode(fs_encoding)
        file_type = SubElement(file, "FileType")
        file_type.text = "%d" % _get_filetype(name)
        file_path = SubElement(file, "FilePath")

        file_path.text = path.decode(fs_encoding)
Ejemplo n.º 41
0
def MDK4AddLibToGroup(ProjectFiles, group, name, filename, project_path):
    name = os.path.basename(filename)
    path = os.path.dirname(filename)

    basename = os.path.basename(path)
    path = _make_path_relative(project_path, path)
    path = os.path.join(path, name)
    files = SubElement(group, 'Files')
    file = SubElement(files, 'File')
    file_name = SubElement(file, 'FileName')
    name = os.path.basename(path)

    if name.find('.cpp') != -1:
        obj_name = name.replace('.cpp', '.o')
    elif name.find('.c') != -1:
        obj_name = name.replace('.c', '.o')
    elif name.find('.s') != -1:
        obj_name = name.replace('.s', '.o')
    elif name.find('.S') != -1:
        obj_name = name.replace('.s', '.o')
    else:
        obj_name = name

    if ProjectFiles.count(obj_name):
        name = basename + '_' + name
    ProjectFiles.append(obj_name)
    try:
        file_name.text = name.decode(fs_encoding)
    except:
        file_name.text = name
    file_type = SubElement(file, 'FileType')
    file_type.text = '%d' % _get_filetype(name)
    file_path = SubElement(file, 'FilePath')

    try:
        file_path.text = path.decode(fs_encoding)
    except:
        file_path.text = path

    return group
Ejemplo n.º 42
0
def MDKProject(target, script):
    template = file("template.Uv2", "rb")
    lines = template.readlines()

    project = file(target, "wb")
    project_path = os.path.dirname(os.path.abspath(target))

    line_index = 5
    # write group
    for group in script:
        lines.insert(line_index, "Group (%s)\r\n" % group["name"])
        line_index += 1

    lines.insert(line_index, "\r\n")
    line_index += 1

    # write file

    ProjectFiles = []
    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ""
    CCFLAGS = ""

    # number of groups
    group_index = 1
    for group in script:
        # print group['name']

        # get each include path
        if group.has_key("CPPPATH") and group["CPPPATH"]:
            if CPPPATH:
                CPPPATH += group["CPPPATH"]
            else:
                CPPPATH += group["CPPPATH"]

        # get each group's definitions
        if group.has_key("CPPDEFINES") and group["CPPDEFINES"]:
            if CPPDEFINES:
                CPPDEFINES += ";" + group["CPPDEFINES"]
            else:
                CPPDEFINES += group["CPPDEFINES"]

        # get each group's link flags
        if group.has_key("LINKFLAGS") and group["LINKFLAGS"]:
            if LINKFLAGS:
                LINKFLAGS += " " + group["LINKFLAGS"]
            else:
                LINKFLAGS += group["LINKFLAGS"]

        # generate file items
        for node in group["src"]:
            fn = node.rfile()
            name = fn.name
            path = os.path.dirname(fn.abspath)
            basename = os.path.basename(path)
            path = _make_path_relative(project_path, path)
            path = os.path.join(path, name)
            if ProjectFiles.count(name):
                name = basename + "_" + name
            ProjectFiles.append(name)
            lines.insert(line_index, "File %d,%d,<%s><%s>\r\n" % (group_index, _get_filetype(name), path, name))
            line_index += 1

        group_index = group_index + 1

    lines.insert(line_index, "\r\n")
    line_index += 1

    # remove repeat path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc)  # .replace('\\', '/')

    paths = [i for i in paths]
    CPPPATH = string.join(paths, ";")

    definitions = [i for i in set(CPPDEFINES)]
    CPPDEFINES = string.join(definitions, ", ")

    while line_index < len(lines):
        if lines[line_index].startswith(" ADSCINCD "):
            lines[line_index] = " ADSCINCD (" + CPPPATH + ")\r\n"

        if lines[line_index].startswith(" ADSLDMC ("):
            lines[line_index] = " ADSLDMC (" + LINKFLAGS + ")\r\n"

        if lines[line_index].startswith(" ADSCDEFN ("):
            lines[line_index] = " ADSCDEFN (" + CPPDEFINES + ")\r\n"

        line_index += 1

    # write project
    for line in lines:
        project.write(line)

    project.close()
Ejemplo n.º 43
0
def GenerateCFiles(env, project):
    """
    Generate CMakeLists.txt files
    """
    info = utils.ProjectInfo(env)

    CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC).replace('\\', "/")
    if 'CXX' in dir(rtconfig):
        CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX).replace('\\', "/")
    else:
        CXX = ''
    AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS).replace('\\', "/")
    AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/")
    LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/")
    if rtconfig.PLATFORM == 'gcc':
        SIZE = os.path.join(rtconfig.EXEC_PATH,
                            rtconfig.SIZE).replace('\\', "/")
        OBJDUMP = os.path.join(rtconfig.EXEC_PATH,
                               rtconfig.OBJDUMP).replace('\\', "/")
        OBJCOPY = os.path.join(rtconfig.EXEC_PATH,
                               rtconfig.OBJCPY).replace('\\', "/")
    elif rtconfig.PLATFORM in ['armcc', 'armclang']:
        FROMELF = os.path.join(rtconfig.EXEC_PATH,
                               'fromelf').replace('\\', "/")

    CFLAGS = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
    if 'CXXFLAGS' in dir(rtconfig):
        CXXFLAGS = rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"")
    else:
        CXXFLAGS = CFLAGS
    AFLAGS = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
    LFLAGS = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")

    if "win32" in sys.platform:
        CC += ".exe"
        if CXX != '':
            CXX += ".exe"
        AS += ".exe"
        AR += ".exe"
        LINK += ".exe"
        if rtconfig.PLATFORM == 'gcc':
            SIZE += ".exe"
            OBJDUMP += ".exe"
            OBJCOPY += ".exe"
        elif rtconfig.PLATFORM in ['armcc', 'armclang']:
            FROMELF += ".exe"

    if not os.path.exists(CC) or not os.path.exists(AS) or not os.path.exists(
            AR) or not os.path.exists(LINK):
        print(
            "'Cannot found toolchain directory, please check RTT_CC and RTT_EXEC_PATH'"
        )
        sys.exit(-1)

    cm_file = open('CMakeLists.txt', 'w')
    if cm_file:
        cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n")

        cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n")
        cm_file.write("SET(CMAKE_SYSTEM_PROCESSOR " + rtconfig.CPU + ")\n")
        cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n")
        cm_file.write("SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)\n\n")

        cm_file.write("SET(CMAKE_C_COMPILER \"" + CC + "\")\n")
        cm_file.write("SET(CMAKE_ASM_COMPILER \"" + AS + "\")\n")
        cm_file.write("SET(CMAKE_C_FLAGS \"" + CFLAGS + "\")\n")
        cm_file.write("SET(CMAKE_ASM_FLAGS \"" + AFLAGS + "\")\n")
        cm_file.write("SET(CMAKE_C_COMPILER_WORKS TRUE)\n\n")

        if CXX != '':
            cm_file.write("SET(CMAKE_CXX_COMPILER \"" + CXX + "\")\n")
            cm_file.write("SET(CMAKE_CXX_FLAGS \"" + CXXFLAGS + "\")\n")
            cm_file.write("SET(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")

        if rtconfig.PLATFORM == 'gcc':
            cm_file.write("SET(CMAKE_OBJCOPY \"" + OBJCOPY + "\")\n")
            cm_file.write("SET(CMAKE_SIZE \"" + SIZE + "\")\n\n")
        elif rtconfig.PLATFORM in ['armcc', 'armclang']:
            cm_file.write("SET(CMAKE_FROMELF \"" + FROMELF + "\")\n\n")

        LINKER_FLAGS = ''
        LINKER_LIBS = ''
        if rtconfig.PLATFORM == 'gcc':
            LINKER_FLAGS += '-T'
        elif rtconfig.PLATFORM in ['armcc', 'armclang']:
            LINKER_FLAGS += '--scatter'
            for group in project:
                if 'LIBPATH' in group.keys():
                    for f in group['LIBPATH']:
                        LINKER_LIBS += ' --userlibpath ' + f.replace("\\", "/")
            for group in project:
                if 'LIBS' in group.keys():
                    for f in group['LIBS']:
                        LINKER_LIBS += ' ' + f.replace("\\", "/") + '.lib'
        cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \"" +
                      re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS +
                             ' ${CMAKE_SOURCE_DIR}/', LFLAGS) + LINKER_LIBS +
                      "\")\n\n")

        if CXX != '':
            cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n")
            cm_file.write("PROJECT(rtthread C CXX ASM)\n")
        else:
            cm_file.write("PROJECT(rtthread C ASM)\n")

        cm_file.write("INCLUDE_DIRECTORIES(\n")
        for i in info['CPPPATH']:
            # use relative path
            path = _make_path_relative(os.getcwd(), i)
            cm_file.write("\t" + path.replace("\\", "/") + "\n")
        cm_file.write(")\n\n")

        cm_file.write("ADD_DEFINITIONS(\n")
        for i in info['CPPDEFINES']:
            cm_file.write("\t-D" + i + "\n")
        cm_file.write(")\n\n")

        cm_file.write("SET(PROJECT_SOURCES\n")
        for group in project:
            for f in group['src']:
                # use relative path
                path = _make_path_relative(os.getcwd(),
                                           os.path.normpath(f.rfile().abspath))
                cm_file.write("\t" + path.replace("\\", "/") + "\n")
        cm_file.write(")\n\n")

        if rtconfig.PLATFORM == 'gcc':
            cm_file.write("LINK_DIRECTORIES(\n")
            for group in project:
                if 'LIBPATH' in group.keys():
                    for f in group['LIBPATH']:
                        cm_file.write("\t" + f.replace("\\", "/") + "\n")
            cm_file.write(")\n\n")

            cm_file.write("LINK_LIBRARIES(\n")
            for group in project:
                if 'LIBS' in group.keys():
                    for f in group['LIBS']:
                        cm_file.write("\t" +
                                      "{}\n".format(f.replace("\\", "/")))
            cm_file.write(")\n\n")

            cm_file.write(
                "ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n"
            )
            cm_file.write(
                "ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)"
            )
        elif rtconfig.PLATFORM in ['armcc', 'armclang']:
            cm_file.write(
                "ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES})\n")
            cm_file.write(
                "ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD \nCOMMAND ${CMAKE_FROMELF} --bin ${CMAKE_PROJECT_NAME}.elf --output ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_FROMELF} -z ${CMAKE_PROJECT_NAME}.elf)"
            )

        cm_file.close()

    return
Ejemplo n.º 44
0
def QtProject(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))
    
    #tree = etree.parse('template_vs2005.vcproj')
    #root = tree.getroot()
    
    out = file(target, 'wb')
    out.write('# Qt project file create by rt-thread\r\n')
    out.write('QT += core\r\n')
    out.write('TARGET = rtthread\r\n')
    out.write('TEMPLATE = app\r\n')
    out.write('CONFIG   += console\r\n')
    out.write('\r\n')
    out.write('\r\n')
    
    ProjectFiles = []
    
    # add "*.c" files group
    #for elem in tree.iter(tag='Filter'):
    #    if elem.attrib['Name'] == 'Source Files':
    #        #print elem.tag, elem.attrib
    #        break
    out.write('\r\n\r\n')
    out.write('# source files\r\n')
    for group in script:
        libs = []
        if group.has_key('LIBS') and group['LIBS']:
            for item in group['LIBS']:
                lib_path = ''
                for path_item in group['LIBPATH']:
                    full_path = os.path.join(path_item, item + '.lib')
                    if os.path.isfile(full_path): # has this library
                        lib_path = full_path

                if lib_path != '':
                    libs.append(lib_path)
        Qt_AddGroup(ProjectFiles, out, group['name'], group['src'], libs, project_path)
    
    #print 'get lib', len(libs)
    #print libs

    # add "*.h" files group
    #for elem in tree.iter(tag='Filter'):
    #    if elem.attrib['Name'] == 'Header Files':
    #        break
    out.write('\r\n\r\n')
    out.write('# head files\r\n')
    Qt_AddHeadFilesGroup(program, out, project_path)
    
    out.write('\r\n\r\n')
    out.write('# Include path\r\n')
    # write head include path
    if building.Env.has_key('CPPPATH'):
        cpp_path = building.Env['CPPPATH']
        paths  = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        cpp_path = ';'.join(paths)
        cpp_path_list = cpp_path.split(';') 
        #print "get cpp path", len(cpp_path_list)
        for e in cpp_path_list:
            out.write('INCLUDEPATH += '+e+'\r\n')
        #print cpp_path_list
        # write include path, definitions
        #for elem in tree.iter(tag='Tool'):
        #    if elem.attrib['Name'] == 'VCCLCompilerTool':
                #print elem.tag, elem.attrib
        #        break
        #elem.set('AdditionalIncludeDirectories', cpp_path)

    # write cppdefinitons flags
    out.write('\r\n\r\n')
    out.write('# defines\r\n')
    
    if building.Env.has_key('CPPDEFINES'):
        CPPDEFINES = building.Env['CPPDEFINES']
        definitions = []
        if type(CPPDEFINES[0]) == type(()):
            for item in CPPDEFINES:
                definitions += [i for i in item]
            definitions = ';'.join(definitions)
        else:
            definitions = ';'.join(building.Env['CPPDEFINES'])
        #elem.set('PreprocessorDefinitions', definitions)
        cpp_define_list = definitions.split(';')
        for e in cpp_define_list:
            out.write('DEFINES += '+e+'\r\n')
        #print "get cpp defines", len(cpp_define_list)
        #print cpp_define_list
    # write link flags

    out.write('\r\n\r\n')
    out.write('# libs\r\n')
    # write lib dependence 
    if building.Env.has_key('LIBS'):
        #for elem in tree.iter(tag='Tool'):
        #    if elem.attrib['Name'] == 'VCLinkerTool':
        #        break
        libs_with_extention = [i+'.lib' for i in building.Env['LIBS']]
        libs = ' '.join(libs_with_extention)
        #elem.set('AdditionalDependencies', libs)
        for e in libs.split(' '):
            if len(e) > 0 :
                out.write('LIBS += -l'+e+'\r\n')
        #print "get libs"
        #print '"'+libs+'"'

    # write lib include path
    out.write('# lib paths\r\n')
    if building.Env.has_key('LIBPATH'):
        lib_path = building.Env['LIBPATH']
        paths  = set()
        for path in lib_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        lib_paths = ';'.join(paths)
        for e in lib_paths.split(';'):
            if len(e) > 0 :
                out.write('LIBS += -L'+e+'\r\n')
        #elem.set('AdditionalLibraryDirectories', lib_paths)
        #print "get lib paths"
        #print '"'+lib_paths+'"'

    #xml_indent(root)
    #out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 45
0
Archivo: vs.py Proyecto: yygg/rt-thread
def VSProject(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))

    tree = etree.parse("template_vs2005.vcproj")
    root = tree.getroot()

    out = file(target, "wb")
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')

    ProjectFiles = []

    # add "*.c" files group
    for elem in tree.iter(tag="Filter"):
        if elem.attrib["Name"] == "Source Files":
            # print elem.tag, elem.attrib
            break

    for group in script:
        group_xml = VS_AddGroup(ProjectFiles, elem, group["name"], group["src"], project_path)

    # add "*.h" files group
    for elem in tree.iter(tag="Filter"):
        if elem.attrib["Name"] == "Header Files":
            break
    VS_AddHeadFilesGroup(program, elem, project_path)

    # write head include path
    if building.Env.has_key("CPPPATH"):
        cpp_path = building.Env["CPPPATH"]
        paths = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)  # .replace('\\', '/')

        paths = [i for i in paths]
        paths.sort()
        cpp_path = ";".join(paths)

        # write include path, definitions
        for elem in tree.iter(tag="Tool"):
            if elem.attrib["Name"] == "VCCLCompilerTool":
                # print elem.tag, elem.attrib
                break
        elem.set("AdditionalIncludeDirectories", cpp_path)

    # write cppdefinitons flags
    if building.Env.has_key("CPPDEFINES"):
        CPPDEFINES = building.Env["CPPDEFINES"]
        definitions = []
        if type(CPPDEFINES[0]) == type(()):
            for item in CPPDEFINES:
                definitions += [i for i in item]
            definitions = ";".join(definitions)
        else:
            definitions = ";".join(building.Env["CPPDEFINES"])
        elem.set("PreprocessorDefinitions", definitions)
    # write link flags

    # write lib dependence
    if building.Env.has_key("LIBS"):
        for elem in tree.iter(tag="Tool"):
            if elem.attrib["Name"] == "VCLinkerTool":
                break
        libs_with_extention = [i + ".lib" for i in building.Env["LIBS"]]
        libs = " ".join(libs_with_extention)
        elem.set("AdditionalDependencies", libs)

    # write lib include path
    if building.Env.has_key("LIBPATH"):
        lib_path = building.Env["LIBPATH"]
        paths = set()
        for path in lib_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)  # .replace('\\', '/')

        paths = [i for i in paths]
        paths.sort()
        lib_paths = ";".join(paths)
        elem.set("AdditionalLibraryDirectories", lib_paths)

    xml_indent(root)
    out.write(etree.tostring(root, encoding="utf-8"))
    out.close()
Ejemplo n.º 46
0
def VSProject(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))
    
    tree = etree.parse('template_vs2005.vcproj')
    root = tree.getroot()
    
    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
    
    ProjectFiles = []
    
    # add "*.c" files group
    for elem in tree.iter(tag='Filter'):
        if elem.attrib['Name'] == 'Source Files':
            #print elem.tag, elem.attrib
            break

    for group in script:
        group_xml = VS_AddGroup(ProjectFiles, elem, group['name'], group['src'], project_path)

    # add "*.h" files group
    for elem in tree.iter(tag='Filter'):
        if elem.attrib['Name'] == 'Header Files':
            break
    VS_AddHeadFilesGroup(program, elem, project_path)
    
    # write head include path
    if building.Env.has_key('CPPPATH'):
        cpp_path = building.Env['CPPPATH']
        paths  = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        cpp_path = ';'.join(paths)

        # write include path, definitions
        for elem in tree.iter(tag='Tool'):
            if elem.attrib['Name'] == 'VCCLCompilerTool':
                #print elem.tag, elem.attrib
                break
        elem.set('AdditionalIncludeDirectories', cpp_path)

    # write cppdefinitons flags
    if building.Env.has_key('CPPDEFINES'):
        definitions = ';'.join(building.Env['CPPDEFINES'])
        elem.set('PreprocessorDefinitions', definitions)
    # write link flags

    # write lib dependence 
    if building.Env.has_key('LIBS'):
        for elem in tree.iter(tag='Tool'):
            if elem.attrib['Name'] == 'VCLinkerTool':
                break
        libs_with_extention = [i+'.lib' for i in building.Env['LIBS']]
        libs = ' '.join(libs_with_extention)
        elem.set('AdditionalDependencies', libs)

    # write lib include path
    if building.Env.has_key('LIBPATH'):
        lib_path = building.Env['LIBPATH']
        paths  = set()
        for path in lib_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        lib_paths = ';'.join(paths)
        elem.set('AdditionalLibraryDirectories', lib_paths)

    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 47
0
def VS2012Project(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))

    tree = etree.parse('template_vs2012.vcxproj')
    root = tree.getroot()
    elem = root

    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')

    ProjectFiles = []

    # add "*.c or *.h" files

    VS2012_CreateFilter(script, project_path)
    # add "*.c" files
    for group in script:
        VS_add_ItemGroup(elem, 'C', group['src'], project_path)

    # add "*.h" files
    VS_add_HeadFiles(program, elem, project_path)

    # write head include path
    if building.Env.has_key('CPPPATH'):
        cpp_path = building.Env['CPPPATH']
        paths = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)  #.replace('\\', '/')

        paths = [i for i in paths]
        paths.sort()
        cpp_path = ';'.join(paths) + ';%(AdditionalIncludeDirectories)'

        # write include path
        for elem in tree.iter(tag='AdditionalIncludeDirectories'):
            elem.text = cpp_path
            break

    # write cppdefinitons flags
    if building.Env.has_key('CPPDEFINES'):
        for elem in tree.iter(tag='PreprocessorDefinitions'):
            definitions = ';'.join(
                building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)'
            elem.text = definitions
            break
    # write link flags

    # write lib dependence (Link)
    if building.Env.has_key('LIBS'):
        for elem in tree.iter(tag='AdditionalDependencies'):
            libs_with_extention = [i + '.lib' for i in building.Env['LIBS']]
            libs = ';'.join(libs_with_extention) + ';%(AdditionalDependencies)'
            elem.text = libs
            break

    # write lib include path
    if building.Env.has_key('LIBPATH'):
        lib_path = building.Env['LIBPATH']
        paths = set()
        for path in lib_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)

        paths = [i for i in paths]
        paths.sort()
        lib_paths = ';'.join(paths) + ';%(AdditionalLibraryDirectories)'
        for elem in tree.iter(tag='AdditionalLibraryDirectories'):
            elem.text = lib_paths
            break

    xml_indent(root)
    vcxproj_string = etree.tostring(root, encoding='utf-8')
    root_node = r'<Project DefaultTargets="Build" ToolsVersion="4.0">'
    out.write(
        r'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
    )
    out.write(vcxproj_string[len(root_node):])
    out.close()

    xml_indent(filter_project)
    filter_string = etree.tostring(filter_project, encoding='utf-8')
    out = file('project.vcxproj.filters', 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
    root_node = r'<Project ToolsVersion="4.0">'
    out.write(
        r'<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
    )
    out.write(filter_string[len(root_node):])
    out.close()
Ejemplo n.º 48
0
def VS2012Project(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))
    
    tree = etree.parse('template_vs2012.vcxproj')
    root = tree.getroot()
    elem = root
    
    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
    
    ProjectFiles = []
    
    # add "*.c or *.h" files

    VS2012_CreateFilter(script, project_path)
    # add "*.c" files
    for group in script:
        VS_add_ItemGroup(elem, 'C', group['src'], project_path)

    # add "*.h" files
    VS_add_HeadFiles(program, elem, project_path)

    # write head include path
    if building.Env.has_key('CPPPATH'):
        cpp_path = building.Env['CPPPATH']
        paths = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        cpp_path = ';'.join(paths) + ';%(AdditionalIncludeDirectories)'

        # write include path
        for elem in tree.iter(tag='AdditionalIncludeDirectories'):
            elem.text = cpp_path
            break

    # write cppdefinitons flags
    if building.Env.has_key('CPPDEFINES'):
        for elem in tree.iter(tag='PreprocessorDefinitions'):
            definitions = ';'.join(building.Env['CPPDEFINES']) + ';%(PreprocessorDefinitions)'
            elem.text = definitions
            break
    # write link flags

    # write lib dependence (Link)
    if building.Env.has_key('LIBS'):
        for elem in tree.iter(tag='AdditionalDependencies'):
            libs_with_extention = [i+'.lib' for i in building.Env['LIBS']]
            libs = ';'.join(libs_with_extention) + ';%(AdditionalDependencies)'
            elem.text = libs
            break

    # write lib include path
    if building.Env.has_key('LIBPATH'):
        lib_path = building.Env['LIBPATH']
        paths  = set()
        for path in lib_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)
    
        paths = [i for i in paths]
        paths.sort()
        lib_paths = ';'.join(paths) + ';%(AdditionalLibraryDirectories)'
        for elem in tree.iter(tag='AdditionalLibraryDirectories'):
            elem.text = lib_paths
            break

    xml_indent(root)
    vcxproj_string = etree.tostring(root, encoding='utf-8')
    root_node=r'<Project DefaultTargets="Build" ToolsVersion="4.0">'
    out.write(r'<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">')
    out.write(vcxproj_string[len(root_node):])
    out.close()

    xml_indent(filter_project)
    filter_string = etree.tostring(filter_project, encoding='utf-8')
    out = file('project.vcxproj.filters', 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\r\n')
    root_node=r'<Project ToolsVersion="4.0">'
    out.write(r'<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">')
    out.write(filter_string[len(root_node):])
    out.close()
Ejemplo n.º 49
0
def MDKProject(target, script):
    template = file('template.Uv2', "rb")
    lines = template.readlines()

    project = file(target, "wb")
    project_path = os.path.dirname(os.path.abspath(target))

    line_index = 5
    # write group
    for group in script:
        lines.insert(line_index, 'Group (%s)\r\n' % group['name'])
        line_index += 1

    lines.insert(line_index, '\r\n')
    line_index += 1

    # write file

    ProjectFiles = []
    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''

    # number of groups
    group_index = 1
    for group in script:
        # print group['name']

        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            if CPPPATH:
                CPPPATH += group['CPPPATH']
            else:
                CPPPATH += group['CPPPATH']

        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            if CPPDEFINES:
                CPPDEFINES += ';' + group['CPPDEFINES']
            else:
                CPPDEFINES += group['CPPDEFINES']

        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            if LINKFLAGS:
                LINKFLAGS += ' ' + group['LINKFLAGS']
            else:
                LINKFLAGS += group['LINKFLAGS']

        # generate file items
        for node in group['src']:
            fn = node.rfile()
            name = fn.name
            path = os.path.dirname(fn.abspath)
            basename = os.path.basename(path)
            path = _make_path_relative(project_path, path)
            path = os.path.join(path, name)
            if ProjectFiles.count(name):
                name = basename + '_' + name
            ProjectFiles.append(name)
            lines.insert(line_index, 'File %d,%d,<%s><%s>\r\n'
                % (group_index, _get_filetype(name), path, name))
            line_index += 1

        group_index = group_index + 1

    lines.insert(line_index, '\r\n')
    line_index += 1

    # remove repeat path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc) #.replace('\\', '/')

    paths = [i for i in paths]
    CPPPATH = string.join(paths, ';')

    definitions = [i for i in set(CPPDEFINES)]
    CPPDEFINES = string.join(definitions, ', ')

    while line_index < len(lines):
        if lines[line_index].startswith(' ADSCINCD '):
            lines[line_index] = ' ADSCINCD (' + CPPPATH + ')\r\n'

        if lines[line_index].startswith(' ADSLDMC ('):
            lines[line_index] = ' ADSLDMC (' + LINKFLAGS + ')\r\n'

        if lines[line_index].startswith(' ADSCDEFN ('):
            lines[line_index] = ' ADSCDEFN (' + CPPDEFINES + ')\r\n'

        line_index += 1

    # write project
    for line in lines:
        project.write(line)

    project.close()
Ejemplo n.º 50
0
def MDK4Project(target, script):
    project_path = os.path.dirname(os.path.abspath(target))

    project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt')
    if os.path.isfile(project_uvopt):
        os.unlink(project_uvopt)

    tree = etree.parse('template.uvproj')
    root = tree.getroot()
    
    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
    
    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''
    ProjectFiles = []
    
    # add group
    groups = tree.find('Targets/Target/Groups')
    if groups is None:
        groups = SubElement(tree.find('Targets/Target'), 'Groups')
    for group in script:
        group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)
        
        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            if CPPPATH:
                CPPPATH += group['CPPPATH']
            else:
                CPPPATH += group['CPPPATH']
        
        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            if CPPDEFINES:
                CPPDEFINES += group['CPPDEFINES']
            else:
                CPPDEFINES += group['CPPDEFINES']
        
        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            if LINKFLAGS:
                LINKFLAGS += ' ' + group['LINKFLAGS']
            else:
                LINKFLAGS += group['LINKFLAGS']
    
        if group.has_key('LIBS') and group['LIBS']:
            for item in group['LIBS']:
                lib_path = ''
                for path_item in group['LIBPATH']:
                    full_path = os.path.join(path_item, item + '.lib')
                    if os.path.isfile(full_path): # has this library
                        lib_path = full_path

                if lib_path != '':
                    MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)

    # remove repeat path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc) #.replace('\\', '/')
    
    paths = [i for i in paths]
    paths.sort()
    CPPPATH = string.join(paths, ';')
    
    definitions = [i for i in set(CPPDEFINES)]
    CPPDEFINES = string.join(definitions, ', ')
    
    # write include path, definitions and link flags
    IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
    IncludePath.text = CPPPATH
    
    Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
    Define.text = CPPDEFINES

    Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
    Misc.text = LINKFLAGS
    
    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 51
0
def TargetCodelite(script, program):
    project_name = os.path.abspath('.').replace('\\', '/').split('/')[-1]
    #project_name.replace('-', '_')
    project_path = os.path.abspath('.')
    CLGenWorkspace(project_name, project_path)

    if os.path.isfile('codelite_template.project'):
        tree = etree.parse('codelite_template.project')
    else:
        tree = etree.parse(
            os.path.join(os.path.dirname(__file__),
                         'codelite_template.project'))

    root = tree.getroot()
    root.attrib['Name'] = project_name

    out = open(project_name + '.project', 'w')
    out.write('<?xml version="1.0" encoding="UTF-8"?>\n')

    # add files
    for group in script:
        CLAddCFiles(root, group['src'], project_path)
    # add header file
    CLAddHeaderFiles(root, program, project_path)

    # SECTION 2.
    # write head include path

    if 'CPPPATH' in building.Env:
        cpp_path = building.Env['CPPPATH']
        paths = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc)  #.replace('\\', '/')

        paths = [i for i in paths]
        paths.sort()

        # write include path, definitions
        for elem in tree.iter(tag='Compiler'):
            break

        for path in paths:
            CLAddIncludePath(root, path)

        #print building.Env.get('LIBPATH', [])
        #print building.Env.get('LIBS', [])

        CLSetCFlags(root, building.Env.get('CFLAGS', []))
        CLSetCxxFlags(root, building.Env.get('CFLAGS', []))

        asflags = building.Env.get('ASFLAGS', [])
        asflags = asflags.replace('-ffunction-sections', '')
        asflags = asflags.replace('-fdata-sections', '')
        asflags = asflags.replace('-x', '')
        asflags = asflags.replace('-Wa,', '')
        asflags = asflags.replace('assembler-with-cpp', '')
        CLSetAsFlags(root, asflags)
        CLSetLdFlags(root, building.Env.get('LINKFLAGS', []))

        for macro in building.Env.get('CPPDEFINES', []):
            for d in macro:
                CLAddPreprocessor(root, d)

    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 52
0
def MDK45Project(tree, target, script):
    project_path = os.path.dirname(os.path.abspath(target))

    root = tree.getroot()
    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')

    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''
    ProjectFiles = []

    # add group
    groups = tree.find('Targets/Target/Groups')
    if groups is None:
        groups = SubElement(tree.find('Targets/Target'), 'Groups')
    groups.clear() # clean old groups
    for group in script:
        group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)

        # for local CPPPATH/CPPDEFINES
        if (group_tree != None) and (group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CCFLAGS')):
            GroupOption     = SubElement(group_tree,  'GroupOption')
            GroupArmAds     = SubElement(GroupOption, 'GroupArmAds')
            Cads            = SubElement(GroupArmAds, 'Cads')
            VariousControls = SubElement(Cads, 'VariousControls')
            MiscControls    = SubElement(VariousControls, 'MiscControls')
            if group.has_key('LOCAL_CCFLAGS'):
                MiscControls.text = group['LOCAL_CCFLAGS']
            else:
                MiscControls.text = ' '
            Define          = SubElement(VariousControls, 'Define')
            if group.has_key('LOCAL_CPPDEFINES'):
                Define.text     = ', '.join(set(group['LOCAL_CPPDEFINES']))
            else:
                Define.text     = ' '
            Undefine        = SubElement(VariousControls, 'Undefine')
            Undefine.text   = ' '
            IncludePath     = SubElement(VariousControls, 'IncludePath')
            if group.has_key('LOCAL_CPPPATH'):
                IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH']])
            else:
                IncludePath.text = ' '

        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            if CPPPATH:
                CPPPATH += group['CPPPATH']
            else:
                CPPPATH += group['CPPPATH']

        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            if CPPDEFINES:
                CPPDEFINES += group['CPPDEFINES']
            else:
                CPPDEFINES += group['CPPDEFINES']

        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            if LINKFLAGS:
                LINKFLAGS += ' ' + group['LINKFLAGS']
            else:
                LINKFLAGS += group['LINKFLAGS']

        if group.has_key('LIBS') and group['LIBS']:
            for item in group['LIBS']:
                lib_path = ''
                for path_item in group['LIBPATH']:
                    full_path = os.path.join(path_item, item + '.lib')
                    if os.path.isfile(full_path): # has this library
                        lib_path = full_path

                if lib_path != '':
                    if (group_tree != None):
                        MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
                    else:
                        MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)

    # write include path, definitions and link flags
    IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
    IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in CPPPATH])

    Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
    Define.text = ', '.join(set(CPPDEFINES))

    Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
    Misc.text = LINKFLAGS

    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 53
0
def CBProject(target, script, program):
    project_path = os.path.dirname(os.path.abspath(target))

    if os.path.isfile('template.cbp'):
        tree = etree.parse('template.cbp')
    else:
        tree = etree.parse(os.path.join(os.path.dirname(__file__), 'template.cbp'))
    
    root = tree.getroot()
    
    out = file(target, 'wb')
    out.write('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\n')
    
    ProjectFiles = []
    
    # SECTION 1. add "*.c|*.h" files group
    for elem in tree.iter(tag='Project'):
        # print elem.tag, elem.attrib
        break
    # add c files
    for group in script:
        group_xml = CB_AddCFiles(ProjectFiles, elem, group['name'], group['src'], project_path)
    # add h files
    CB_AddHeadFiles(program, elem, project_path)

    # SECTION 2. 
    # write head include path
    if building.Env.has_key('CPPPATH'):
        cpp_path = building.Env['CPPPATH']
        paths  = set()
        for path in cpp_path:
            inc = _make_path_relative(project_path, os.path.normpath(path))
            paths.add(inc) #.replace('\\', '/')
    
        paths = [i for i in paths]
        paths.sort()
        # write include path, definitions
        for elem in tree.iter(tag='Compiler'):
            break
        for path in paths:
            Add = SubElement(elem, 'Add')
            Add.set('directory', path)

        for macro in building.Env.get('CPPDEFINES', []):
            Add = SubElement(elem, 'Add')
            Add.set('option', "-D"+macro)
        
        # write link flags
    '''
        # write lib dependence 
        if building.Env.has_key('LIBS'):
            for elem in tree.iter(tag='Tool'):
                if elem.attrib['Name'] == 'VCLinkerTool':
                    break
            libs_with_extention = [i+'.lib' for i in building.Env['LIBS']]
            libs = ' '.join(libs_with_extention)
            elem.set('AdditionalDependencies', libs)
    
        # write lib include path
        if building.Env.has_key('LIBPATH'):
            lib_path = building.Env['LIBPATH']
            paths  = set()
            for path in lib_path:
                inc = _make_path_relative(project_path, os.path.normpath(path))
                paths.add(inc) #.replace('\\', '/')
        
            paths = [i for i in paths]
            paths.sort()
            lib_paths = ';'.join(paths)
            elem.set('AdditionalLibraryDirectories', lib_paths)
    '''
    xml_indent(root)
    out.write(etree.tostring(root, encoding='utf-8'))
    out.close()
Ejemplo n.º 54
0
def MDK5Project(target, script):
    project_path = os.path.dirname(os.path.abspath(target))

    project_uvopt = os.path.abspath(target).replace("uvprojx", "uvoptx")
    if os.path.isfile(project_uvopt):
        os.unlink(project_uvopt)

    tree = etree.parse("template.uvprojx")
    root = tree.getroot()

    out = file(target, "wb")
    out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')

    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ""
    CCFLAGS = ""
    ProjectFiles = []

    # add group
    groups = tree.find("Targets/Target/Groups")
    if groups is None:
        groups = SubElement(tree.find("Targets/Target"), "Groups")
    for group in script:
        group_xml = MDK4AddGroup(ProjectFiles, groups, group["name"], group["src"], project_path)

        # get each include path
        if group.has_key("CPPPATH") and group["CPPPATH"]:
            if CPPPATH:
                CPPPATH += group["CPPPATH"]
            else:
                CPPPATH += group["CPPPATH"]

        # get each group's definitions
        if group.has_key("CPPDEFINES") and group["CPPDEFINES"]:
            if CPPDEFINES:
                CPPDEFINES += group["CPPDEFINES"]
            else:
                CPPDEFINES += group["CPPDEFINES"]

        # get each group's link flags
        if group.has_key("LINKFLAGS") and group["LINKFLAGS"]:
            if LINKFLAGS:
                LINKFLAGS += " " + group["LINKFLAGS"]
            else:
                LINKFLAGS += group["LINKFLAGS"]

        if group.has_key("LIBS") and group["LIBS"]:
            for item in group["LIBS"]:
                lib_path = ""
                for path_item in group["LIBPATH"]:
                    full_path = os.path.join(path_item, item + ".lib")
                    if os.path.isfile(full_path):  # has this library
                        lib_path = full_path

                if lib_path != "":
                    MDK4AddGroupForFN(ProjectFiles, groups, group["name"], lib_path, project_path)

    # remove repeat path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc)  # .replace('\\', '/')

    paths = [i for i in paths]
    paths.sort()
    CPPPATH = string.join(paths, ";")

    definitions = [i for i in set(CPPDEFINES)]
    CPPDEFINES = string.join(definitions, ", ")

    # write include path, definitions and link flags
    IncludePath = tree.find("Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath")
    IncludePath.text = CPPPATH

    Define = tree.find("Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define")
    Define.text = CPPDEFINES

    Misc = tree.find("Targets/Target/TargetOption/TargetArmAds/LDads/Misc")
    Misc.text = LINKFLAGS

    xml_indent(root)
    out.write(etree.tostring(root, encoding="utf-8"))
    out.close()

    # copy uvopt file
    if os.path.exists("template.uvoptx"):
        import shutil

        shutil.copy2("template.uvoptx", "project.uvoptx")
Ejemplo n.º 55
0
def MDKProject(target, script):
    template = file('template.Uv2', "rb")
    lines = template.readlines()

    project = file(target, "wb")
    project_path = os.path.dirname(os.path.abspath(target))

    line_index = 5
    # write group
    for group in script:
        lines.insert(line_index, 'Group (%s)\r\n' % group['name'])
        line_index += 1

    lines.insert(line_index, '\r\n')
    line_index += 1

    # write file

    ProjectFiles = []
    CPPPATH = []
    CPPDEFINES = []
    LINKFLAGS = ''
    CCFLAGS = ''

    # number of groups
    group_index = 1
    for group in script:
        # print group['name']

        # get each include path
        if group.has_key('CPPPATH') and group['CPPPATH']:
            if CPPPATH:
                CPPPATH += group['CPPPATH']
            else:
                CPPPATH += group['CPPPATH']

        # get each group's definitions
        if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
            if CPPDEFINES:
                CPPDEFINES += ';' + group['CPPDEFINES']
            else:
                CPPDEFINES += group['CPPDEFINES']

        # get each group's link flags
        if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
            if LINKFLAGS:
                LINKFLAGS += ' ' + group['LINKFLAGS']
            else:
                LINKFLAGS += group['LINKFLAGS']

        # generate file items
        for node in group['src']:
            fn = node.rfile()
            name = fn.name
            path = os.path.dirname(fn.abspath)
            basename = os.path.basename(path)
            path = _make_path_relative(project_path, path)
            path = os.path.join(path, name)
            if ProjectFiles.count(name):
                name = basename + '_' + name
            ProjectFiles.append(name)
            lines.insert(
                line_index, 'File %d,%d,<%s><%s>\r\n' %
                (group_index, _get_filetype(name), path, name))
            line_index += 1

        group_index = group_index + 1

    lines.insert(line_index, '\r\n')
    line_index += 1

    # remove repeat path
    paths = set()
    for path in CPPPATH:
        inc = _make_path_relative(project_path, os.path.normpath(path))
        paths.add(inc)  #.replace('\\', '/')

    paths = [i for i in paths]
    CPPPATH = string.join(paths, ';')

    definitions = [i for i in set(CPPDEFINES)]
    CPPDEFINES = string.join(definitions, ', ')

    while line_index < len(lines):
        if lines[line_index].startswith(' ADSCINCD '):
            lines[line_index] = ' ADSCINCD (' + CPPPATH + ')\r\n'

        if lines[line_index].startswith(' ADSLDMC ('):
            lines[line_index] = ' ADSLDMC (' + LINKFLAGS + ')\r\n'

        if lines[line_index].startswith(' ADSCDEFN ('):
            lines[line_index] = ' ADSCDEFN (' + CPPDEFINES + ')\r\n'

        line_index += 1

    # write project
    for line in lines:
        project.write(line)

    project.close()