Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theotherjimmy 43:2a7da56ebd24 1 from __future__ import print_function, absolute_import
theotherjimmy 43:2a7da56ebd24 2 from builtins import str
theotherjimmy 43:2a7da56ebd24 3
theotherjimmy 43:2a7da56ebd24 4 import os
theotherjimmy 43:2a7da56ebd24 5 import copy
theotherjimmy 43:2a7da56ebd24 6 import shutil
theotherjimmy 43:2a7da56ebd24 7
theotherjimmy 43:2a7da56ebd24 8 from os.path import relpath, join, exists, dirname, basename
theotherjimmy 43:2a7da56ebd24 9 from os import makedirs, remove
theotherjimmy 43:2a7da56ebd24 10 from json import load
theotherjimmy 43:2a7da56ebd24 11
theotherjimmy 43:2a7da56ebd24 12 from tools.export.exporters import Exporter, apply_supported_whitelist
theotherjimmy 43:2a7da56ebd24 13 from tools.targets import TARGET_MAP
theotherjimmy 43:2a7da56ebd24 14 from tools.utils import NotSupportedException
theotherjimmy 43:2a7da56ebd24 15 from tools.build_api import prepare_toolchain
theotherjimmy 43:2a7da56ebd24 16
theotherjimmy 43:2a7da56ebd24 17 POST_BINARY_WHITELIST = set([
theotherjimmy 43:2a7da56ebd24 18 "TEENSY3_1Code.binary_hook",
theotherjimmy 43:2a7da56ebd24 19 "MCU_NRF51Code.binary_hook",
theotherjimmy 43:2a7da56ebd24 20 "LPCTargetCode.lpc_patch",
theotherjimmy 43:2a7da56ebd24 21 "LPC4088Code.binary_hook"
theotherjimmy 43:2a7da56ebd24 22 ])
theotherjimmy 43:2a7da56ebd24 23
theotherjimmy 43:2a7da56ebd24 24
theotherjimmy 43:2a7da56ebd24 25 class GNUARMNetbeans(Exporter):
theotherjimmy 43:2a7da56ebd24 26 NAME = 'GNU ARM Netbeans'
theotherjimmy 43:2a7da56ebd24 27 TOOLCHAIN = 'GCC_ARM'
theotherjimmy 43:2a7da56ebd24 28
theotherjimmy 43:2a7da56ebd24 29 @classmethod
theotherjimmy 43:2a7da56ebd24 30 def is_target_supported(cls, target_name):
theotherjimmy 43:2a7da56ebd24 31 target = TARGET_MAP[target_name]
theotherjimmy 43:2a7da56ebd24 32 return apply_supported_whitelist(
theotherjimmy 43:2a7da56ebd24 33 cls.TOOLCHAIN, POST_BINARY_WHITELIST, target)
theotherjimmy 43:2a7da56ebd24 34
theotherjimmy 43:2a7da56ebd24 35 @staticmethod
theotherjimmy 43:2a7da56ebd24 36 def prepare_sys_lib(libname):
theotherjimmy 43:2a7da56ebd24 37 return "-l" + libname
theotherjimmy 43:2a7da56ebd24 38
theotherjimmy 43:2a7da56ebd24 39 @staticmethod
theotherjimmy 43:2a7da56ebd24 40 def get_defines_and_remove_from_flags(flags_in, str_key):
theotherjimmy 43:2a7da56ebd24 41 defines = []
theotherjimmy 43:2a7da56ebd24 42 flags_temp = copy.deepcopy(flags_in)
theotherjimmy 43:2a7da56ebd24 43 for f in flags_temp[str_key]:
theotherjimmy 43:2a7da56ebd24 44 f = f.strip()
theotherjimmy 43:2a7da56ebd24 45 if f.startswith('-D'):
theotherjimmy 43:2a7da56ebd24 46 defines.append(f[2:])
theotherjimmy 43:2a7da56ebd24 47 flags_in[str_key].remove(f)
theotherjimmy 43:2a7da56ebd24 48
theotherjimmy 43:2a7da56ebd24 49 return defines
theotherjimmy 43:2a7da56ebd24 50
theotherjimmy 43:2a7da56ebd24 51 @staticmethod
theotherjimmy 43:2a7da56ebd24 52 def get_includes_and_remove_from_flags(flags_in, str_key):
theotherjimmy 43:2a7da56ebd24 53 includes = []
theotherjimmy 43:2a7da56ebd24 54 flags_temp = copy.deepcopy(flags_in)
theotherjimmy 43:2a7da56ebd24 55 next_is_include = False
theotherjimmy 43:2a7da56ebd24 56 for f in flags_temp[str_key]:
theotherjimmy 43:2a7da56ebd24 57 f = f.strip()
theotherjimmy 43:2a7da56ebd24 58 if next_is_include:
theotherjimmy 43:2a7da56ebd24 59 includes.append(f)
theotherjimmy 43:2a7da56ebd24 60 flags_in[str_key].remove(f)
theotherjimmy 43:2a7da56ebd24 61 next_is_include = False
theotherjimmy 43:2a7da56ebd24 62 continue
theotherjimmy 43:2a7da56ebd24 63 if f == "-include":
theotherjimmy 43:2a7da56ebd24 64 flags_in[str_key].remove(f)
theotherjimmy 43:2a7da56ebd24 65 next_is_include = True
theotherjimmy 43:2a7da56ebd24 66
theotherjimmy 43:2a7da56ebd24 67 return includes
theotherjimmy 43:2a7da56ebd24 68
theotherjimmy 43:2a7da56ebd24 69 @staticmethod
theotherjimmy 43:2a7da56ebd24 70 def get_c_std_and_remove_from_flag(flags_in, str_key):
theotherjimmy 43:2a7da56ebd24 71 comp_std = ''
theotherjimmy 43:2a7da56ebd24 72 c_std = {
theotherjimmy 43:2a7da56ebd24 73 'c90': 'c90', 'c89': 'c90', 'gnu90': 'gnu90', 'gnu89': 'gnu90',
theotherjimmy 43:2a7da56ebd24 74 'c99': 'c99', 'c9x': 'c99', 'gnu99': 'gnu99', 'gnu9x': 'gnu98',
theotherjimmy 43:2a7da56ebd24 75 'c11': 'c11', 'c1x': 'c11', 'gnu11': 'gnu11', 'gnu1x': 'gnu11'
theotherjimmy 43:2a7da56ebd24 76 }
theotherjimmy 43:2a7da56ebd24 77 cpp_std = {
theotherjimmy 43:2a7da56ebd24 78 'c++98': 'cpp98', 'c++03': 'cpp98',
theotherjimmy 43:2a7da56ebd24 79 'gnu++98': 'gnucpp98', 'gnu++03': 'gnucpp98',
theotherjimmy 43:2a7da56ebd24 80 'c++0x': 'cpp0x', 'gnu++0x': 'gnucpp0x',
theotherjimmy 43:2a7da56ebd24 81 'c++11': 'cpp11', 'gnu++11': 'gnucpp11',
theotherjimmy 43:2a7da56ebd24 82 'c++1y': 'cpp1y', 'gnu++1y': 'gnucpp1y',
theotherjimmy 43:2a7da56ebd24 83 'c++14': 'cpp14', 'gnu++14': 'gnucpp14',
theotherjimmy 43:2a7da56ebd24 84 'c++1z': 'cpp1z', 'gnu++1z': 'gnucpp1z',
theotherjimmy 43:2a7da56ebd24 85 }
theotherjimmy 43:2a7da56ebd24 86
theotherjimmy 43:2a7da56ebd24 87 flags_temp = copy.deepcopy(flags_in)
theotherjimmy 43:2a7da56ebd24 88 for f in flags_temp[str_key]:
theotherjimmy 43:2a7da56ebd24 89 f = f.strip()
theotherjimmy 43:2a7da56ebd24 90 if f.startswith('-std='):
theotherjimmy 43:2a7da56ebd24 91 comp_std = f[len('-std='):]
theotherjimmy 43:2a7da56ebd24 92 flags_in[str_key].remove(f)
theotherjimmy 43:2a7da56ebd24 93 elif f.startswith('-'):
theotherjimmy 43:2a7da56ebd24 94 std = f[len('-'):]
theotherjimmy 43:2a7da56ebd24 95 if std in c_std or std in cpp_std:
theotherjimmy 43:2a7da56ebd24 96 comp_std = std
theotherjimmy 43:2a7da56ebd24 97 flags_in[str_key].remove(f)
theotherjimmy 43:2a7da56ebd24 98 return comp_std
theotherjimmy 43:2a7da56ebd24 99
theotherjimmy 43:2a7da56ebd24 100 def validate_resources(self):
theotherjimmy 43:2a7da56ebd24 101 if not self.resources.linker_script:
theotherjimmy 43:2a7da56ebd24 102 raise NotSupportedException("No linker script found.")
theotherjimmy 43:2a7da56ebd24 103
theotherjimmy 43:2a7da56ebd24 104 def create_jinja_ctx(self):
theotherjimmy 43:2a7da56ebd24 105 self.options = {}
theotherjimmy 43:2a7da56ebd24 106 flags = {}
theotherjimmy 43:2a7da56ebd24 107 self.validate_resources()
theotherjimmy 43:2a7da56ebd24 108 # Convert all Backslashes to Forward Slashes
theotherjimmy 43:2a7da56ebd24 109 self.resources.win_to_unix()
theotherjimmy 43:2a7da56ebd24 110
theotherjimmy 43:2a7da56ebd24 111 self.ld_script = self.filter_dot(
theotherjimmy 43:2a7da56ebd24 112 self.resources.linker_script)
theotherjimmy 43:2a7da56ebd24 113
theotherjimmy 43:2a7da56ebd24 114 # Read in all profiles, we'll extract compiler options.
theotherjimmy 43:2a7da56ebd24 115 profiles = self.get_all_profiles()
theotherjimmy 43:2a7da56ebd24 116
theotherjimmy 43:2a7da56ebd24 117 profile_ids = [s.lower() for s in profiles]
theotherjimmy 43:2a7da56ebd24 118 profile_ids.sort()
theotherjimmy 43:2a7da56ebd24 119 for prof_id in profile_ids:
theotherjimmy 43:2a7da56ebd24 120 # There are 4 categories of options, a category common too
theotherjimmy 43:2a7da56ebd24 121 # all tools and a specific category for each of the tools.
theotherjimmy 43:2a7da56ebd24 122 opts = {}
theotherjimmy 43:2a7da56ebd24 123 opts['defines'] = {}
theotherjimmy 43:2a7da56ebd24 124 opts['common'] = {}
theotherjimmy 43:2a7da56ebd24 125 opts['as'] = {}
theotherjimmy 43:2a7da56ebd24 126 opts['c'] = {}
theotherjimmy 43:2a7da56ebd24 127 opts['cpp'] = {}
theotherjimmy 43:2a7da56ebd24 128 opts['ld'] = {}
theotherjimmy 43:2a7da56ebd24 129
theotherjimmy 43:2a7da56ebd24 130 opts['id'] = prof_id
theotherjimmy 43:2a7da56ebd24 131 opts['name'] = opts['id'].capitalize()
theotherjimmy 43:2a7da56ebd24 132
theotherjimmy 43:2a7da56ebd24 133 profile = profiles[prof_id]
theotherjimmy 43:2a7da56ebd24 134
theotherjimmy 43:2a7da56ebd24 135 # A small hack, do not bother with src_path again,
theotherjimmy 43:2a7da56ebd24 136 # pass an empty string to avoid crashing.
theotherjimmy 43:2a7da56ebd24 137 src_paths = ['']
theotherjimmy 43:2a7da56ebd24 138 target_name = self.toolchain.target.name
theotherjimmy 43:2a7da56ebd24 139
theotherjimmy 43:2a7da56ebd24 140 toolchain = prepare_toolchain(
theotherjimmy 43:2a7da56ebd24 141 src_paths, "", target_name, self.TOOLCHAIN, build_profile=[profile])
theotherjimmy 43:2a7da56ebd24 142
theotherjimmy 43:2a7da56ebd24 143 flags = self.toolchain_flags(toolchain)
theotherjimmy 43:2a7da56ebd24 144
theotherjimmy 43:2a7da56ebd24 145 opts['defines'] = self.get_defines_and_remove_from_flags(flags, 'common_flags')
theotherjimmy 43:2a7da56ebd24 146 opts['forced_includes'] = self.get_includes_and_remove_from_flags(flags, 'common_flags')
theotherjimmy 43:2a7da56ebd24 147 opts['common'] = flags['common_flags']
theotherjimmy 43:2a7da56ebd24 148 opts['as'] = flags['asm_flags']
theotherjimmy 43:2a7da56ebd24 149 opts['c'] = flags['c_flags']
theotherjimmy 43:2a7da56ebd24 150 opts['cpp'] = flags['cxx_flags']
theotherjimmy 43:2a7da56ebd24 151 opts['ld'] = flags['ld_flags']
theotherjimmy 43:2a7da56ebd24 152
theotherjimmy 43:2a7da56ebd24 153 self.options[prof_id] = opts
theotherjimmy 43:2a7da56ebd24 154
theotherjimmy 43:2a7da56ebd24 155 sources = [] # list of strings
theotherjimmy 43:2a7da56ebd24 156
theotherjimmy 43:2a7da56ebd24 157 forced_includes = self.get_includes_and_remove_from_flags(flags, 'c_flags')
theotherjimmy 43:2a7da56ebd24 158 forced_includes += self.get_includes_and_remove_from_flags(flags, 'cxx_flags')
theotherjimmy 43:2a7da56ebd24 159
theotherjimmy 43:2a7da56ebd24 160 # Remove Duplicates
theotherjimmy 43:2a7da56ebd24 161 forced_includes = list(set(forced_includes))
theotherjimmy 43:2a7da56ebd24 162
theotherjimmy 43:2a7da56ebd24 163 c_std = self.get_c_std_and_remove_from_flag(flags, 'c_flags')
theotherjimmy 43:2a7da56ebd24 164 cpp_std = self.get_c_std_and_remove_from_flag(flags, 'cxx_flags')
theotherjimmy 43:2a7da56ebd24 165
theotherjimmy 43:2a7da56ebd24 166 # Make one list of all resources
theotherjimmy 43:2a7da56ebd24 167 for r_type in ['c_sources', 's_sources', 'cpp_sources']:
theotherjimmy 43:2a7da56ebd24 168 sources.extend(getattr(self.resources, r_type))
theotherjimmy 43:2a7da56ebd24 169
theotherjimmy 43:2a7da56ebd24 170 # Remove all leading './'
theotherjimmy 43:2a7da56ebd24 171 c_sources = [self.filter_dot(field) for field in self.resources.c_sources]
theotherjimmy 43:2a7da56ebd24 172 cpp_sources = [self.filter_dot(field) for field in self.resources.cpp_sources]
theotherjimmy 43:2a7da56ebd24 173 s_sources = [self.filter_dot(field) for field in self.resources.s_sources]
theotherjimmy 43:2a7da56ebd24 174 headers = [self.filter_dot(field) for field in self.resources.headers]
theotherjimmy 43:2a7da56ebd24 175 sources = [self.filter_dot(field) for field in sources]
theotherjimmy 43:2a7da56ebd24 176 include_paths = [self.filter_dot(field) for field in self.resources.inc_dirs]
theotherjimmy 43:2a7da56ebd24 177
theotherjimmy 43:2a7da56ebd24 178 sys_libs = [self.prepare_sys_lib(lib) for lib
theotherjimmy 43:2a7da56ebd24 179 in self.toolchain.sys_libs]
theotherjimmy 43:2a7da56ebd24 180 preproc = " ".join([basename(self.toolchain.preproc[0])] +
theotherjimmy 43:2a7da56ebd24 181 self.toolchain.preproc[1:] +
theotherjimmy 43:2a7da56ebd24 182 self.toolchain.ld[1:])
theotherjimmy 43:2a7da56ebd24 183
theotherjimmy 43:2a7da56ebd24 184 if 'nbproject' in include_paths:
theotherjimmy 43:2a7da56ebd24 185 include_paths.remove('nbproject')
theotherjimmy 43:2a7da56ebd24 186
theotherjimmy 43:2a7da56ebd24 187 jinja_ctx = {
theotherjimmy 43:2a7da56ebd24 188 'name': self.project_name,
theotherjimmy 43:2a7da56ebd24 189 'target': self.toolchain.target.name,
theotherjimmy 43:2a7da56ebd24 190 'elf_location': join('BUILD', self.project_name) + '.elf',
theotherjimmy 43:2a7da56ebd24 191 'c_symbols': self.toolchain.get_symbols(),
theotherjimmy 43:2a7da56ebd24 192 'asm_symbols': self.toolchain.get_symbols(True),
theotherjimmy 43:2a7da56ebd24 193 'c_flags': flags['c_flags'],
theotherjimmy 43:2a7da56ebd24 194 'cxx_flags': flags['cxx_flags'],
theotherjimmy 43:2a7da56ebd24 195 'ld_flags': self.flags['ld_flags'],
theotherjimmy 43:2a7da56ebd24 196 'asm_flags': self.flags['asm_flags'],
theotherjimmy 43:2a7da56ebd24 197 'common_flags': self.flags['common_flags'],
theotherjimmy 43:2a7da56ebd24 198 'include_paths': include_paths,
theotherjimmy 43:2a7da56ebd24 199 'forced_includes': forced_includes,
theotherjimmy 43:2a7da56ebd24 200 'c_sources': c_sources,
theotherjimmy 43:2a7da56ebd24 201 'cpp_sources': cpp_sources,
theotherjimmy 43:2a7da56ebd24 202 's_sources': s_sources,
theotherjimmy 43:2a7da56ebd24 203 'headers': headers,
theotherjimmy 43:2a7da56ebd24 204 'headers_folder': self.get_netbeans_file_list(sorted(headers)),
theotherjimmy 43:2a7da56ebd24 205 'sources_folder': self.get_netbeans_file_list(sorted(sources)),
theotherjimmy 43:2a7da56ebd24 206 'options': self.options,
theotherjimmy 43:2a7da56ebd24 207 'c_std': self.get_netbeans_c_std(c_std),
theotherjimmy 43:2a7da56ebd24 208 'cpp_std': self.get_netbeans_cpp_std(cpp_std),
theotherjimmy 43:2a7da56ebd24 209 'linker_script': self.ld_script,
theotherjimmy 43:2a7da56ebd24 210 'linker_libs': sys_libs,
theotherjimmy 43:2a7da56ebd24 211 'pp_cmd': preproc,
theotherjimmy 43:2a7da56ebd24 212 'cc_cmd': self.toolchain.cc[0],
theotherjimmy 43:2a7da56ebd24 213 'cppc_cmd': self.toolchain.cppc[0],
theotherjimmy 43:2a7da56ebd24 214 'asm_cmd': self.toolchain.asm[0],
theotherjimmy 43:2a7da56ebd24 215 'ld_cmd': self.toolchain.ld[0],
theotherjimmy 43:2a7da56ebd24 216 'elf2bin_cmd': self.toolchain.elf2bin
theotherjimmy 43:2a7da56ebd24 217 }
theotherjimmy 43:2a7da56ebd24 218 return jinja_ctx
theotherjimmy 43:2a7da56ebd24 219
theotherjimmy 43:2a7da56ebd24 220 def generate(self):
theotherjimmy 43:2a7da56ebd24 221 """Generate Makefile, configurations.xml & project.xml Netbeans project file
theotherjimmy 43:2a7da56ebd24 222 """
theotherjimmy 43:2a7da56ebd24 223 jinja_ctx = self.create_jinja_ctx()
theotherjimmy 43:2a7da56ebd24 224
theotherjimmy 43:2a7da56ebd24 225 if not exists(join(self.export_dir, 'nbproject')):
theotherjimmy 43:2a7da56ebd24 226 makedirs(join(self.export_dir, 'nbproject'))
theotherjimmy 43:2a7da56ebd24 227
theotherjimmy 43:2a7da56ebd24 228 self.gen_file('nb/configurations.tmpl', jinja_ctx, 'nbproject/configurations.xml')
theotherjimmy 43:2a7da56ebd24 229 self.gen_file('nb/project.tmpl', jinja_ctx, 'nbproject/project.xml')
theotherjimmy 43:2a7da56ebd24 230 self.gen_file_nonoverwrite('nb/mbedignore.tmpl', jinja_ctx,
theotherjimmy 43:2a7da56ebd24 231 '.mbedignore')
theotherjimmy 43:2a7da56ebd24 232 self.gen_file('nb/Makefile.tmpl', jinja_ctx, 'Makefile')
theotherjimmy 43:2a7da56ebd24 233
theotherjimmy 43:2a7da56ebd24 234 print('Done. Import the \'{0}\' project in Netbeans.'.format(self.project_name))
theotherjimmy 43:2a7da56ebd24 235
theotherjimmy 43:2a7da56ebd24 236 @staticmethod
theotherjimmy 43:2a7da56ebd24 237 def clean(_):
theotherjimmy 43:2a7da56ebd24 238 shutil.rmtree("nbproject")
theotherjimmy 43:2a7da56ebd24 239 remove("Makefile")
theotherjimmy 43:2a7da56ebd24 240
theotherjimmy 43:2a7da56ebd24 241 # -------------------------------------------------------------------------
theotherjimmy 43:2a7da56ebd24 242
theotherjimmy 43:2a7da56ebd24 243 @staticmethod
theotherjimmy 43:2a7da56ebd24 244 def filter_dot(str_in):
theotherjimmy 43:2a7da56ebd24 245 """
theotherjimmy 43:2a7da56ebd24 246 Remove the './' prefix, if present.
theotherjimmy 43:2a7da56ebd24 247 This function assumes that resources.win_to_unix()
theotherjimmy 43:2a7da56ebd24 248 replaced all windows backslashes with slashes.
theotherjimmy 43:2a7da56ebd24 249 """
theotherjimmy 43:2a7da56ebd24 250 if str_in is None:
theotherjimmy 43:2a7da56ebd24 251 return None
theotherjimmy 43:2a7da56ebd24 252 if str_in[:2] == './':
theotherjimmy 43:2a7da56ebd24 253 return str_in[2:]
theotherjimmy 43:2a7da56ebd24 254 return str_in
theotherjimmy 43:2a7da56ebd24 255
theotherjimmy 43:2a7da56ebd24 256 # -------------------------------------------------------------------------
theotherjimmy 43:2a7da56ebd24 257
theotherjimmy 43:2a7da56ebd24 258 @staticmethod
theotherjimmy 43:2a7da56ebd24 259 def get_all_profiles():
theotherjimmy 43:2a7da56ebd24 260 tools_path = dirname(dirname(dirname(__file__)))
theotherjimmy 43:2a7da56ebd24 261 file_names = [join(tools_path, "profiles", fn) for fn in os.listdir(
theotherjimmy 43:2a7da56ebd24 262 join(tools_path, "profiles")) if fn.endswith(".json")]
theotherjimmy 43:2a7da56ebd24 263
theotherjimmy 43:2a7da56ebd24 264 profiles = {}
theotherjimmy 43:2a7da56ebd24 265
theotherjimmy 43:2a7da56ebd24 266 for fn in file_names:
theotherjimmy 43:2a7da56ebd24 267 content = load(open(fn))
theotherjimmy 43:2a7da56ebd24 268 profile_name = basename(fn).replace(".json", "")
theotherjimmy 43:2a7da56ebd24 269 profiles[profile_name] = content
theotherjimmy 43:2a7da56ebd24 270
theotherjimmy 43:2a7da56ebd24 271 return profiles
theotherjimmy 43:2a7da56ebd24 272
theotherjimmy 43:2a7da56ebd24 273 @staticmethod
theotherjimmy 43:2a7da56ebd24 274 def get_netbeans_file_list(file_list):
theotherjimmy 43:2a7da56ebd24 275 cur_dir = ''
theotherjimmy 43:2a7da56ebd24 276 prev_dir = ''
theotherjimmy 43:2a7da56ebd24 277 output = []
theotherjimmy 43:2a7da56ebd24 278 folder_count = 1
theotherjimmy 43:2a7da56ebd24 279 dir_depth = 0
theotherjimmy 43:2a7da56ebd24 280 for item in file_list:
theotherjimmy 43:2a7da56ebd24 281 cur_dir = os.path.dirname(item)
theotherjimmy 43:2a7da56ebd24 282 dir_temp = os.path.normpath(cur_dir)
theotherjimmy 43:2a7da56ebd24 283 prev_dir_temp = os.path.normpath(prev_dir)
theotherjimmy 43:2a7da56ebd24 284 dir_list = dir_temp.split(os.sep)
theotherjimmy 43:2a7da56ebd24 285 prev_dir_list = prev_dir_temp.split(os.sep)
theotherjimmy 43:2a7da56ebd24 286 dir_depth = len(dir_list)
theotherjimmy 43:2a7da56ebd24 287
theotherjimmy 43:2a7da56ebd24 288 # Current File is in Directory: Compare the given dir with previous Dir
theotherjimmy 43:2a7da56ebd24 289 if cur_dir and prev_dir != cur_dir:
theotherjimmy 43:2a7da56ebd24 290 # evaluate all matched items (from current and previous list)
theotherjimmy 43:2a7da56ebd24 291 matched = []
theotherjimmy 43:2a7da56ebd24 292 # Compare the Element in Previous Dir with the Elements in Current Dir
theotherjimmy 43:2a7da56ebd24 293 # and add the equal Elements to the match-List
theotherjimmy 43:2a7da56ebd24 294 for elem_prev_dir, elem_cur_dir in zip(prev_dir_list, dir_list):
theotherjimmy 43:2a7da56ebd24 295 if elem_prev_dir == elem_cur_dir:
theotherjimmy 43:2a7da56ebd24 296 matched.append(elem_cur_dir)
theotherjimmy 43:2a7da56ebd24 297
theotherjimmy 43:2a7da56ebd24 298 # calculate difference between matched and length
theotherjimmy 43:2a7da56ebd24 299 diff = dir_depth - len(matched)
theotherjimmy 43:2a7da56ebd24 300
theotherjimmy 43:2a7da56ebd24 301 # if previous dir was not root
theotherjimmy 43:2a7da56ebd24 302 if prev_dir != '':
theotherjimmy 43:2a7da56ebd24 303 # if the elements count is not equal we calculate the difference
theotherjimmy 43:2a7da56ebd24 304 if len(dir_list) != len(prev_dir_list):
theotherjimmy 43:2a7da56ebd24 305 dir_depth_prev = len(prev_dir_list)
theotherjimmy 43:2a7da56ebd24 306 delta = dir_depth_prev - len(matched)
theotherjimmy 43:2a7da56ebd24 307
theotherjimmy 43:2a7da56ebd24 308 for i in range(dir_depth_prev - delta, dir_depth_prev):
theotherjimmy 43:2a7da56ebd24 309 output.append('</logicalFolder>')
theotherjimmy 43:2a7da56ebd24 310
theotherjimmy 43:2a7da56ebd24 311 # if the elements count is equal, we subtract the matched length from the total length
theotherjimmy 43:2a7da56ebd24 312 else:
theotherjimmy 43:2a7da56ebd24 313 for i in range(len(matched), len(dir_list)):
theotherjimmy 43:2a7da56ebd24 314 output.append('</logicalFolder>')
theotherjimmy 43:2a7da56ebd24 315
theotherjimmy 43:2a7da56ebd24 316 for i in range(dir_depth - diff, dir_depth):
theotherjimmy 43:2a7da56ebd24 317 output.append('<logicalFolder name="f' + str(folder_count) + '" displayName="' + str(
theotherjimmy 43:2a7da56ebd24 318 dir_list[i]) + '" projectFiles="true">')
theotherjimmy 43:2a7da56ebd24 319 folder_count += 1
theotherjimmy 43:2a7da56ebd24 320
theotherjimmy 43:2a7da56ebd24 321 # Current File is in root
theotherjimmy 43:2a7da56ebd24 322 else:
theotherjimmy 43:2a7da56ebd24 323 # Close Tag if we are in root and the previous dir wasn't
theotherjimmy 43:2a7da56ebd24 324 if cur_dir == '' and prev_dir != '':
theotherjimmy 43:2a7da56ebd24 325 for i in range(0, len(prev_dir_list)):
theotherjimmy 43:2a7da56ebd24 326 output.append('</logicalFolder>')
theotherjimmy 43:2a7da56ebd24 327
theotherjimmy 43:2a7da56ebd24 328 # Save the Current Dir
theotherjimmy 43:2a7da56ebd24 329 prev_dir = cur_dir
theotherjimmy 43:2a7da56ebd24 330 output.append('<itemPath>' + str(item) + '</itemPath>')
theotherjimmy 43:2a7da56ebd24 331
theotherjimmy 43:2a7da56ebd24 332 if cur_dir != '':
theotherjimmy 43:2a7da56ebd24 333 # close all open tags
theotherjimmy 43:2a7da56ebd24 334 output.append('</logicalFolder>' * dir_depth)
theotherjimmy 43:2a7da56ebd24 335
theotherjimmy 43:2a7da56ebd24 336 return output
theotherjimmy 43:2a7da56ebd24 337
theotherjimmy 43:2a7da56ebd24 338 @staticmethod
theotherjimmy 43:2a7da56ebd24 339 def get_netbeans_c_std(c_std):
theotherjimmy 43:2a7da56ebd24 340 c_std_netbeans = 0
theotherjimmy 43:2a7da56ebd24 341 if '89' in c_std:
theotherjimmy 43:2a7da56ebd24 342 c_std_netbeans = 2
theotherjimmy 43:2a7da56ebd24 343 elif '99' in c_std:
theotherjimmy 43:2a7da56ebd24 344 c_std_netbeans = 3
theotherjimmy 43:2a7da56ebd24 345 elif '11' in c_std:
theotherjimmy 43:2a7da56ebd24 346 c_std_netbeans = 10
theotherjimmy 43:2a7da56ebd24 347 return c_std_netbeans
theotherjimmy 43:2a7da56ebd24 348
theotherjimmy 43:2a7da56ebd24 349 @staticmethod
theotherjimmy 43:2a7da56ebd24 350 def get_netbeans_cpp_std(cpp_std):
theotherjimmy 43:2a7da56ebd24 351 cpp_std_netbeans = 0
theotherjimmy 43:2a7da56ebd24 352 if '98' in cpp_std:
theotherjimmy 43:2a7da56ebd24 353 cpp_std_netbeans = 4
theotherjimmy 43:2a7da56ebd24 354 elif '11' in cpp_std:
theotherjimmy 43:2a7da56ebd24 355 cpp_std_netbeans = 8
theotherjimmy 43:2a7da56ebd24 356 elif '14' in cpp_std:
theotherjimmy 43:2a7da56ebd24 357 cpp_std_netbeans = 11
theotherjimmy 43:2a7da56ebd24 358 return cpp_std_netbeans