| 1 |
#! /usr/bin/env python3 |
| 2 |
# -*- Mode: python; tab-width: 4; indent-tabs-mode: t -*- |
| 3 |
# |
| 4 |
# This file is part of the LibreOffice project. |
| 5 |
# |
| 6 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 7 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 |
# |
| 10 |
|
| 11 |
import argparse |
| 12 |
import ntpath |
| 13 |
import os |
| 14 |
import os.path |
| 15 |
import shutil |
| 16 |
import re |
| 17 |
import sys |
| 18 |
import uuid |
| 19 |
import json |
| 20 |
import xml.etree.ElementTree as ET |
| 21 |
import xml.dom.minidom as minidom |
| 22 |
import traceback |
| 23 |
import subprocess |
| 24 |
from sys import platform |
| 25 |
import collections |
| 26 |
import urllib.parse |
| 27 |
|
| 28 |
class GbuildLinkTarget: |
| 29 |
includepattern = re.compile(r'-I(\S+)') |
| 30 |
isystempattern = re.compile(r'-isystem\s*(\S+)') |
| 31 |
warningpattern = re.compile(r'-W\S+') |
| 32 |
|
| 33 |
@staticmethod |
| 34 |
def __split_includes(includes): |
| 35 |
foundisystem = GbuildLinkTarget.isystempattern.findall(includes) |
| 36 |
foundincludes = [includeswitch.strip() for includeswitch in GbuildLinkTarget.includepattern.findall(includes) if |
| 37 |
len(includeswitch) > 2] |
| 38 |
return (foundincludes, foundisystem) |
| 39 |
|
| 40 |
@staticmethod |
| 41 |
def __split_objs(objsline): |
| 42 |
return [obj for obj in objsline.strip().split(' ') if obj not in { '', 'CXXOBJECTS', 'COBJECTS', 'OBJCXXOBJECTS', 'CXXCLROBJECTS', '+=' }] |
| 43 |
|
| 44 |
@staticmethod |
| 45 |
def __split_defs(defsline): |
| 46 |
defs = {} |
| 47 |
alldefs = [defswitch.strip() for defswitch in defsline.strip().lstrip('-D').split(' -D') if len(defswitch) > 2] |
| 48 |
for d in alldefs: |
| 49 |
dparts = d.split(' -U') |
| 50 |
"""after dparts.pop(0), dparts will contain only undefs""" |
| 51 |
defparts = dparts.pop(0).strip().split('=') |
| 52 |
if len(defparts) == 1: |
| 53 |
defparts.append(None) |
| 54 |
defs[defparts[0]] = defparts[1] |
| 55 |
"""Drop undefed items (if any) from previous defs""" |
| 56 |
for u in dparts: |
| 57 |
defs.pop(u.strip(), '') |
| 58 |
defs["LIBO_INTERNAL_ONLY"] = None |
| 59 |
return defs |
| 60 |
|
| 61 |
@staticmethod |
| 62 |
def __split_flags(flagsline, flagslineappend): |
| 63 |
return [cxxflag.strip() for cxxflag in GbuildLinkTarget.warningpattern.sub('', '%s %s' % (flagsline, flagslineappend)).split(' ') if len(cxxflag) > 1] |
| 64 |
|
| 65 |
def __init__(self, json): |
| 66 |
(foundincludes, foundisystem) = GbuildLinkTarget.__split_includes(json['INCLUDE']) |
| 67 |
(self.name, self.location, self.include, self.include_sys, self.defs, self.cxxobjects, self.objcxxobjects, self.cxxflags, self.objcxxflags, self.cobjects, self.objcobjects, self.cflags, self.objcflags, self.cxxclrobjects, self.cxxclrflags, self.linked_libs, self.linked_static_libs, self.link_target) = ( |
| 68 |
type(self).targetpattern.match(os.path.basename(json['MAKEFILE'])).group(1), |
| 69 |
os.path.dirname(json['MAKEFILE']), |
| 70 |
foundincludes, |
| 71 |
foundisystem, |
| 72 |
GbuildLinkTarget.__split_defs(json['DEFS']), |
| 73 |
GbuildLinkTarget.__split_objs(json['CXXOBJECTS']), |
| 74 |
GbuildLinkTarget.__split_objs(json['OBJCXXOBJECTS']), |
| 75 |
GbuildLinkTarget.__split_flags(json['CXXFLAGS'], json['CXXFLAGSAPPEND']), |
| 76 |
GbuildLinkTarget.__split_flags(json['OBJCXXFLAGS'], json['OBJCXXFLAGSAPPEND']), |
| 77 |
GbuildLinkTarget.__split_objs(json['COBJECTS']), |
| 78 |
GbuildLinkTarget.__split_objs(json['OBJCOBJECTS']), |
| 79 |
GbuildLinkTarget.__split_flags(json['CFLAGS'], json['CFLAGSAPPEND']), |
| 80 |
GbuildLinkTarget.__split_flags(json['OBJCFLAGS'], json['OBJCFLAGSAPPEND']), |
| 81 |
GbuildLinkTarget.__split_objs(json['CXXCLROBJECTS']), |
| 82 |
GbuildLinkTarget.__split_flags(json['CXXCLRFLAGS'], json['CXXCLRFLAGSAPPEND']), |
| 83 |
json['LINKED_LIBS'].strip().split(' '), |
| 84 |
json['LINKED_STATIC_LIBS'].strip().split(' '), |
| 85 |
json['LINKTARGET'].strip()) |
| 86 |
|
| 87 |
def short_name(self): |
| 88 |
"""Return the short name of target based on the Foo_* makefile name""" |
| 89 |
return '%s %s' % (type(self).targetprefix, self.name) |
| 90 |
|
| 91 |
def target_name(self): |
| 92 |
return '%s_%s' % (type(self).targetprefix, self.name) |
| 93 |
|
| 94 |
def __str__(self): |
| 95 |
return '%s at %s with include path: %s, isystem includes: %s, defines: %s, objects: %s, cxxflags: %s, cobjects: %s, cflags: %s, linked libs: %s and linked static libs: %s' % ( |
| 96 |
self.short_name(), self.location, self.include, self.include_sys, self.defs, self.cxxobjects, |
| 97 |
self.cxxflags, self.cobjects, self.cflags, self.linked_libs, self.linked_static_libs) |
| 98 |
|
| 99 |
|
| 100 |
class GbuildLib(GbuildLinkTarget): |
| 101 |
targetpattern = re.compile(r'Library_(.*)\.mk') |
| 102 |
targetprefix = "Library" |
| 103 |
|
| 104 |
class GbuildStaticLib(GbuildLinkTarget): |
| 105 |
targetpattern = re.compile(r'StaticLibrary_(.*)\.mk') |
| 106 |
targetprefix = "StaticLibrary" |
| 107 |
|
| 108 |
class GbuildTest(GbuildLinkTarget): |
| 109 |
targetpattern = re.compile(r'CppunitTest_(.*)\.mk') |
| 110 |
targetprefix = "CppunitTest" |
| 111 |
|
| 112 |
class GbuildExe(GbuildLinkTarget): |
| 113 |
targetpattern = re.compile(r'Executable_(.*)\.mk') |
| 114 |
targetprefix = "Executable" |
| 115 |
|
| 116 |
|
| 117 |
class GbuildParser: |
| 118 |
"""Main data model object. |
| 119 |
|
| 120 |
Attributes: |
| 121 |
target_by_path : dict[path:string, set(target)] |
| 122 |
where target is one of the GbuildLinkTarget subclasses |
| 123 |
target_by_location : dict[path:string, set(target)] |
| 124 |
where target is one of the GbuildLinkTarget subclasses |
| 125 |
""" |
| 126 |
def __init__(self, makecmd): |
| 127 |
self.makecmd = makecmd |
| 128 |
self.binpath = os.path.dirname(os.environ['GPERF']) # woha, this is quite a hack |
| 129 |
(self.srcdir, self.builddir, self.instdir, self.workdir) = (os.environ['SRCDIR'], os.environ['BUILDDIR'], os.environ['INSTDIR'], os.environ['WORKDIR']) |
| 130 |
(self.libs, self.static_libs, self.exes, self.tests, self.modulenamelist) = (set(), set(), set(), set(), []) |
| 131 |
(self.target_by_path, self.target_by_location) = ({}, {}) |
| 132 |
|
| 133 |
def parse(self): |
| 134 |
for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', 'Library')): |
| 135 |
with open(os.path.join(self.workdir, 'GbuildToJson', 'Library', jsonfilename), 'r') as f: |
| 136 |
lib = GbuildLib(json.load(f)) |
| 137 |
self.libs.add(lib) |
| 138 |
for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', 'StaticLibrary')): |
| 139 |
with open(os.path.join(self.workdir, 'GbuildToJson', 'StaticLibrary', jsonfilename), 'r') as f: |
| 140 |
static_lib = GbuildStaticLib(json.load(f)) |
| 141 |
self.static_libs.add(static_lib) |
| 142 |
for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', 'Executable')): |
| 143 |
with open(os.path.join(self.workdir, 'GbuildToJson', 'Executable', jsonfilename), 'r') as f: |
| 144 |
exe = GbuildExe(json.load(f)) |
| 145 |
self.exes.add(exe) |
| 146 |
for jsonfilename in os.listdir(os.path.join(self.workdir, 'GbuildToJson', 'CppunitTest')): |
| 147 |
with open(os.path.join(self.workdir, 'GbuildToJson', 'CppunitTest', jsonfilename), 'r') as f: |
| 148 |
test = GbuildTest(json.load(f)) |
| 149 |
self.tests.add(test) |
| 150 |
for target in self.libs | self.static_libs | self.exes | self.tests: |
| 151 |
if target.location not in self.target_by_location: |
| 152 |
self.target_by_location[target.location] = set() |
| 153 |
self.target_by_location[target.location] |= set([target]) |
| 154 |
for cxx in target.cxxobjects: |
| 155 |
path = '/'.join(cxx.split('/')[:-1]) |
| 156 |
if path not in self.target_by_path: |
| 157 |
self.target_by_path[path] = set() |
| 158 |
self.target_by_path[path] |= set([target]) |
| 159 |
for c in target.cobjects: |
| 160 |
path = '/'.join(c.split('/')[:-1]) |
| 161 |
if path not in self.target_by_path: |
| 162 |
self.target_by_path[path] = set() |
| 163 |
self.target_by_path[path] |= set([target]) |
| 164 |
for location in self.target_by_location: |
| 165 |
self.modulenamelist.append(os.path.split(location)[1]) |
| 166 |
return self |
| 167 |
|
| 168 |
|
| 169 |
class IdeIntegrationGenerator: |
| 170 |
|
| 171 |
def __init__(self, gbuildparser, ide): |
| 172 |
self.gbuildparser = gbuildparser |
| 173 |
self.ide = ide |
| 174 |
|
| 175 |
def emit(self): |
| 176 |
pass |
| 177 |
|
| 178 |
class EclipseCDTIntegrationGenerator(IdeIntegrationGenerator): |
| 179 |
|
| 180 |
def __init__(self, gbuildparser, ide): |
| 181 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 182 |
|
| 183 |
def create_include_paths(self): |
| 184 |
for module in self.gbuildparser.modulenamelist: |
| 185 |
modulepath = os.path.join(self.gbuildparser.builddir, module) |
| 186 |
includedirfile = open(os.path.join(modulepath, '.eclipsesettingfile'), 'w') |
| 187 |
modulelibs = [] |
| 188 |
for lib in self.gbuildparser.target_by_path.keys(): |
| 189 |
if lib.startswith(module+'/'): |
| 190 |
modulelibs.append(lib) |
| 191 |
include = set() |
| 192 |
for lib in modulelibs: |
| 193 |
for target in self.gbuildparser.target_by_path[lib]: |
| 194 |
include |= set(target.include) |
| 195 |
includedirfile.write('\n'.join(include)) |
| 196 |
includedirfile.close() |
| 197 |
|
| 198 |
|
| 199 |
def create_macros(self): |
| 200 |
for module in self.gbuildparser.modulenamelist: |
| 201 |
modulepath = os.path.join(self.gbuildparser.builddir, module) |
| 202 |
macrofile = open(os.path.join(modulepath, '.macros'), 'w') |
| 203 |
modulelibs = [] |
| 204 |
for lib in self.gbuildparser.target_by_path.keys(): |
| 205 |
if lib.startswith(module+'/'): |
| 206 |
modulelibs.append(lib) |
| 207 |
define = [] |
| 208 |
defineset = set() |
| 209 |
for lib in modulelibs: |
| 210 |
for target in self.gbuildparser.target_by_path[lib]: |
| 211 |
for i in target.defs.keys(): |
| 212 |
tmp = str(i) +','+str(target.defs[i]) |
| 213 |
if tmp not in defineset: |
| 214 |
defineset.add(tmp) |
| 215 |
macrofile.write('\n'.join(defineset)) |
| 216 |
macrofile.close() |
| 217 |
|
| 218 |
|
| 219 |
def create_settings_file(self): |
| 220 |
|
| 221 |
settingsfiletemplate = """\ |
| 222 |
<?xml version="1.0" encoding="UTF-8"?> |
| 223 |
<cdtprojectproperties> |
| 224 |
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePaths"> |
| 225 |
<language name="C++ Source File"> |
| 226 |
|
| 227 |
|
| 228 |
</language> |
| 229 |
<language name="C Source File"> |
| 230 |
|
| 231 |
</language> |
| 232 |
<language name="Object File"> |
| 233 |
|
| 234 |
</language> |
| 235 |
<language name="Assembly Source File"> |
| 236 |
|
| 237 |
</language> |
| 238 |
</section> |
| 239 |
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros"> |
| 240 |
<language name="C++ Source File"> |
| 241 |
|
| 242 |
</language> |
| 243 |
<language name="C Source File"> |
| 244 |
|
| 245 |
</language> |
| 246 |
<language name="Object File"> |
| 247 |
|
| 248 |
</language> |
| 249 |
<language name="Assembly Source File"> |
| 250 |
|
| 251 |
</language> |
| 252 |
</section> |
| 253 |
</cdtprojectproperties> |
| 254 |
""" |
| 255 |
|
| 256 |
for module in self.gbuildparser.modulenamelist: |
| 257 |
tempxml = [] |
| 258 |
modulepath = os.path.join(self.gbuildparser.builddir, module) |
| 259 |
|
| 260 |
settingsfile = open(os.path.join(modulepath, 'eclipsesettingfile.xml'), 'w') |
| 261 |
settingsfile.write(settingsfiletemplate) |
| 262 |
settingsfile.close() |
| 263 |
|
| 264 |
settingsfile = open(os.path.join(modulepath, 'eclipsesettingfile.xml'), 'r') |
| 265 |
tempxml = settingsfile.readlines() |
| 266 |
tempinclude = open(os.path.join(modulepath, '.eclipsesettingfile'), 'r') |
| 267 |
tempmacro = open(os.path.join(modulepath, '.macros'), 'r') |
| 268 |
for includepath in tempinclude: |
| 269 |
if includepath[-1:] == "\n": |
| 270 |
includepath = includepath[:-1] |
| 271 |
templine = "<includepath>%s</includepath>\n" % includepath |
| 272 |
tempxml.insert(5, templine) |
| 273 |
|
| 274 |
for line in tempmacro: |
| 275 |
macroskeyvalue = line.split(',') |
| 276 |
macrokey = macroskeyvalue[0] |
| 277 |
macrovalue = macroskeyvalue[1] |
| 278 |
if macrovalue[-1:] == "\n": |
| 279 |
macrovalue = macrovalue[:-1] |
| 280 |
templine = "<macro><name>%s</name><value>%s</value></macro>\n" %(macrokey, macrovalue) |
| 281 |
tempxml.insert(-13, templine) |
| 282 |
tempxml="".join(tempxml) |
| 283 |
settingsfile.close |
| 284 |
|
| 285 |
settingsfile = open(os.path.join(modulepath, 'eclipsesettingfile.xml'), 'w') |
| 286 |
settingsfile.write(tempxml) |
| 287 |
settingsfile.close() |
| 288 |
os.remove(os.path.join(modulepath, '.eclipsesettingfile')) |
| 289 |
os.remove(os.path.join(modulepath, '.macros')) |
| 290 |
|
| 291 |
def emit(self): |
| 292 |
self.create_include_paths() |
| 293 |
self.create_macros() |
| 294 |
self.create_settings_file() |
| 295 |
|
| 296 |
class CodeliteIntegrationGenerator(IdeIntegrationGenerator): |
| 297 |
|
| 298 |
def __init__(self, gbuildparser, ide): |
| 299 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 300 |
|
| 301 |
def emit(self): |
| 302 |
self.create_workspace_file() |
| 303 |
for module in self.gbuildparser.modulenamelist: |
| 304 |
if os.path.exists(module): # ignore external modules |
| 305 |
self.create_project_file(module) |
| 306 |
#self.create_project_file('vcl') |
| 307 |
|
| 308 |
def create_workspace_file(self): |
| 309 |
root_node = ET.Element('CodeLite_Workspace', Name='libo2', Database='./libo2.tags', Version='10.0.0') |
| 310 |
for module in self.gbuildparser.modulenamelist: |
| 311 |
if os.path.exists(module): # ignore external modules |
| 312 |
ET.SubElement(root_node, 'Project', Name=module, Path='%s/%s.project' % (module, module), Active='No') |
| 313 |
build_matrix_node = ET.SubElement(root_node, 'BuildMatrix') |
| 314 |
workspace_config_node = ET.SubElement(build_matrix_node, 'WorkspaceConfiguration', Name='Debug', Selected='yes') |
| 315 |
ET.SubElement(workspace_config_node, 'Environment') |
| 316 |
for module in self.gbuildparser.modulenamelist: |
| 317 |
if os.path.exists(module): # ignore external modules |
| 318 |
ET.SubElement(workspace_config_node, 'Project', Name=module, ConfigName='Debug') |
| 319 |
workspace_config_node = ET.SubElement(build_matrix_node, 'WorkspaceConfiguration', Name='Release', Selected='yes') |
| 320 |
ET.SubElement(workspace_config_node, 'Environment') |
| 321 |
for module in self.gbuildparser.modulenamelist: |
| 322 |
if os.path.exists(module): # ignore external modules |
| 323 |
ET.SubElement(workspace_config_node, 'Project', Name=module, ConfigName='Release') |
| 324 |
|
| 325 |
self.write_pretty_xml(root_node, os.path.join(self.gbuildparser.builddir, 'libo2.workspace')) |
| 326 |
|
| 327 |
def create_project_file(self, module_name): |
| 328 |
root_node = ET.Element('CodeLite_Project', Name=module_name, InternalType='') |
| 329 |
ET.SubElement(root_node, 'Plugins') |
| 330 |
|
| 331 |
# add CXX files |
| 332 |
virtual_dirs = collections.defaultdict(set) |
| 333 |
for target_path in self.gbuildparser.target_by_path.keys(): |
| 334 |
if target_path.startswith(module_name+'/'): |
| 335 |
for target in self.gbuildparser.target_by_path[target_path]: |
| 336 |
for file in target.cxxobjects: |
| 337 |
relative_file = '/'.join(file.split('/')[1:]) |
| 338 |
path = '/'.join(file.split('/')[1:-1]) |
| 339 |
virtual_dirs[path].add(relative_file + '.cxx') |
| 340 |
# add HXX files |
| 341 |
all_libs = self.gbuildparser.libs | self.gbuildparser.exes |
| 342 |
for lib in all_libs: |
| 343 |
if lib.name == module_name: |
| 344 |
for hdir in lib.include: |
| 345 |
# only want the module-internal ones |
| 346 |
if hdir.startswith(module_name+'/'): |
| 347 |
for hf in os.listdir(hdir): |
| 348 |
if hf.endswith(('.h', '.hxx', '.hpp', '.hrc')): |
| 349 |
path = '/'.join(hf.split('/')[1:-1]) |
| 350 |
virtual_dirs[path].add(hf) |
| 351 |
# add HXX files from the root/include/** folders |
| 352 |
module_include = os.path.join(self.gbuildparser.builddir, 'include', module_name) |
| 353 |
if os.path.exists(module_include): |
| 354 |
for hf in os.listdir(module_include): |
| 355 |
if hf.endswith(('.h', '.hxx', '.hpp', '.hrc')): |
| 356 |
path = '../include/' + ('/'.join(hf.split('/')[1:-1])) |
| 357 |
virtual_dirs['include/' + module_name].add('../include/' + module_name + '/' + hf) |
| 358 |
|
| 359 |
for vd_name in sorted(virtual_dirs.keys()): |
| 360 |
vd_files = sorted(virtual_dirs[vd_name]) |
| 361 |
parent_node = root_node |
| 362 |
for subname in vd_name.split('/'): |
| 363 |
parent_node = ET.SubElement(parent_node, 'VirtualDirectory', Name=subname) |
| 364 |
for file in vd_files: |
| 365 |
ET.SubElement(parent_node, 'File', Name=file) |
| 366 |
|
| 367 |
ET.SubElement(root_node, 'Description') |
| 368 |
ET.SubElement(root_node, 'Dependencies') |
| 369 |
ET.SubElement(root_node, 'Dependencies', Name='Debug') |
| 370 |
ET.SubElement(root_node, 'Dependencies', Name='Release') |
| 371 |
|
| 372 |
settingstemplate = """\ |
| 373 |
<Settings Type="Dynamic Library"> |
| 374 |
<GlobalSettings> |
| 375 |
<Compiler Options="" C_Options="" Assembler=""> |
| 376 |
<IncludePath Value="."/> |
| 377 |
</Compiler> |
| 378 |
<Linker Options=""> |
| 379 |
<LibraryPath Value="."/> |
| 380 |
</Linker> |
| 381 |
<ResourceCompiler Options=""/> |
| 382 |
</GlobalSettings> |
| 383 |
<Configuration Name="Debug" CompilerType="clang( based on LLVM 3.5.0 )" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> |
| 384 |
<Compiler Options="-g" C_Options="-g" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0"> |
| 385 |
<IncludePath Value="."/> |
| 386 |
</Compiler> |
| 387 |
<Linker Options="" Required="yes"/> |
| 388 |
<ResourceCompiler Options="" Required="no"/> |
| 389 |
<General OutputFile="" IntermediateDirectory="./Debug" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> |
| 390 |
<BuildSystem Name="Default"/> |
| 391 |
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> |
| 392 |
<![CDATA[]]> |
| 393 |
</Environment> |
| 394 |
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no"> |
| 395 |
<DebuggerSearchPaths/> |
| 396 |
<PostConnectCommands/> |
| 397 |
<StartupCommands/> |
| 398 |
</Debugger> |
| 399 |
<PreBuild/> |
| 400 |
<PostBuild/> |
| 401 |
<CustomBuild Enabled="yes"> |
| 402 |
<RebuildCommand/> |
| 403 |
<CleanCommand>make %s.clean</CleanCommand> |
| 404 |
<BuildCommand>make %s.build</BuildCommand> |
| 405 |
<PreprocessFileCommand/> |
| 406 |
<SingleFileCommand/> |
| 407 |
<MakefileGenerationCommand/> |
| 408 |
<ThirdPartyToolName>None</ThirdPartyToolName> |
| 409 |
<WorkingDirectory>$(WorkspacePath)</WorkingDirectory> |
| 410 |
</CustomBuild> |
| 411 |
<AdditionalRules> |
| 412 |
<CustomPostBuild/> |
| 413 |
<CustomPreBuild/> |
| 414 |
</AdditionalRules> |
| 415 |
<Completion EnableCpp11="no" EnableCpp14="no"> |
| 416 |
<ClangCmpFlagsC/> |
| 417 |
<ClangCmpFlags/> |
| 418 |
<ClangPP/> |
| 419 |
<SearchPaths/> |
| 420 |
</Completion> |
| 421 |
</Configuration> |
| 422 |
<Configuration Name="Release" CompilerType="clang( based on LLVM 3.5.0 )" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> |
| 423 |
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0"> |
| 424 |
<IncludePath Value="."/> |
| 425 |
</Compiler> |
| 426 |
<Linker Options="-O2" Required="yes"/> |
| 427 |
<ResourceCompiler Options="" Required="no"/> |
| 428 |
<General OutputFile="" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> |
| 429 |
<BuildSystem Name="Default"/> |
| 430 |
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> |
| 431 |
<![CDATA[]]> |
| 432 |
</Environment> |
| 433 |
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no"> |
| 434 |
<DebuggerSearchPaths/> |
| 435 |
<PostConnectCommands/> |
| 436 |
<StartupCommands/> |
| 437 |
</Debugger> |
| 438 |
<PreBuild/> |
| 439 |
<PostBuild/> |
| 440 |
<CustomBuild Enabled="yes"> |
| 441 |
<RebuildCommand/> |
| 442 |
<CleanCommand>make %s.clean</CleanCommand> |
| 443 |
<BuildCommand>make %s.build</BuildCommand> |
| 444 |
<PreprocessFileCommand/> |
| 445 |
<SingleFileCommand/> |
| 446 |
<MakefileGenerationCommand/> |
| 447 |
<ThirdPartyToolName>None</ThirdPartyToolName> |
| 448 |
<WorkingDirectory>$(WorkspacePath)</WorkingDirectory> |
| 449 |
</CustomBuild> |
| 450 |
<AdditionalRules> |
| 451 |
<CustomPostBuild/> |
| 452 |
<CustomPreBuild/> |
| 453 |
</AdditionalRules> |
| 454 |
<Completion EnableCpp11="no" EnableCpp14="no"> |
| 455 |
<ClangCmpFlagsC/> |
| 456 |
<ClangCmpFlags/> |
| 457 |
<ClangPP/> |
| 458 |
<SearchPaths/> |
| 459 |
</Completion> |
| 460 |
</Configuration> |
| 461 |
</Settings> |
| 462 |
""" |
| 463 |
root_node.append(ET.fromstring(settingstemplate % (module_name, module_name, module_name, module_name))) |
| 464 |
|
| 465 |
self.write_pretty_xml(root_node, os.path.join(self.gbuildparser.builddir, module_name, '%s.project' % module_name)) |
| 466 |
|
| 467 |
def write_pretty_xml(self, node, file_path): |
| 468 |
xml_str = ET.tostring(node, encoding='unicode') |
| 469 |
pretty_str = minidom.parseString(xml_str).toprettyxml(encoding='utf-8') |
| 470 |
with open(file_path, 'w') as f: |
| 471 |
f.write(pretty_str.decode()) |
| 472 |
|
| 473 |
class DebugIntegrationGenerator(IdeIntegrationGenerator): |
| 474 |
|
| 475 |
def __init__(self, gbuildparser, ide): |
| 476 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 477 |
|
| 478 |
def emit(self): |
| 479 |
print(self.gbuildparser.srcdir) |
| 480 |
print(self.gbuildparser.builddir) |
| 481 |
for lib in self.gbuildparser.libs: |
| 482 |
print(lib) |
| 483 |
for exe in self.gbuildparser.exes: |
| 484 |
print(exe) |
| 485 |
for test in self.gbuildparser.tests: |
| 486 |
print(test) |
| 487 |
|
| 488 |
|
| 489 |
class VimIntegrationGenerator(IdeIntegrationGenerator): |
| 490 |
|
| 491 |
def __init__(self, gbuildparser, ide): |
| 492 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 493 |
|
| 494 |
def emit(self): |
| 495 |
global_list = [] |
| 496 |
for lib in self.gbuildparser.libs | self.gbuildparser.tests | self.gbuildparser.exes: |
| 497 |
entries = [] |
| 498 |
for file in lib.cxxobjects: |
| 499 |
filePath = os.path.join(self.gbuildparser.srcdir, file) + ".cxx" |
| 500 |
entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)} |
| 501 |
entries.append(entry) |
| 502 |
global_list.extend(entries) |
| 503 |
entries = [] |
| 504 |
for file in lib.objcxxobjects: |
| 505 |
filePath = os.path.join(self.gbuildparser.srcdir, file) + ".mm" |
| 506 |
entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)} |
| 507 |
entries.append(entry) |
| 508 |
global_list.extend(entries) |
| 509 |
entries = [] |
| 510 |
for file in lib.cobjects: |
| 511 |
filePath = os.path.join(self.gbuildparser.srcdir, file) + ".c" |
| 512 |
entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)} |
| 513 |
entries.append(entry) |
| 514 |
global_list.extend(entries) |
| 515 |
entries = [] |
| 516 |
for file in lib.objcobjects: |
| 517 |
filePath = os.path.join(self.gbuildparser.srcdir, file) + ".m" |
| 518 |
entry = {'directory': lib.location, 'file': filePath, 'command': self.generateCommand(lib, filePath)} |
| 519 |
entries.append(entry) |
| 520 |
global_list.extend(entries) |
| 521 |
with open(os.path.join(self.gbuildparser.builddir, 'compile_commands.json'), 'w') as export_file: |
| 522 |
json.dump(global_list, export_file) |
| 523 |
|
| 524 |
def generateCommand(self, lib, file): |
| 525 |
command = os.environ.get('CXX') |
| 526 |
if file.endswith('.c') or file.endswith('.m'): |
| 527 |
command = os.environ.get('CC') |
| 528 |
command += ' -Wall' |
| 529 |
for key, value in lib.defs.items(): |
| 530 |
command += ' -D' |
| 531 |
command += key |
| 532 |
if value is not None: |
| 533 |
command += '=' |
| 534 |
command += value |
| 535 |
|
| 536 |
for include in lib.include: |
| 537 |
command += ' -I' |
| 538 |
command += include |
| 539 |
for isystem in lib.include_sys: |
| 540 |
command += ' -isystem ' |
| 541 |
command += isystem |
| 542 |
flags = lib.cxxflags |
| 543 |
if file.endswith('.mm'): |
| 544 |
flags = lib.objcxxflags |
| 545 |
elif file.endswith('.c'): |
| 546 |
flags = lib.cflags |
| 547 |
elif file.endswith('.m'): |
| 548 |
flags = lib.objcflags |
| 549 |
for cxxflag in flags: |
| 550 |
command += ' ' |
| 551 |
command += cxxflag |
| 552 |
command += ' -c ' |
| 553 |
command += file |
| 554 |
return command |
| 555 |
|
| 556 |
|
| 557 |
class KdevelopIntegrationGenerator(IdeIntegrationGenerator): |
| 558 |
|
| 559 |
def encode_int(self, i): |
| 560 |
temp = '%08x' % i |
| 561 |
return '\\x%s\\x%s\\x%s\\x%s' % (temp[0:2], temp[2:4], temp[4:6], temp[6:8]) |
| 562 |
|
| 563 |
def encode_string(self, string): |
| 564 |
result = self.encode_int(len(string) * 2) |
| 565 |
for c in string.encode('utf-16-be'): |
| 566 |
if c in range(32, 126): |
| 567 |
result += chr(c) |
| 568 |
else: |
| 569 |
result += '\\x%02x' % c |
| 570 |
return result |
| 571 |
|
| 572 |
def generate_buildsystemconfigtool(self, configid, tool, args, exe, typenr): |
| 573 |
return KdevelopIntegrationGenerator.buildsystemconfigtooltemplate % {'configid': configid, 'tool': tool, |
| 574 |
'args': args, 'exe': exe, 'typenr': typenr} |
| 575 |
|
| 576 |
buildsystemconfigtooltemplate = """ |
| 577 |
[CustomBuildSystem][BuildConfig%(configid)d][Tool%(tool)s] |
| 578 |
Arguments=%(args)s |
| 579 |
Enabled=true |
| 580 |
Environment= |
| 581 |
Executable=%(exe)s |
| 582 |
Type=%(typenr)d |
| 583 |
|
| 584 |
""" |
| 585 |
|
| 586 |
def generate_buildsystemconfig(self, configid, moduledir, builddir, title, buildparms=''): |
| 587 |
result = KdevelopIntegrationGenerator.buildsystemconfigtemplate % {'configid': configid, 'builddir': builddir, |
| 588 |
'title': title} |
| 589 |
result += self.generate_buildsystemconfigtool(configid, 'Clean', 'clean %s' % buildparms, |
| 590 |
self.gbuildparser.makecmd, 3) |
| 591 |
result += self.generate_buildsystemconfigtool(configid, 'Build', 'all %s' % buildparms, |
| 592 |
self.gbuildparser.makecmd, 0) |
| 593 |
return result |
| 594 |
|
| 595 |
buildsystemconfigtemplate = """ |
| 596 |
[CustomBuildSystem][BuildConfig%(configid)d] |
| 597 |
BuildDir=file://%(builddir)s |
| 598 |
Title=%(title)s |
| 599 |
|
| 600 |
""" |
| 601 |
|
| 602 |
def generate_buildsystem(self, moduledir): |
| 603 |
result = KdevelopIntegrationGenerator.buildsystemtemplate % {'defaultconfigid': 0} |
| 604 |
result += self.generate_buildsystemconfig(0, moduledir, moduledir, 'Module Build -- Release') |
| 605 |
result += self.generate_buildsystemconfig(1, moduledir, self.gbuildparser.builddir, 'Full Build -- Release') |
| 606 |
result += self.generate_buildsystemconfig(2, moduledir, moduledir, 'Module Build -- Debug', 'debug=T') |
| 607 |
result += self.generate_buildsystemconfig(3, moduledir, self.gbuildparser.builddir, 'Full Build -- Debug', |
| 608 |
'debug=T') |
| 609 |
return result |
| 610 |
|
| 611 |
buildsystemtemplate = """ |
| 612 |
[CustomBuildSystem] |
| 613 |
CurrentConfiguration=BuildConfig%(defaultconfigid)d |
| 614 |
|
| 615 |
""" |
| 616 |
|
| 617 |
def generate_launch(self, launchid, launchname, executablepath, args, workdir): |
| 618 |
return KdevelopIntegrationGenerator.launchtemplate % {'launchid': launchid, 'launchname': launchname, |
| 619 |
'executablepath': executablepath, 'args': args, |
| 620 |
'workdir': workdir} |
| 621 |
|
| 622 |
launchtemplate = """ |
| 623 |
[Launch][Launch Configuration %(launchid)d] |
| 624 |
Configured Launch Modes=execute |
| 625 |
Configured Launchers=nativeAppLauncher |
| 626 |
Name=%(launchname)s |
| 627 |
Type=Native Application |
| 628 |
|
| 629 |
[Launch][Launch Configuration %(launchid)d][Data] |
| 630 |
Arguments=%(args)s |
| 631 |
Dependencies=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x00) |
| 632 |
Dependency Action=Nothing |
| 633 |
EnvironmentGroup=default |
| 634 |
Executable=file://%(executablepath)s |
| 635 |
External Terminal=konsole --noclose --workdir %%workdir -e %%exe |
| 636 |
Project Target= |
| 637 |
Use External Terminal=false |
| 638 |
Working Directory=file://%(workdir)s |
| 639 |
isExecutable=true |
| 640 |
|
| 641 |
""" |
| 642 |
|
| 643 |
def generate_launches(self, moduledir): |
| 644 |
launches = ','.join(['Launch Configuration %d' % i for i in range(7)]) |
| 645 |
result = KdevelopIntegrationGenerator.launchestemplate % {'launches': launches} |
| 646 |
result += self.generate_launch(0, 'Local tests -- quick tests (unitcheck)', self.gbuildparser.makecmd, |
| 647 |
'unitcheck', moduledir) |
| 648 |
result += self.generate_launch(1, 'Local tests -- slow tests (unitcheck, slowcheck, screenshot)', self.gbuildparser.makecmd, |
| 649 |
'unitcheck slowcheck screenshot', moduledir) |
| 650 |
result += self.generate_launch(2, 'Local tests -- integration tests (unitcheck, slowcheck, screenshot, subsequentcheck)', |
| 651 |
self.gbuildparser.makecmd, 'unitcheck slowcheck screenshot subsequentcheck', moduledir) |
| 652 |
result += self.generate_launch(3, 'Global tests -- quick tests (unitcheck)', self.gbuildparser.makecmd, |
| 653 |
'unitcheck', self.gbuildparser.builddir) |
| 654 |
result += self.generate_launch(4, 'Global tests -- slow tests (unitcheck, slowcheck, screenshot)', |
| 655 |
self.gbuildparser.makecmd, 'unitcheck slowcheck screenshot', self.gbuildparser.builddir) |
| 656 |
result += self.generate_launch(5, 'Global tests -- integration tests (unitcheck, slowcheck, screenshot, subsequentcheck)', |
| 657 |
self.gbuildparser.makecmd, 'unitcheck slowcheck screenshot subsequentcheck', |
| 658 |
self.gbuildparser.builddir) |
| 659 |
result += self.generate_launch(6, 'Run LibreOffice', |
| 660 |
os.path.join(self.gbuildparser.instdir, 'program/soffice.bin'), '', |
| 661 |
self.gbuildparser.instdir) |
| 662 |
return result |
| 663 |
|
| 664 |
launchestemplate = """ |
| 665 |
[Launch] |
| 666 |
Launch Configurations=%(launches)s |
| 667 |
|
| 668 |
""" |
| 669 |
|
| 670 |
def write_modulebeef(self, moduledir, modulename): |
| 671 |
beefdir = os.path.join(moduledir, '.kdev4') |
| 672 |
os.mkdir(beefdir) |
| 673 |
beeffile = open(os.path.join(beefdir, 'Module_%s.kdev4' % modulename), 'w') |
| 674 |
beeffile.write(self.generate_buildsystem(moduledir)) |
| 675 |
beeffile.write(self.generate_launches(moduledir)) |
| 676 |
beeffile.close() |
| 677 |
|
| 678 |
def write_modulestub(self, moduledir, modulename): |
| 679 |
stubfile = open(os.path.join(moduledir, 'Module_%s.kdev4' % modulename), 'w') |
| 680 |
stubfile.write(KdevelopIntegrationGenerator.modulestubtemplate % {'modulename': modulename, |
| 681 |
'builditem': self.encode_string( |
| 682 |
'Module_%s' % modulename)}) |
| 683 |
stubfile.close() |
| 684 |
|
| 685 |
modulestubtemplate = """ |
| 686 |
[Buildset] |
| 687 |
BuildItems=@Variant(\\x00\\x00\\x00\\t\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x0b\\x00\\x00\\x00\\x00\\x01%(builditem)s) |
| 688 |
|
| 689 |
[Project] |
| 690 |
Name=Module_%(modulename)s |
| 691 |
Manager=KDevCustomBuildSystem |
| 692 |
VersionControl=kdevgit |
| 693 |
""" |
| 694 |
|
| 695 |
def write_includepaths(self, path): |
| 696 |
includedirfile = open(os.path.join(path, '.kdev_include_paths'), 'w') |
| 697 |
include = set() |
| 698 |
for target in self.gbuildparser.target_by_path[path]: |
| 699 |
include |= set(target.include) |
| 700 |
includedirfile.write('\n'.join(include)) |
| 701 |
includedirfile.close() |
| 702 |
|
| 703 |
def __init__(self, gbuildparser, ide): |
| 704 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 705 |
|
| 706 |
def emit(self): |
| 707 |
for path in self.gbuildparser.target_by_path: |
| 708 |
self.write_includepaths(path) |
| 709 |
for location in self.gbuildparser.target_by_location: |
| 710 |
for f in os.listdir(location): |
| 711 |
if f.endswith('.kdev4'): |
| 712 |
try: |
| 713 |
os.remove(os.path.join(location, f)) |
| 714 |
except OSError: |
| 715 |
shutil.rmtree(os.path.join(location, f)) |
| 716 |
for location in self.gbuildparser.target_by_location: |
| 717 |
modulename = os.path.split(location)[1] |
| 718 |
self.write_modulestub(location, modulename) |
| 719 |
self.write_modulebeef(location, modulename) |
| 720 |
|
| 721 |
|
| 722 |
class XcodeIntegrationGenerator(IdeIntegrationGenerator): |
| 723 |
|
| 724 |
def indent(self, file, level): |
| 725 |
if level == 0: |
| 726 |
return |
| 727 |
for i in range(0, level): |
| 728 |
file.write(' ') |
| 729 |
|
| 730 |
def write_object(self, object, file, indent): |
| 731 |
if isinstance(object, int): |
| 732 |
file.write('%d' % object) |
| 733 |
elif isinstance(object, str) and not re.search('[^A-Za-z0-9_]', object): |
| 734 |
file.write('%s' % object) |
| 735 |
elif isinstance(object, str): |
| 736 |
file.write('"%s"' % object) |
| 737 |
elif isinstance(object, dict): |
| 738 |
self.write_dict(object, file, indent) |
| 739 |
|
| 740 |
# Write a dictionary out as an "old-style (NeXT) ASCII plist" |
| 741 |
def write_dict(self, dict, file, indent): |
| 742 |
file.write('{') |
| 743 |
file.write('\n') |
| 744 |
for key in sorted(dict.keys()): |
| 745 |
self.indent(file, indent + 1) |
| 746 |
file.write('%s = ' % key) |
| 747 |
self.write_object(dict[key], file, indent + 1) |
| 748 |
file.write(';\n') |
| 749 |
self.indent(file, indent) |
| 750 |
file.write('}') |
| 751 |
|
| 752 |
def write_dict_to_plist(self, dict, file): |
| 753 |
file.write('// !$*UTF8*$!\n') |
| 754 |
self.write_dict(dict, file, 0) |
| 755 |
|
| 756 |
def get_product_type(self, modulename): |
| 757 |
if modulename in self.gbuildparser.libs: |
| 758 |
return 'com.apple.product-type.library.dynamic' |
| 759 |
elif modulename in self.gbuildparser.exes: |
| 760 |
return 'com.apple.product-type.something' |
| 761 |
|
| 762 |
counter = 0 |
| 763 |
|
| 764 |
def generate_id(self): |
| 765 |
XcodeIntegrationGenerator.counter = XcodeIntegrationGenerator.counter + 1 |
| 766 |
return str('X%07x' % XcodeIntegrationGenerator.counter) |
| 767 |
|
| 768 |
def generate_build_phases(self, modulename): |
| 769 |
result = [self.sourcesBuildPhaseId] |
| 770 |
return result |
| 771 |
|
| 772 |
def generate_root_object(self, modulename): |
| 773 |
result = {'isa': 'PBXProject', |
| 774 |
'attributes': {'LastUpgradeCheck': '0500', |
| 775 |
'ORGANIZATIONNAME': 'LibreOffice'}, |
| 776 |
'buildConfigurationList': self.generate_id(), |
| 777 |
'compatibilityVersion': 'Xcode 3.2', |
| 778 |
'hasScannedForEncodings': 0, |
| 779 |
'knownRegions': ['en'], |
| 780 |
'mainGroup': self.mainGroupId, |
| 781 |
'productRefGroup': self.productRefGroupId, |
| 782 |
'projectDirPath': '', |
| 783 |
'projectRoot': '', |
| 784 |
'targets': self.targetId} |
| 785 |
return result |
| 786 |
|
| 787 |
def generate_target(self, modulename): |
| 788 |
result = {'isa': 'PBXNativeTarget', |
| 789 |
'buildConfigurationList': self.generate_id(), |
| 790 |
'buildPhases': self.generate_build_phases(modulename), |
| 791 |
'buildRules': [], |
| 792 |
'dependencies': [], |
| 793 |
'name': modulename, |
| 794 |
'productName': modulename, |
| 795 |
'productReference': self.productReferenceId, |
| 796 |
'productType': self.get_product_type(modulename)} |
| 797 |
return result |
| 798 |
|
| 799 |
def generate_main_group(self, modulename): |
| 800 |
result = {'isa': 'PBXGroup', |
| 801 |
'children': [self.subMainGroupId, self.productGroupId], |
| 802 |
'sourceTree': '<group>'} |
| 803 |
return result |
| 804 |
|
| 805 |
def generate_sub_main_children(self, modulename): |
| 806 |
return {} |
| 807 |
|
| 808 |
def generate_sub_main_group(self, modulename): |
| 809 |
result = {'isa': 'PBXGroup', |
| 810 |
'children': self.generate_sub_main_children(modulename), |
| 811 |
'path': modulename, |
| 812 |
'sourceTree': '<group>'} |
| 813 |
return result |
| 814 |
|
| 815 |
def generate_product_group(self, modulename): |
| 816 |
result = {'isa': 'PBXGroup', |
| 817 |
'children': [self.productReferenceId], |
| 818 |
'name': 'Products', |
| 819 |
'sourceTree': '<group>'} |
| 820 |
return result |
| 821 |
|
| 822 |
def build_source_list(self, module): |
| 823 |
self.sourceRefList = {} |
| 824 |
self.sourceList = {} |
| 825 |
|
| 826 |
for i in module.cxxobjects: |
| 827 |
ref = self.generate_id() |
| 828 |
self.sourceList[self.generate_id()] = ref |
| 829 |
self.sourceRefList[ref] = {'lastKnownFileType': 'sourcecode.cpp.cpp', |
| 830 |
'path': i + '.cxx', |
| 831 |
'sourceTree': '<group>'} |
| 832 |
|
| 833 |
def generate_sources_build_phase(self, modulename): |
| 834 |
result = {'isa': 'PBXSourcesBuildPhase', |
| 835 |
'buildActionMask': 2147483647, |
| 836 |
'files': self.sourceList.keys(), |
| 837 |
'runOnlyForDeploymentPostprocessing': 0} |
| 838 |
return result |
| 839 |
|
| 840 |
def generate_project(self, target): |
| 841 |
self.rootObjectId = self.generate_id() |
| 842 |
self.mainGroupId = self.generate_id() |
| 843 |
self.subMainGroupId = self.generate_id() |
| 844 |
self.productReferenceId = self.generate_id() |
| 845 |
self.productRefGroupId = self.generate_id() |
| 846 |
self.productGroupId = self.generate_id() |
| 847 |
self.targetId = self.generate_id() |
| 848 |
self.build_source_list(target) |
| 849 |
self.sourcesBuildPhaseId = self.generate_id() |
| 850 |
objects = {self.rootObjectId: self.generate_root_object(target), |
| 851 |
self.targetId: self.generate_target(target), |
| 852 |
self.mainGroupId: self.generate_main_group(target), |
| 853 |
self.subMainGroupId: self.generate_sub_main_group(target), |
| 854 |
self.productGroupId: self.generate_product_group(target), |
| 855 |
self.sourcesBuildPhaseId: self.generate_sources_build_phase(target) |
| 856 |
} |
| 857 |
for i in self.sourceList.keys(): |
| 858 |
ref = self.sourceList[i] |
| 859 |
objects[i] = {'isa': 'PBXBuildFile', |
| 860 |
'fileRef': ref} |
| 861 |
objects[ref] = {'isa': 'PBXFileReference', |
| 862 |
'lastKnownFileType': self.sourceRefList[ref]['lastKnownFileType'], |
| 863 |
'path': self.sourceRefList[ref]['path']} |
| 864 |
project = {'archiveVersion': 1, |
| 865 |
'classes': {}, |
| 866 |
'objectVersion': 46, |
| 867 |
'objects': objects, |
| 868 |
'rootObject': self.rootObjectId} |
| 869 |
return project |
| 870 |
|
| 871 |
# For some reverse-engineered documentation on the project.pbxproj format, |
| 872 |
# see http://www.monobjc.net/xcode-project-file-format.html . |
| 873 |
def write_xcodeproj(self, moduledir, target): |
| 874 |
xcodeprojdir = os.path.join(moduledir, '%s.xcodeproj' % target.target_name()) |
| 875 |
try: |
| 876 |
os.mkdir(xcodeprojdir) |
| 877 |
except: |
| 878 |
pass |
| 879 |
self.write_dict_to_plist(self.generate_project(target), |
| 880 |
open(os.path.join(xcodeprojdir, 'project.pbxproj'), 'w')) |
| 881 |
|
| 882 |
def __init__(self, gbuildparser, ide): |
| 883 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 884 |
|
| 885 |
def emit(self): |
| 886 |
self.rootlocation = './' |
| 887 |
for location in self.gbuildparser.target_by_location: |
| 888 |
# module = location.split('/')[-1] |
| 889 |
# module_directory = os.path.join(self.rootlocation, module) |
| 890 |
for target in self.gbuildparser.target_by_location[location]: |
| 891 |
# project_path = os.path.join(module_directory, '%s.pbxroj' % target.target_name()) |
| 892 |
self.write_xcodeproj(location, target) |
| 893 |
|
| 894 |
|
| 895 |
class VisualStudioIntegrationGenerator(IdeIntegrationGenerator): |
| 896 |
|
| 897 |
def __init__(self, gbuildparser, ide): |
| 898 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 899 |
self.toolset = os.environ['VCTOOLSET'] |
| 900 |
if os.environ['CPUNAME'] == 'X86_64': |
| 901 |
self.platform = 'x64' |
| 902 |
elif os.environ['CPUNAME'] == 'AARCH64': |
| 903 |
self.platform = 'ARM' |
| 904 |
else: # 'INTEL' |
| 905 |
self.platform = 'Win32' |
| 906 |
self.solution_directory = self.gbuildparser.builddir |
| 907 |
self.configurations = { |
| 908 |
'Build': { |
| 909 |
'build': self.module_make_command('%(target)s'), |
| 910 |
'clean': self.module_make_command('%(target)s.clean'), |
| 911 |
'rebuild': self.module_make_command('%(target)s.clean %(target)s') |
| 912 |
}, |
| 913 |
'Unit Tests': { |
| 914 |
'build': self.module_make_command('unitcheck'), |
| 915 |
'clean': self.module_make_command('clean'), |
| 916 |
'rebuild': self.module_make_command('clean unitcheck'), |
| 917 |
}, |
| 918 |
'Integration tests': { |
| 919 |
'build': self.module_make_command('unitcheck slowcheck screenshot subsequentcheck'), |
| 920 |
'clean': self.module_make_command('clean'), |
| 921 |
'rebuild': self.module_make_command('clean unitcheck slowcheck screenshot subsequentcheck') |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
def module_make_command(self, targets): |
| 926 |
return '%(sh)s -c "PATH=\\"/bin:$PATH\\";BUILDDIR=\\"%(builddir)s\\" %(makecmd)s -rsC %(location)s ' + targets + '"' |
| 927 |
|
| 928 |
class Project: |
| 929 |
|
| 930 |
def __init__(self, guid, target, project_path): |
| 931 |
self.guid = guid |
| 932 |
self.target = target |
| 933 |
self.path = project_path |
| 934 |
|
| 935 |
# Check if the target is empty (no source files would be added to project file) |
| 936 |
@staticmethod |
| 937 |
def should_skip(target): |
| 938 |
return not target.cxxobjects and not target.cxxclrobjects and not target.cobjects |
| 939 |
|
| 940 |
def emit(self): |
| 941 |
all_projects = [] |
| 942 |
for location, targets in self.gbuildparser.target_by_location.items(): |
| 943 |
projects = [] |
| 944 |
module = location.split('/')[-1] |
| 945 |
module_directory = os.path.join(self.solution_directory, module) |
| 946 |
for target in targets: |
| 947 |
if self.should_skip(target): |
| 948 |
print(' %s: no files to add, skipping' % target.target_name()) |
| 949 |
continue |
| 950 |
project_path = os.path.join(module_directory, '%s.vcxproj' % target.target_name()) |
| 951 |
project_guid = self.write_project(project_path, target) |
| 952 |
p = VisualStudioIntegrationGenerator.Project(project_guid, target, project_path) |
| 953 |
projects.append(p) |
| 954 |
self.write_solution(os.path.join(module_directory, '%s.sln' % module), projects) |
| 955 |
all_projects += projects |
| 956 |
|
| 957 |
self.write_solution(os.path.join(self.solution_directory, 'LibreOffice.sln'), all_projects) |
| 958 |
# this enables Python GDB pretty printers when debugging a WSL Linux build from VS |
| 959 |
MIEngine_options_path = os.path.join(gbuildparser.srcdir, 'solenv/vs/Microsoft.MIEngine.Options.xml') |
| 960 |
shutil.copy(MIEngine_options_path, self.solution_directory) |
| 961 |
|
| 962 |
@staticmethod |
| 963 |
def gen_guid(category, name): |
| 964 |
return str(uuid.uuid5(uuid.NAMESPACE_URL, 'vnd.libreoffice.vs-ide-integration:' + category + '/' + urllib.parse.quote(name))).upper() |
| 965 |
|
| 966 |
nmake_project_guid = '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942' |
| 967 |
nmake_folder_guid = '2150E333-8FDC-42A3-9474-1A3956D46DE8' |
| 968 |
|
| 969 |
def get_dependency_libs(self, linked_libs, library_projects): |
| 970 |
dependency_libs = {} |
| 971 |
for linked_lib in linked_libs: |
| 972 |
for library_project in library_projects: |
| 973 |
if library_project.target.name == linked_lib: |
| 974 |
dependency_libs[library_project.guid] = library_project |
| 975 |
return dependency_libs |
| 976 |
|
| 977 |
def write_solution(self, solution_path, projects): |
| 978 |
print('Solution %s:' % os.path.splitext(os.path.basename(solution_path))[0], end='') |
| 979 |
if not projects: |
| 980 |
print(' no projects, skipping') |
| 981 |
return |
| 982 |
library_projects = [project for project in projects if project.target in self.gbuildparser.libs] |
| 983 |
static_library_projects = [project for project in projects if project.target in self.gbuildparser.static_libs] |
| 984 |
test_projects = [project for project in projects if project.target in self.gbuildparser.tests] |
| 985 |
executable_projects = [project for project in projects if project.target in self.gbuildparser.exes] |
| 986 |
with open(solution_path, 'w') as f: |
| 987 |
f.write('Microsoft Visual Studio Solution File, Format Version 12.00\n') |
| 988 |
for project in projects: |
| 989 |
target = project.target |
| 990 |
print(' %s' % target.target_name(), end='') |
| 991 |
proj_path = os.path.relpath(project.path, os.path.abspath(os.path.dirname(solution_path))) |
| 992 |
f.write('Project("{%s}") = "%s", "%s", "{%s}"\n' % |
| 993 |
(VisualStudioIntegrationGenerator.nmake_project_guid, |
| 994 |
target.short_name(), proj_path, project.guid)) |
| 995 |
libs_in_solution = self.get_dependency_libs(target.linked_libs, |
| 996 |
library_projects) |
| 997 |
libs_in_solution |= self.get_dependency_libs(target.linked_static_libs, |
| 998 |
static_library_projects) |
| 999 |
if libs_in_solution: |
| 1000 |
f.write('\tProjectSection(ProjectDependencies) = postProject\n') |
| 1001 |
for lib_guid in libs_in_solution.keys(): |
| 1002 |
f.write('\t\t{%(guid)s} = {%(guid)s}\n' % {'guid': lib_guid}) |
| 1003 |
f.write('\tEndProjectSection\n') |
| 1004 |
f.write('EndProject\n') |
| 1005 |
f.write('Project("{%s}") = "Utility", "Utility", "{6778240E-8B6B-47A0-AC31-7E7A257B97E6}"\n' % |
| 1006 |
(VisualStudioIntegrationGenerator.nmake_folder_guid)) |
| 1007 |
f.write('\tProjectSection(SolutionItems) = preProject\n') |
| 1008 |
# The natvis file gives pretty-printed variable values when debugging |
| 1009 |
natvis_path = os.path.join(gbuildparser.srcdir, 'solenv/vs/LibreOffice.natvis') |
| 1010 |
f.write('\t\t%(natvis)s = %(natvis)s\n' % {'natvis': natvis_path}) |
| 1011 |
# The natstepfilter file allows to skip specific functions when stepping into in debugging |
| 1012 |
natstepfilter_path = os.path.join(gbuildparser.srcdir, 'solenv/vs/LibreOffice.natstepfilter') |
| 1013 |
f.write('\t\t%(natstepfilter)s = %(natstepfilter)s\n' % {'natstepfilter': natstepfilter_path}) |
| 1014 |
# The ruleset file defines the rules checked when --enable-msvc-analyze is used |
| 1015 |
ruleset_path = os.path.join(gbuildparser.srcdir, 'solenv/vs/LibreOffice.ruleset') |
| 1016 |
f.write('\t\t%(ruleset)s = %(ruleset)s\n' % {'ruleset': ruleset_path}) |
| 1017 |
f.write('\tEndProjectSection\n') |
| 1018 |
f.write('EndProject\n') |
| 1019 |
# Folders to group tests/libraries/executables |
| 1020 |
nmake_tests_guid = 'CF544F7B-9D02-4D83-8370-5887851209B7' |
| 1021 |
nmake_libraries_guid = 'C624F43D-616C-4627-B58F-F5C2047B7BDC' |
| 1022 |
nmake_static_libraries_guid = 'EB2CD1D4-7C29-4232-9B1E-9FB1FE62D61C' |
| 1023 |
nmake_executables_guid = '1CD80999-9FA9-4BA9-B4D9-6E33035CF648' |
| 1024 |
f.write('Project("{%s}") = "Tests", "Tests", "{%s}"\n' % |
| 1025 |
(VisualStudioIntegrationGenerator.nmake_folder_guid, nmake_tests_guid)) |
| 1026 |
f.write('EndProject\n') |
| 1027 |
f.write('Project("{%s}") = "Libraries", "Libraries", "{%s}"\n' % |
| 1028 |
(VisualStudioIntegrationGenerator.nmake_folder_guid, nmake_libraries_guid)) |
| 1029 |
f.write('EndProject\n') |
| 1030 |
f.write('Project("{%s}") = "StaticLibraries", "StaticLibraries", "{%s}"\n' % |
| 1031 |
(VisualStudioIntegrationGenerator.nmake_folder_guid, nmake_static_libraries_guid)) |
| 1032 |
f.write('EndProject\n') |
| 1033 |
f.write('Project("{%s}") = "Executables", "Executables", "{%s}"\n' % |
| 1034 |
(VisualStudioIntegrationGenerator.nmake_folder_guid, nmake_executables_guid)) |
| 1035 |
f.write('EndProject\n') |
| 1036 |
# end Folders to group tests/libraries/executables |
| 1037 |
f.write('Global\n') |
| 1038 |
platform = self.platform |
| 1039 |
f.write('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n') |
| 1040 |
for cfg in self.configurations: |
| 1041 |
f.write('\t\t%(cfg)s|%(platform)s = %(cfg)s|%(platform)s\n' % {'cfg': cfg, 'platform': platform}) |
| 1042 |
f.write('\tEndGlobalSection\n') |
| 1043 |
# Group projects to folders |
| 1044 |
f.write('\tGlobalSection(NestedProjects) = preSolution\n') |
| 1045 |
for project in test_projects: |
| 1046 |
f.write('\t\t{%s} = {%s}\n' % (project.guid, nmake_tests_guid)) |
| 1047 |
for project in library_projects: |
| 1048 |
f.write('\t\t{%s} = {%s}\n' % (project.guid, nmake_libraries_guid)) |
| 1049 |
for project in static_library_projects: |
| 1050 |
f.write('\t\t{%s} = {%s}\n' % (project.guid, nmake_static_libraries_guid)) |
| 1051 |
for project in executable_projects: |
| 1052 |
f.write('\t\t{%s} = {%s}\n' % (project.guid, nmake_executables_guid)) |
| 1053 |
f.write('\tEndGlobalSection\n') |
| 1054 |
# end Group projects to folders |
| 1055 |
f.write('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n') |
| 1056 |
# Specifies project configurations for solution configuration |
| 1057 |
for project in projects: |
| 1058 |
for cfg in self.configurations: |
| 1059 |
params = {'guid': project.guid, 'sol_cfg': cfg, 'proj_cfg': cfg, 'platform': platform} |
| 1060 |
f.write('\t\t{%(guid)s}.%(sol_cfg)s|%(platform)s.ActiveCfg = %(proj_cfg)s|%(platform)s\n' % params) |
| 1061 |
# Build.0 is basically 'Build checkbox' in configuration manager |
| 1062 |
f.write('\t\t{%(guid)s}.%(sol_cfg)s|%(platform)s.Build.0 = %(proj_cfg)s|%(platform)s\n' % params) |
| 1063 |
f.write('\tEndGlobalSection\n') |
| 1064 |
f.write('EndGlobal\n') |
| 1065 |
print('') |
| 1066 |
|
| 1067 |
@staticmethod |
| 1068 |
def to_long_names(shortnames): |
| 1069 |
if platform == "cygwin": |
| 1070 |
return (subprocess.check_output(["cygpath", "-wal"] + shortnames).decode("utf-8", "strict").rstrip()).split("\n") |
| 1071 |
else: |
| 1072 |
return shortnames |
| 1073 |
|
| 1074 |
# Unescape the values: \"tklo.dll\" => "tklo.dll" |
| 1075 |
escapepattern = re.compile(r'\\(.)') |
| 1076 |
|
| 1077 |
@staticmethod |
| 1078 |
def defs_list(defs): |
| 1079 |
defines_list = [] |
| 1080 |
# List defines |
| 1081 |
for key, value in defs.items(): |
| 1082 |
define = key |
| 1083 |
if value is not None: |
| 1084 |
define += '=' + VisualStudioIntegrationGenerator.escapepattern.sub(r'\1', value).replace('""', '"') |
| 1085 |
defines_list.append(define) |
| 1086 |
return defines_list |
| 1087 |
|
| 1088 |
ns = 'http://schemas.microsoft.com/developer/msbuild/2003' |
| 1089 |
|
| 1090 |
@classmethod |
| 1091 |
def add_objects(cls, objects, root_path, ext, target, parent_node, flags = ''): |
| 1092 |
for obj in objects: |
| 1093 |
objfile = os.path.join(root_path, obj) + ext |
| 1094 |
if os.path.isfile(objfile): |
| 1095 |
obj_node = ET.SubElement(parent_node, '{%s}ClCompile' % cls.ns, Include=objfile) |
| 1096 |
if flags: |
| 1097 |
obj_additional_options_node = ET.SubElement(obj_node, '{%s}AdditionalOptions' % cls.ns) |
| 1098 |
obj_additional_options_node.text = flags |
| 1099 |
else: |
| 1100 |
print('Source %s in project %s does not exist' % (objfile, target.target_name())) |
| 1101 |
|
| 1102 |
def write_project(self, project_path, target): |
| 1103 |
# See info at http://blogs.msdn.com/b/visualstudio/archive/2010/05/14/a-guide-to-vcxproj-and-props-file-structure.aspx |
| 1104 |
folder = os.path.dirname(project_path) |
| 1105 |
if not os.path.exists(folder): |
| 1106 |
os.makedirs(folder) |
| 1107 |
project_guid = self.gen_guid('project', target.short_name()) |
| 1108 |
cxxflags = ' '.join(target.cxxflags) |
| 1109 |
cxxclrflags = ' '.join(target.cxxclrflags) |
| 1110 |
cflags = ' '.join(target.cflags) |
| 1111 |
ET.register_namespace('', self.ns) |
| 1112 |
proj_node = ET.Element('{%s}Project' % self.ns, DefaultTargets='Build', ToolsVersion='4.0') |
| 1113 |
proj_confs_node = ET.SubElement(proj_node, '{%s}ItemGroup' % self.ns, Label='ProjectConfigurations') |
| 1114 |
platform = self.platform |
| 1115 |
for configuration in self.configurations: |
| 1116 |
proj_conf_node = ET.SubElement(proj_confs_node, |
| 1117 |
'{%s}ProjectConfiguration' % self.ns, |
| 1118 |
Include='%s|%s' % (configuration, platform)) |
| 1119 |
conf_node = ET.SubElement(proj_conf_node, '{%s}Configuration' % self.ns) |
| 1120 |
conf_node.text = configuration |
| 1121 |
platform_node = ET.SubElement(proj_conf_node, '{%s}Platform' % self.ns) |
| 1122 |
platform_node.text = platform |
| 1123 |
|
| 1124 |
globals_node = ET.SubElement(proj_node, '{%s}PropertyGroup' % self.ns, Label='Globals') |
| 1125 |
proj_guid_node = ET.SubElement(globals_node, '{%s}ProjectGuid' % self.ns) |
| 1126 |
proj_guid_node.text = '{%s}' % project_guid |
| 1127 |
proj_keyword_node = ET.SubElement(globals_node, '{%s}Keyword' % self.ns) |
| 1128 |
proj_keyword_node.text = 'MakeFileProj' |
| 1129 |
proj_name_node = ET.SubElement(globals_node, '{%s}ProjectName' % self.ns) |
| 1130 |
proj_name_node.text = target.short_name() |
| 1131 |
|
| 1132 |
ET.SubElement(proj_node, '{%s}Import' % self.ns, Project='$(VCTargetsPath)\\Microsoft.Cpp.Default.props') |
| 1133 |
for configuration in self.configurations: |
| 1134 |
conf_node = ET.SubElement(proj_node, '{%s}PropertyGroup' % self.ns, Label="Configuration", |
| 1135 |
Condition="'$(Configuration)|$(Platform)'=='%s|%s'" % (configuration, platform)) |
| 1136 |
# Type of project used by the MSBuild to determine build process, see Microsoft.Makefile.targets |
| 1137 |
conf_type_node = ET.SubElement(conf_node, '{%s}ConfigurationType' % self.ns) |
| 1138 |
conf_type_node.text = 'Makefile' |
| 1139 |
# This defines the version of Visual Studio which can show next to project names in the Solution Explorer |
| 1140 |
platform_toolset_node = ET.SubElement(conf_node, '{%s}PlatformToolset' % self.ns) |
| 1141 |
platform_toolset_node.text = self.toolset |
| 1142 |
|
| 1143 |
ET.SubElement(proj_node, '{%s}Import' % self.ns, Project='$(VCTargetsPath)\\Microsoft.Cpp.props') |
| 1144 |
ET.SubElement(proj_node, '{%s}ImportGroup' % self.ns, Label='ExtensionSettings') |
| 1145 |
for configuration in self.configurations: |
| 1146 |
prop_sheets_node = ET.SubElement(proj_node, '{%s}ImportGroup' % self.ns, Label='Configuration', |
| 1147 |
Condition="'$(Configuration)|$(Platform)'=='%s|%s'" % (configuration, platform)) |
| 1148 |
ET.SubElement(prop_sheets_node, '{%s}Import' % self.ns, |
| 1149 |
Project='$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props', |
| 1150 |
Condition="exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')", |
| 1151 |
Label='LocalAppDataPlatform') |
| 1152 |
|
| 1153 |
ET.SubElement(proj_node, '{%s}PropertyGroup' % self.ns, Label='UserMacros') |
| 1154 |
# VS IDE (at least "Peek definition") is allergic to paths like "C:/PROGRA~2/WI3CF2~1/10/Include/10.0.14393.0/um"; see |
| 1155 |
# https://developercommunity.visualstudio.com/content/problem/139659/vc-peek-definition-fails-to-navigate-to-windows-ki.html |
| 1156 |
# We need to convert to long paths here. Do this once, since it's time-consuming operation. |
| 1157 |
include_path_node_text = ';'.join(self.to_long_names(target.include)) |
| 1158 |
for cfg_name, cfg_targets in self.configurations.items(): |
| 1159 |
conf_node = ET.SubElement(proj_node, '{%s}PropertyGroup' % self.ns, |
| 1160 |
Condition="'$(Configuration)|$(Platform)'=='%s|%s'" % (cfg_name, platform)) |
| 1161 |
nmake_params = { |
| 1162 |
'sh': os.path.join(self.gbuildparser.binpath, 'dash.exe'), |
| 1163 |
'builddir': self.gbuildparser.builddir, |
| 1164 |
'location': target.location, |
| 1165 |
'makecmd': self.gbuildparser.makecmd, |
| 1166 |
'target': target.target_name()} |
| 1167 |
nmake_build_node = ET.SubElement(conf_node, '{%s}NMakeBuildCommandLine' % self.ns) |
| 1168 |
nmake_build_node.text = cfg_targets['build'] % nmake_params |
| 1169 |
nmake_clean_node = ET.SubElement(conf_node, '{%s}NMakeCleanCommandLine' % self.ns) |
| 1170 |
nmake_clean_node.text = cfg_targets['clean'] % nmake_params |
| 1171 |
nmake_rebuild_node = ET.SubElement(conf_node, '{%s}NMakeReBuildCommandLine' % self.ns) |
| 1172 |
nmake_rebuild_node.text = cfg_targets['rebuild'] % nmake_params |
| 1173 |
nmake_output_node = ET.SubElement(conf_node, '{%s}NMakeOutput' % self.ns) |
| 1174 |
nmake_output_node.text = os.path.join(self.gbuildparser.workdir, 'LinkTarget', target.link_target) |
| 1175 |
nmake_defs_node = ET.SubElement(conf_node, '{%s}NMakePreprocessorDefinitions' % self.ns) |
| 1176 |
nmake_defs_node.text = ';'.join(self.defs_list(target.defs) + ['$(NMakePreprocessorDefinitions)']) |
| 1177 |
nmake_debug_command_node = ET.SubElement(conf_node, '{%s}LocalDebuggerCommand' % self.ns) |
| 1178 |
nmake_debug_command_node.text = os.path.join(self.gbuildparser.instdir, 'program', 'soffice.bin') |
| 1179 |
nmake_debug_flavor_node = ET.SubElement(conf_node, '{%s}DebuggerFlavor' % self.ns) |
| 1180 |
nmake_debug_flavor_node.text = 'WindowsLocalDebugger' |
| 1181 |
include_path_node = ET.SubElement(conf_node, '{%s}IncludePath' % self.ns) |
| 1182 |
include_path_node.text = include_path_node_text |
| 1183 |
additional_options_node = ET.SubElement(conf_node, '{%s}AdditionalOptions' % self.ns) |
| 1184 |
additional_options_node.text = cxxflags |
| 1185 |
|
| 1186 |
ET.SubElement(proj_node, '{%s}ItemDefinitionGroup' % self.ns) |
| 1187 |
|
| 1188 |
cxxobjects_node = ET.SubElement(proj_node, '{%s}ItemGroup' % self.ns) |
| 1189 |
self.add_objects(target.cxxobjects, self.gbuildparser.srcdir, '.cxx', target, cxxobjects_node) |
| 1190 |
self.add_objects(target.cxxclrobjects, self.gbuildparser.srcdir, '.cxx', target, cxxobjects_node, cxxclrflags) |
| 1191 |
|
| 1192 |
cobjects_node = ET.SubElement(proj_node, '{%s}ItemGroup' % self.ns) |
| 1193 |
self.add_objects(target.cobjects, self.gbuildparser.srcdir, '.c', target, cobjects_node, cflags) |
| 1194 |
|
| 1195 |
ET.SubElement(proj_node, '{%s}Import' % self.ns, Project='$(VCTargetsPath)\\Microsoft.Cpp.targets') |
| 1196 |
ET.SubElement(proj_node, '{%s}ImportGroup' % self.ns, Label='ExtensionTargets') |
| 1197 |
self.write_pretty_xml(proj_node, project_path) |
| 1198 |
self.write_filters(project_path + '.filters', |
| 1199 |
os.path.join(self.gbuildparser.srcdir, os.path.basename(target.location)), |
| 1200 |
[cxx_node.get('Include') for cxx_node in cxxobjects_node.findall('{%s}ClCompile' % self.ns)], |
| 1201 |
[c_node.get('Include') for c_node in cobjects_node.findall('{%s}ClCompile' % self.ns)]) |
| 1202 |
return project_guid |
| 1203 |
|
| 1204 |
def get_filter(self, module_dir, proj_file): |
| 1205 |
return '\\'.join(os.path.relpath(proj_file, module_dir).split('/')[:-1]) |
| 1206 |
|
| 1207 |
def get_subfilters(self, proj_filter): |
| 1208 |
parts = proj_filter.split('\\') |
| 1209 |
subfilters = set([proj_filter]) if proj_filter else set() |
| 1210 |
for i in range(1, len(parts)): |
| 1211 |
subfilters.add('\\'.join(parts[:i])) |
| 1212 |
return subfilters |
| 1213 |
|
| 1214 |
def write_pretty_xml(self, node, file_path): |
| 1215 |
xml_str = ET.tostring(node, encoding='unicode') |
| 1216 |
pretty_str = minidom.parseString(xml_str).toprettyxml(encoding='utf-8') |
| 1217 |
with open(file_path, 'w') as f: |
| 1218 |
f.write(pretty_str.decode()) |
| 1219 |
|
| 1220 |
def add_nodes(self, files_node, module_dir, tag, project_files): |
| 1221 |
filters = set() |
| 1222 |
for project_file in project_files: |
| 1223 |
file_node = ET.SubElement(files_node, tag, Include=project_file) |
| 1224 |
if os.path.commonprefix([module_dir, project_file]) == module_dir: |
| 1225 |
project_filter = self.get_filter(module_dir, project_file) |
| 1226 |
filter_node = ET.SubElement(file_node, '{%s}Filter' % self.ns) |
| 1227 |
filter_node.text = project_filter |
| 1228 |
filters |= self.get_subfilters(project_filter) |
| 1229 |
return filters |
| 1230 |
|
| 1231 |
def write_filters(self, filters_path, module_dir, cxx_files, c_files): |
| 1232 |
ET.register_namespace('', self.ns) |
| 1233 |
proj_node = ET.Element('{%s}Project' % self.ns, ToolsVersion='4.0') |
| 1234 |
filters = set() |
| 1235 |
compiles_node = ET.SubElement(proj_node, '{%s}ItemGroup' % self.ns) |
| 1236 |
filters |= self.add_nodes(compiles_node, module_dir, '{%s}ClCompile' % self.ns, cxx_files) |
| 1237 |
filters |= self.add_nodes(compiles_node, module_dir, '{%s}ClCompile' % self.ns, c_files) |
| 1238 |
|
| 1239 |
filters_node = ET.SubElement(proj_node, '{%s}ItemGroup' % self.ns) |
| 1240 |
for proj_filter in filters: |
| 1241 |
filter_node = ET.SubElement(filters_node, '{%s}Filter' % self.ns, Include=proj_filter) |
| 1242 |
self.write_pretty_xml(proj_node, filters_path) |
| 1243 |
|
| 1244 |
|
| 1245 |
class QtCreatorIntegrationGenerator(IdeIntegrationGenerator): |
| 1246 |
|
| 1247 |
def __init__(self, gbuildparser, ide): |
| 1248 |
IdeIntegrationGenerator.__init__(self, gbuildparser, ide) |
| 1249 |
self.target_by_location = {} |
| 1250 |
for target in self.gbuildparser.libs | self.gbuildparser.exes | self.gbuildparser.tests: |
| 1251 |
if target.location not in self.target_by_location: |
| 1252 |
self.target_by_location[target.location] = set() |
| 1253 |
self.target_by_location[target.location] |= set([target]) |
| 1254 |
|
| 1255 |
self._do_log = False # set to 'True' to activate log of QtCreatorIntegrationGenerator |
| 1256 |
if self._do_log: |
| 1257 |
qtlog_path = os.path.abspath('../qtlog_.txt') |
| 1258 |
self.qtlog = open(qtlog_path, 'w') |
| 1259 |
|
| 1260 |
def _log(self, message): |
| 1261 |
if self._do_log: |
| 1262 |
self.qtlog.write(message) |
| 1263 |
|
| 1264 |
def log_close(self): |
| 1265 |
if self._do_log: |
| 1266 |
self.qtlog.close() |
| 1267 |
|
| 1268 |
def generate_build_configs(self, lib_folder): |
| 1269 |
module_folder = os.path.join(self.base_folder, lib_folder) |
| 1270 |
xml = "" |
| 1271 |
# In QtCreator UI, build configs are listed alphabetically, |
| 1272 |
# so it can be different from the creation order. |
| 1273 |
# So we prefix the names with the index. |
| 1274 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1275 |
'index': '0', |
| 1276 |
'base_folder': module_folder, |
| 1277 |
'arg': "", |
| 1278 |
'name': "1-Build %s" % lib_folder, |
| 1279 |
} |
| 1280 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1281 |
'index': '1', |
| 1282 |
'base_folder': module_folder, |
| 1283 |
'arg': "unitcheck", |
| 1284 |
'name': "2-Local tests -- quick tests (unitcheck)", |
| 1285 |
} |
| 1286 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1287 |
'index': '2', |
| 1288 |
'base_folder': module_folder, |
| 1289 |
'arg': "unitcheck slowcheck screenshot", |
| 1290 |
'name': "3-Local tests -- slow tests (unitcheck, slowcheck, screenshot)", |
| 1291 |
} |
| 1292 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1293 |
'index': '3', |
| 1294 |
'base_folder': module_folder, |
| 1295 |
'arg': "unitcheck slowcheck screenshot subsequentcheck", |
| 1296 |
'name': "4-Local tests -- integration tests (unitcheck, slowcheck, screenshot, subsequentcheck)", |
| 1297 |
} |
| 1298 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1299 |
'index': '4', |
| 1300 |
'base_folder': self.base_folder, |
| 1301 |
'arg': "unitcheck", |
| 1302 |
'name': "5-Global tests -- quick tests (unitcheck)", |
| 1303 |
} |
| 1304 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1305 |
'index': '5', |
| 1306 |
'base_folder': self.base_folder, |
| 1307 |
'arg': "unitcheck slowcheck screenshot", |
| 1308 |
'name': "6-Global tests -- slow tests (unitcheck, slowcheck, screenshot)", |
| 1309 |
} |
| 1310 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1311 |
'index': '6', |
| 1312 |
'base_folder': self.base_folder, |
| 1313 |
'arg': "unitcheck slowcheck screenshot subsequentcheck", |
| 1314 |
'name': "7-Global tests -- integration tests (unitcheck, slowcheck, screenshot, subsequentcheck)", |
| 1315 |
} |
| 1316 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1317 |
'index': '7', |
| 1318 |
'base_folder': self.base_folder, |
| 1319 |
'arg': "", |
| 1320 |
'name': "8-Global build -- nocheck", |
| 1321 |
} |
| 1322 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1323 |
'index': '8', |
| 1324 |
'base_folder': self.base_folder, |
| 1325 |
'arg': "", |
| 1326 |
'name': "9-Global build", |
| 1327 |
} |
| 1328 |
|
| 1329 |
xml += QtCreatorIntegrationGenerator.build_configs_count_template % { |
| 1330 |
'nb': '9', |
| 1331 |
} |
| 1332 |
return xml |
| 1333 |
|
| 1334 |
def generate_meta_build_configs(self): |
| 1335 |
xml = "" |
| 1336 |
# In QtCreator UI, build configs are listed alphabetically, |
| 1337 |
# so it can be different from the creation order. |
| 1338 |
# So we prefix the names with the index. |
| 1339 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1340 |
'index': '0', |
| 1341 |
'base_folder': self.base_folder, |
| 1342 |
'arg': "", |
| 1343 |
'name': "01-Global Build", |
| 1344 |
} |
| 1345 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1346 |
'index': '1', |
| 1347 |
'base_folder': self.base_folder, |
| 1348 |
'arg': "unitcheck", |
| 1349 |
'name': "02-Global tests -- quick tests (unitcheck)", |
| 1350 |
} |
| 1351 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1352 |
'index': '2', |
| 1353 |
'base_folder': self.base_folder, |
| 1354 |
'arg': "unitcheck slowcheck screenshot", |
| 1355 |
'name': "03-Global tests -- slow tests (unitcheck, slowcheck, screenshot)", |
| 1356 |
} |
| 1357 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1358 |
'index': '3', |
| 1359 |
'base_folder': self.base_folder, |
| 1360 |
'arg': "unitcheck slowcheck screenshot subsequentcheck", |
| 1361 |
'name': "04-Global tests -- integration tests (unitcheck, slowcheck, screenshot, subsequentcheck)", |
| 1362 |
} |
| 1363 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1364 |
'index': '4', |
| 1365 |
'base_folder': self.base_folder, |
| 1366 |
'arg': "perfcheck", |
| 1367 |
'name': "05-Global tests -- performance tests (perfcheck)", |
| 1368 |
} |
| 1369 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1370 |
'index': '5', |
| 1371 |
'base_folder': self.base_folder, |
| 1372 |
'arg': "check", |
| 1373 |
'name': "06-Global tests -- tests (check)", |
| 1374 |
} |
| 1375 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1376 |
'index': '6', |
| 1377 |
'base_folder': self.base_folder, |
| 1378 |
'arg': "", |
| 1379 |
'name': "07-Global build -- nocheck", |
| 1380 |
} |
| 1381 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1382 |
'index': '7', |
| 1383 |
'base_folder': self.base_folder, |
| 1384 |
'arg': "build-l10n-only", |
| 1385 |
'name': "08-Global build -- build-l10n-only", |
| 1386 |
} |
| 1387 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1388 |
'index': '8', |
| 1389 |
'base_folder': self.base_folder, |
| 1390 |
'arg': "build-non-l10n-only", |
| 1391 |
'name': "09-Global build -- build-non-l10n-only", |
| 1392 |
} |
| 1393 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1394 |
'index': '9', |
| 1395 |
'base_folder': self.base_folder, |
| 1396 |
'arg': "clean", |
| 1397 |
'name': "10-Global build -- clean", |
| 1398 |
} |
| 1399 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1400 |
'index': '10', |
| 1401 |
'base_folder': self.base_folder, |
| 1402 |
'arg': "clean-build", |
| 1403 |
'name': "11-Global build -- clean-build", |
| 1404 |
} |
| 1405 |
xml += QtCreatorIntegrationGenerator.build_configs_template % { |
| 1406 |
'index': '11', |
| 1407 |
'base_folder': self.base_folder, |
| 1408 |
'arg': "clean-host", |
| 1409 |
'name': "12-Global build -- clean-host", |
| 1410 |
} |
| 1411 |
xml += QtCreatorIntegrationGenerator.build_configs_count_template % { |
| 1412 |
'nb': '12', |
| 1413 |
} |
| 1414 |
return xml |
| 1415 |
|
| 1416 |
# By default, QtCreator creates 2 BuildStepList : "Build" and "Clean" |
| 1417 |
# but the "clean" can be empty. |
| 1418 |
build_configs_template = """ |
| 1419 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.%(index)s"> |
| 1420 |
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">%(base_folder)s</value> |
| 1421 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
| 1422 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
| 1423 |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
| 1424 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
| 1425 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 1426 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value> |
| 1427 |
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"> |
| 1428 |
<value type="QString">-w</value> |
| 1429 |
<value type="QString">-r</value> |
| 1430 |
</valuelist> |
| 1431 |
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value> |
| 1432 |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">%(arg)s</value> |
| 1433 |
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value> |
| 1434 |
</valuemap> |
| 1435 |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> |
| 1436 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value> |
| 1437 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 1438 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> |
| 1439 |
</valuemap> |
| 1440 |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> |
| 1441 |
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> |
| 1442 |
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> |
| 1443 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">%(name)s</value> |
| 1444 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> |
| 1445 |
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">%(index)s</value> |
| 1446 |
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> |
| 1447 |
</valuemap> |
| 1448 |
""" |
| 1449 |
|
| 1450 |
build_configs_count_template = """ |
| 1451 |
<!-- nb build configurations --> |
| 1452 |
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">%(nb)s</value> |
| 1453 |
""" |
| 1454 |
|
| 1455 |
def generate_deploy_configs(self, lib_folder): |
| 1456 |
xml = QtCreatorIntegrationGenerator.deploy_configs_template % {} |
| 1457 |
return xml |
| 1458 |
|
| 1459 |
deploy_configs_template = """ |
| 1460 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> |
| 1461 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
| 1462 |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> |
| 1463 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> |
| 1464 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 1465 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> |
| 1466 |
</valuemap> |
| 1467 |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> |
| 1468 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value> |
| 1469 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 1470 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> |
| 1471 |
</valuemap> |
| 1472 |
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value> |
| 1473 |
""" |
| 1474 |
|
| 1475 |
def generate_run_configs(self, lib_folder): |
| 1476 |
|
| 1477 |
if platform == 'darwin': |
| 1478 |
loexec = "%s/instdir/LibreOfficeDev.app/Contents/MacOS/soffice" % self.base_folder |
| 1479 |
else: |
| 1480 |
loexec = "%s/instdir/program/soffice.bin" % self.base_folder |
| 1481 |
xml = QtCreatorIntegrationGenerator.run_configs_template % { |
| 1482 |
'loexec': loexec, |
| 1483 |
'workdir': self.base_folder |
| 1484 |
} |
| 1485 |
return xml |
| 1486 |
|
| 1487 |
run_configs_template = """ |
| 1488 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> |
| 1489 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/> |
| 1490 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value> |
| 1491 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value> |
| 1492 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value> |
| 1493 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value> |
| 1494 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value> |
| 1495 |
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value> |
| 1496 |
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value> |
| 1497 |
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value> |
| 1498 |
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value> |
| 1499 |
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value> |
| 1500 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/> |
| 1501 |
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value> |
| 1502 |
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value> |
| 1503 |
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value> |
| 1504 |
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value> |
| 1505 |
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value> |
| 1506 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds"> |
| 1507 |
<value type="int">0</value> |
| 1508 |
<value type="int">1</value> |
| 1509 |
<value type="int">2</value> |
| 1510 |
<value type="int">3</value> |
| 1511 |
<value type="int">4</value> |
| 1512 |
<value type="int">5</value> |
| 1513 |
<value type="int">6</value> |
| 1514 |
<value type="int">7</value> |
| 1515 |
<value type="int">8</value> |
| 1516 |
<value type="int">9</value> |
| 1517 |
<value type="int">10</value> |
| 1518 |
<value type="int">11</value> |
| 1519 |
<value type="int">12</value> |
| 1520 |
<value type="int">13</value> |
| 1521 |
<value type="int">14</value> |
| 1522 |
</valuelist> |
| 1523 |
<value type="int" key="PE.EnvironmentAspect.Base">2</value> |
| 1524 |
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
| 1525 |
|
| 1526 |
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value> |
| 1527 |
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">%(loexec)s</value> |
| 1528 |
<value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">false</value> |
| 1529 |
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%(workdir)s</value> |
| 1530 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run libreoffice/instdir/program/soffice</value> |
| 1531 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
| 1532 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> |
| 1533 |
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> |
| 1534 |
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> |
| 1535 |
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> |
| 1536 |
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value> |
| 1537 |
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> |
| 1538 |
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> |
| 1539 |
|
| 1540 |
</valuemap> |
| 1541 |
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> |
| 1542 |
""" |
| 1543 |
|
| 1544 |
def generate_pro_shared_content(self, lib_folder): |
| 1545 |
|
| 1546 |
build_configs = self.generate_build_configs(lib_folder) |
| 1547 |
deploy_configs = self.generate_deploy_configs(lib_folder) |
| 1548 |
run_configs = self.generate_run_configs(lib_folder) |
| 1549 |
|
| 1550 |
xml = QtCreatorIntegrationGenerator.pro_shared_template % { |
| 1551 |
'build_configs': build_configs, |
| 1552 |
'deploy_configs': deploy_configs, |
| 1553 |
'run_configs': run_configs, |
| 1554 |
} |
| 1555 |
return xml |
| 1556 |
|
| 1557 |
def generate_meta_pro_shared_content(self): |
| 1558 |
|
| 1559 |
build_configs = self.generate_meta_build_configs() |
| 1560 |
deploy_configs = self.generate_deploy_configs("") |
| 1561 |
run_configs = self.generate_run_configs("") |
| 1562 |
|
| 1563 |
xml = QtCreatorIntegrationGenerator.pro_shared_template % { |
| 1564 |
'build_configs': build_configs, |
| 1565 |
'deploy_configs': deploy_configs, |
| 1566 |
'run_configs': run_configs, |
| 1567 |
} |
| 1568 |
return xml |
| 1569 |
|
| 1570 |
pro_shared_template = """<?xml version="1.0" encoding="UTF-8"?> |
| 1571 |
<!DOCTYPE QtCreatorProject> |
| 1572 |
<!-- Written by QtCreator 3.1.1, 2015-05-14T15:54:34. --> |
| 1573 |
<qtcreator> |
| 1574 |
<data> |
| 1575 |
<variable>ProjectExplorer.Project.ActiveTarget</variable> |
| 1576 |
<value type="int">0</value> |
| 1577 |
</data> |
| 1578 |
|
| 1579 |
<!-- editor settings --> |
| 1580 |
<data> |
| 1581 |
<variable>ProjectExplorer.Project.EditorSettings</variable> |
| 1582 |
<valuemap type="QVariantMap"> |
| 1583 |
<value type="bool" key="EditorConfiguration.AutoIndent">true</value> |
| 1584 |
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value> |
| 1585 |
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value> |
| 1586 |
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0"> |
| 1587 |
<value type="QString" key="language">Cpp</value> |
| 1588 |
<valuemap type="QVariantMap" key="value"> |
| 1589 |
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value> |
| 1590 |
</valuemap> |
| 1591 |
</valuemap> |
| 1592 |
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1"> |
| 1593 |
<value type="QString" key="language">QmlJS</value> |
| 1594 |
<valuemap type="QVariantMap" key="value"> |
| 1595 |
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value> |
| 1596 |
</valuemap> |
| 1597 |
</valuemap> |
| 1598 |
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value> |
| 1599 |
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value> |
| 1600 |
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value> |
| 1601 |
<value type="int" key="EditorConfiguration.IndentSize">4</value> |
| 1602 |
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value> |
| 1603 |
<value type="int" key="EditorConfiguration.MarginColumn">80</value> |
| 1604 |
<value type="bool" key="EditorConfiguration.MouseHiding">true</value> |
| 1605 |
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value> |
| 1606 |
<value type="int" key="EditorConfiguration.PaddingMode">1</value> |
| 1607 |
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value> |
| 1608 |
<value type="bool" key="EditorConfiguration.ShowMargin">false</value> |
| 1609 |
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value> |
| 1610 |
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value> |
| 1611 |
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value> |
| 1612 |
<value type="int" key="EditorConfiguration.TabSize">8</value> |
| 1613 |
<value type="bool" key="EditorConfiguration.UseGlobal">true</value> |
| 1614 |
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value> |
| 1615 |
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value> |
| 1616 |
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value> |
| 1617 |
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value> |
| 1618 |
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value> |
| 1619 |
</valuemap> |
| 1620 |
</data> |
| 1621 |
|
| 1622 |
<data> |
| 1623 |
<variable>ProjectExplorer.Project.PluginSettings</variable> |
| 1624 |
<valuemap type="QVariantMap"/> |
| 1625 |
</data> |
| 1626 |
|
| 1627 |
<!-- target --> |
| 1628 |
<data> |
| 1629 |
<variable>ProjectExplorer.Project.Target.0</variable> |
| 1630 |
<valuemap type="QVariantMap"> |
| 1631 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value> |
| 1632 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value> |
| 1633 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{0701de51-c96e-4e4f-85c3-e70b223c5076}</value> |
| 1634 |
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> |
| 1635 |
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> |
| 1636 |
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> |
| 1637 |
|
| 1638 |
<!-- build configurations --> |
| 1639 |
%(build_configs)s |
| 1640 |
|
| 1641 |
<!-- deploy configurations --> |
| 1642 |
%(deploy_configs)s |
| 1643 |
|
| 1644 |
<!-- plugin settings --> |
| 1645 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/> |
| 1646 |
|
| 1647 |
<!-- run configurations --> |
| 1648 |
%(run_configs)s |
| 1649 |
|
| 1650 |
</valuemap> |
| 1651 |
</data> |
| 1652 |
<!-- nb targets : 1 --> |
| 1653 |
<data> |
| 1654 |
<variable>ProjectExplorer.Project.TargetCount</variable> |
| 1655 |
<value type="int">1</value> |
| 1656 |
</data> |
| 1657 |
<data> |
| 1658 |
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable> |
| 1659 |
<value type="QByteArray">{5abcafed-86f6-49f6-b1cb-380fadd21211}</value> |
| 1660 |
</data> |
| 1661 |
<data> |
| 1662 |
<variable>ProjectExplorer.Project.Updater.FileVersion</variable> |
| 1663 |
<value type="int">15</value> |
| 1664 |
</data> |
| 1665 |
</qtcreator> |
| 1666 |
""" |
| 1667 |
|
| 1668 |
def get_file_path(self, src_file, ext_choices): |
| 1669 |
path = os.path.join(self.gbuildparser.srcdir, src_file) |
| 1670 |
for ext in ext_choices: |
| 1671 |
full_path = path + ext |
| 1672 |
if os.path.isfile(full_path): |
| 1673 |
return full_path |
| 1674 |
return "" |
| 1675 |
|
| 1676 |
def get_source_path(self, src_file): |
| 1677 |
return self.get_file_path(src_file, (".cxx", ".cpp", ".c", ".mm")) |
| 1678 |
|
| 1679 |
def get_header_path(self, src_file): |
| 1680 |
return self.get_file_path(src_file, (".hxx", ".hpp", ".h")) |
| 1681 |
|
| 1682 |
def build_data_libs(self): |
| 1683 |
|
| 1684 |
self.data_libs = {} |
| 1685 |
|
| 1686 |
all_libs = self.gbuildparser.libs | self.gbuildparser.exes | self.gbuildparser.tests |
| 1687 |
for lib in all_libs: |
| 1688 |
self._log("\nlibrary : %s, loc=%s" % (lib.short_name(), lib.location)) |
| 1689 |
lib_name = os.path.basename(lib.location) |
| 1690 |
lib_folder = os.path.relpath(lib.location, self.base_folder) |
| 1691 |
|
| 1692 |
def lopath(path): |
| 1693 |
if platform == "cygwin": |
| 1694 |
# absolute paths from GbuildToJson are Windows paths, |
| 1695 |
# so convert everything to such ones |
| 1696 |
abs_path = path |
| 1697 |
if not ntpath.isabs(abs_path): |
| 1698 |
abs_path = ntpath.join(self.gbuildparser.srcdir, path) |
| 1699 |
return abs_path.replace('\\', '/') |
| 1700 |
|
| 1701 |
return os.path.abspath(path) |
| 1702 |
|
| 1703 |
defines_list = [] |
| 1704 |
sources_list = [] |
| 1705 |
objcxx_sources_list = [] |
| 1706 |
includepath_list = [] |
| 1707 |
# The explicit headers list is not mandatory : |
| 1708 |
# QtCreator just needs 'include_path_list' to find all headers files. |
| 1709 |
# But files listed in 'header_list' will be shown |
| 1710 |
# in a specific "Headers" folder in QtCreator's Project panel. |
| 1711 |
# We will list here only headers files of current lib. |
| 1712 |
headers_list = [] |
| 1713 |
objcxx_headers_list = [] |
| 1714 |
for file_ in lib.cxxobjects: |
| 1715 |
# the file has no extension : search it |
| 1716 |
# self._log("\n file : %s" % file_) |
| 1717 |
path = self.get_source_path(file_) |
| 1718 |
if path: |
| 1719 |
sources_list.append(lopath(path)) |
| 1720 |
|
| 1721 |
# few cxxobject files have a header beside |
| 1722 |
path = self.get_header_path(file_) |
| 1723 |
if path: |
| 1724 |
headers_list.append(lopath(path)) |
| 1725 |
|
| 1726 |
for file_ in lib.objcxxobjects: |
| 1727 |
# the file has no extension: search it |
| 1728 |
path = self.get_source_path(file_) |
| 1729 |
if path: |
| 1730 |
objcxx_sources_list.append(lopath(path)) |
| 1731 |
|
| 1732 |
# several objcxxobject files have a header beside |
| 1733 |
path = self.get_header_path(file_) |
| 1734 |
if path: |
| 1735 |
objcxx_headers_list.append(lopath(path)) |
| 1736 |
|
| 1737 |
cxxstdversionflag = '' |
| 1738 |
for cxxflag in lib.cxxflags: |
| 1739 |
# extract flag for C++ standard version |
| 1740 |
if cxxflag.startswith('-std'): |
| 1741 |
cxxstdversionflag = cxxflag |
| 1742 |
|
| 1743 |
# List all include paths |
| 1744 |
for hdir in (lib.include + lib.include_sys): |
| 1745 |
hf_lopath = lopath(hdir) |
| 1746 |
includepath_list.append(hf_lopath) |
| 1747 |
|
| 1748 |
# List headers files from current lib |
| 1749 |
for hdir in lib.include: |
| 1750 |
if hdir.startswith(lib.location): |
| 1751 |
for dirpath, _, files in os.walk(hdir): |
| 1752 |
for hf in files: |
| 1753 |
if hf.endswith(('.h', '.hxx', '.hpp', '.hrc')): |
| 1754 |
hf_lopath = lopath(os.path.join(dirpath, hf)) |
| 1755 |
headers_list.append(hf_lopath) |
| 1756 |
|
| 1757 |
# List defines |
| 1758 |
for key, value in lib.defs.items(): |
| 1759 |
define = key |
| 1760 |
if value is not None: |
| 1761 |
define += '=' + value |
| 1762 |
defines_list.append(define) |
| 1763 |
|
| 1764 |
# All data are prepared, store them for the lib. |
| 1765 |
if lib_folder in self.data_libs: |
| 1766 |
self.data_libs[lib_folder]['sources'] |= set(sources_list) |
| 1767 |
self.data_libs[lib_folder]['headers'] |= set(headers_list) |
| 1768 |
self.data_libs[lib_folder]['objcxx_sources'] |= set(objcxx_sources_list) |
| 1769 |
self.data_libs[lib_folder]['objcxx_headers'] |= set(objcxx_headers_list) |
| 1770 |
self.data_libs[lib_folder]['cxxstdversionflag'] = cxxstdversionflag |
| 1771 |
self.data_libs[lib_folder]['includepath'] |= set(includepath_list) |
| 1772 |
self.data_libs[lib_folder]['defines'] |= set(defines_list) |
| 1773 |
else: |
| 1774 |
self.data_libs[lib_folder] = { |
| 1775 |
'sources': set(sources_list), |
| 1776 |
'headers': set(headers_list), |
| 1777 |
'objcxx_sources': set(objcxx_sources_list), |
| 1778 |
'objcxx_headers': set(objcxx_headers_list), |
| 1779 |
'cxxstdversionflag': cxxstdversionflag, |
| 1780 |
'includepath': set(includepath_list), |
| 1781 |
'defines': set(defines_list), |
| 1782 |
'loc': lib.location, |
| 1783 |
'name': lib_name |
| 1784 |
} |
| 1785 |
|
| 1786 |
def emit(self): |
| 1787 |
|
| 1788 |
mode = 'w+' |
| 1789 |
self.base_folder = self.gbuildparser.builddir |
| 1790 |
|
| 1791 |
# for .pro files, we must explicitly list all files (.c, .h) |
| 1792 |
# so we can't reuse directly the same method than for kde integration. |
| 1793 |
self.build_data_libs() |
| 1794 |
|
| 1795 |
# subdirs for the meta .pro file |
| 1796 |
subdirs_meta_pro = [] |
| 1797 |
subdirs_list = self.data_libs.keys() |
| 1798 |
# Now we can create Qt files |
| 1799 |
for lib_folder in subdirs_list: |
| 1800 |
sources_list = sorted(self.data_libs[lib_folder]['sources']) |
| 1801 |
headers_list = sorted(self.data_libs[lib_folder]['headers']) |
| 1802 |
objcxx_sources_list = sorted(self.data_libs[lib_folder]['objcxx_sources']) |
| 1803 |
objcxx_headers_list = sorted(self.data_libs[lib_folder]['objcxx_headers']) |
| 1804 |
cxxstdversionflag = self.data_libs[lib_folder]['cxxstdversionflag'] |
| 1805 |
includepath_list = sorted(self.data_libs[lib_folder]['includepath']) |
| 1806 |
defines_list = sorted(self.data_libs[lib_folder]['defines']) |
| 1807 |
lib_loc = self.data_libs[lib_folder]['loc'] |
| 1808 |
lib_name = self.data_libs[lib_folder]['name'] |
| 1809 |
|
| 1810 |
sources = " \\\n".join(sources_list) |
| 1811 |
headers = " \\\n".join(headers_list) |
| 1812 |
objcxx_sources = " \\\n".join(objcxx_sources_list) |
| 1813 |
objcxx_headers = " \\\n".join(objcxx_headers_list) |
| 1814 |
includepath = " \\\n".join(includepath_list) |
| 1815 |
defines = " \\\n".join(defines_list) |
| 1816 |
# strip '-std=' or '-std:' prefix |
| 1817 |
assert(isinstance(cxxstdversionflag, str) and cxxstdversionflag.startswith('-std')) |
| 1818 |
cxxstdversion = cxxstdversionflag[5:] |
| 1819 |
|
| 1820 |
# create .pro file |
| 1821 |
relative_subdir_path = os.path.relpath(lib_loc, self.gbuildparser.srcdir) |
| 1822 |
subdirs_meta_pro.append(relative_subdir_path) |
| 1823 |
qt_pro_file = os.path.join(self.base_folder, relative_subdir_path, lib_name + '.pro') |
| 1824 |
try: |
| 1825 |
content = QtCreatorIntegrationGenerator.pro_template % {'sources': sources, 'headers': headers, 'cxxstdversionflag': cxxstdversionflag, |
| 1826 |
'cxxstdversion': cxxstdversion, 'objcxx_sources': objcxx_sources, |
| 1827 |
'objcxx_headers': objcxx_headers, 'includepath': includepath, 'defines': defines} |
| 1828 |
with open(qt_pro_file, mode) as fpro: |
| 1829 |
fpro.write(content) |
| 1830 |
self._log("created %s\n" % qt_pro_file) |
| 1831 |
|
| 1832 |
except Exception as e: |
| 1833 |
print("ERROR : creating pro file=" + qt_pro_file, file=sys.stderr) |
| 1834 |
print(e, file=sys.stderr) |
| 1835 |
temp = traceback.format_exc() # .decode('utf8') |
| 1836 |
print(temp, file=sys.stderr) |
| 1837 |
print("\n\n", file=sys.stderr) |
| 1838 |
|
| 1839 |
# create .pro.shared file |
| 1840 |
qt_pro_shared_file = os.path.join(self.base_folder, relative_subdir_path, lib_name + '.pro.shared') |
| 1841 |
try: |
| 1842 |
with open(qt_pro_shared_file, mode) as fproshared: |
| 1843 |
fproshared.write(self.generate_pro_shared_content(lib_folder)) |
| 1844 |
self._log("created %s\n" % qt_pro_shared_file) |
| 1845 |
|
| 1846 |
except Exception as e: |
| 1847 |
print("ERROR : creating pro.shared file=" + qt_pro_shared_file, file=sys.stderr) |
| 1848 |
print(e, file=sys.stderr) |
| 1849 |
temp = traceback.format_exc() |
| 1850 |
print(temp, file=sys.stderr) |
| 1851 |
print("\n\n", file=sys.stderr) |
| 1852 |
|
| 1853 |
# create meta .pro file (lists all sub projects) |
| 1854 |
qt_meta_pro_file = os.path.join(self.base_folder, 'lo.pro') |
| 1855 |
try: |
| 1856 |
subdirs = " \\\n".join(sorted(subdirs_meta_pro)) |
| 1857 |
content = QtCreatorIntegrationGenerator.pro_meta_template % {'subdirs': subdirs} |
| 1858 |
with open(qt_meta_pro_file, 'w+') as fmpro: |
| 1859 |
fmpro.write(content) |
| 1860 |
|
| 1861 |
except Exception as e: |
| 1862 |
print("ERROR : creating lo.pro file=" + qt_meta_pro_file, file=sys.stderr) |
| 1863 |
print(e, file=sys.stderr) |
| 1864 |
temp = traceback.format_exc() |
| 1865 |
print(temp, file=sys.stderr) |
| 1866 |
print("\n\n", file=sys.stderr) |
| 1867 |
|
| 1868 |
# create meta .pro.shared file |
| 1869 |
qt_meta_pro_shared_file = os.path.join(self.base_folder, 'lo.pro.shared') |
| 1870 |
try: |
| 1871 |
with open(qt_meta_pro_shared_file, mode) as fmproshared: |
| 1872 |
fmproshared.write(self.generate_meta_pro_shared_content()) |
| 1873 |
self._log("created %s\n" % qt_meta_pro_shared_file) |
| 1874 |
|
| 1875 |
except Exception as e: |
| 1876 |
print("ERROR : creating lo.pro.shared file=" + qt_meta_pro_shared_file, file=sys.stderr) |
| 1877 |
print(e, file=sys.stderr) |
| 1878 |
temp = traceback.format_exc() |
| 1879 |
print(temp, file=sys.stderr) |
| 1880 |
print("\n\n", file=sys.stderr) |
| 1881 |
|
| 1882 |
self.log_close() |
| 1883 |
|
| 1884 |
pro_template = """TEMPLATE = lib |
| 1885 |
CONFIG += console |
| 1886 |
CONFIG -= app_bundle |
| 1887 |
CONFIG -= qt |
| 1888 |
CONFIG += %(cxxstdversion)s |
| 1889 |
|
| 1890 |
QMAKE_CXXFLAGS += %(cxxstdversionflag)s |
| 1891 |
|
| 1892 |
INCLUDEPATH += %(includepath)s |
| 1893 |
|
| 1894 |
SOURCES += %(sources)s |
| 1895 |
|
| 1896 |
HEADERS += %(headers)s |
| 1897 |
|
| 1898 |
OBJECTIVE_SOURCES += %(objcxx_sources)s |
| 1899 |
|
| 1900 |
OBJECTIVE_HEADERS += %(objcxx_headers)s |
| 1901 |
|
| 1902 |
DEFINES += %(defines)s |
| 1903 |
|
| 1904 |
""" |
| 1905 |
pro_meta_template = """TEMPLATE = subdirs |
| 1906 |
|
| 1907 |
SUBDIRS = %(subdirs)s |
| 1908 |
""" |
| 1909 |
|
| 1910 |
|
| 1911 |
def get_options(): |
| 1912 |
parser = argparse.ArgumentParser( |
| 1913 |
description='LibreOffice gbuild IDE project generator') |
| 1914 |
parser.add_argument('--ide', dest='ide', required=True, |
| 1915 |
help='the IDE to generate project files for') |
| 1916 |
parser.add_argument('--make', dest='makecmd', required=True, |
| 1917 |
help='the command to execute make') |
| 1918 |
return parser.parse_args() |
| 1919 |
|
| 1920 |
|
| 1921 |
if __name__ == '__main__': |
| 1922 |
args = get_options() |
| 1923 |
# FIXME: Hack |
| 1924 |
if args.makecmd == 'make': |
| 1925 |
args.makecmd = '/usr/bin/make' |
| 1926 |
|
| 1927 |
paths = {} |
| 1928 |
generators = { |
| 1929 |
'codelite': CodeliteIntegrationGenerator, |
| 1930 |
'eclipsecdt': EclipseCDTIntegrationGenerator, |
| 1931 |
'kdevelop': KdevelopIntegrationGenerator, |
| 1932 |
'xcode': XcodeIntegrationGenerator, |
| 1933 |
'vs': VisualStudioIntegrationGenerator, |
| 1934 |
'vim': VimIntegrationGenerator, |
| 1935 |
'debug': DebugIntegrationGenerator, |
| 1936 |
'qtcreator': QtCreatorIntegrationGenerator, |
| 1937 |
} |
| 1938 |
|
| 1939 |
if args.ide not in generators.keys(): |
| 1940 |
print("Invalid ide. valid values are %s" % ','.join(generators.keys())) |
| 1941 |
sys.exit(1) |
| 1942 |
|
| 1943 |
gbuildparser = GbuildParser(args.makecmd).parse() |
| 1944 |
|
| 1945 |
generators[args.ide](gbuildparser, args.ide).emit() |
| 1946 |
print("Successfully created the project files.") |
| 1947 |
|
| 1948 |
# Local Variables: |
| 1949 |
# indent-tabs-mode: nil |
| 1950 |
# End: |
| 1951 |
# |
| 1952 |
# vim: set et sw=4 ts=4: |