This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 247
/
migrate-to-xammac
executable file
·95 lines (80 loc) · 2.69 KB
/
migrate-to-xammac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import os
import sys
import xml.dom.minidom as DOM
def migrate_guid (project):
for node in project.getElementsByTagName ('ProjectTypeGuids'):
old = node.firstChild.nodeValue
node.firstChild.nodeValue = old.replace (
'{948B3504-5B70-4649-8FE4-BDE1FB46EC69}',
'{42C0BBD9-55CE-4FC1-8D90-A7348ABAFB23}')
return node.firstChild.nodeValue != old
def migrate_reference (project):
xammac_added = False
for ref in project.getElementsByTagName ('Reference'):
if ref.hasAttribute ('Include'):
name = ref.attributes['Include'].value.lower ()
if name == 'monomac' or name.startswith ('monomac ') or name.startswith('monomac,'):
if not xammac_added:
ref.attributes['Include'] = 'XamMac'
while ref.firstChild:
ref.removeChild (ref.firstChild)
xammac_added = True
return xammac_added
def add_linker_options (project):
options = {
'EnableCodeSigning': 'True',
'CodeSigningKey': 'Mac Developer',
'CreatePackage': 'False',
'EnablePackageSigning': 'False',
'PackageSigningKey': 'Developer ID Installer',
'IncludeMonoRuntime': 'True',
'UseSGen': 'False',
'LinkMode': 'Full'
}
options_updated = False
for node in project.getElementsByTagName ('PropertyGroup'):
if not node.hasAttribute ('Condition'):
continue
cond = node.attributes['Condition'].value
if cond == " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " or \
cond == " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ":
first_append_made = False
for key, value in options.iteritems ():
children = node.getElementsByTagName (key)
if len (children) > 0:
old = children[0].nodeValue
children[0].nodeValue = value
if children[0].nodeValue != old:
options_updated = True
else:
child = project.createElement (key)
child.appendChild (project.createTextNode (value))
if first_append_made:
node.appendChild (project.createTextNode (' '))
else:
node.appendChild (project.createTextNode (' '))
node.appendChild (child)
node.appendChild (project.createTextNode ('\n'))
first_append_made = True
options_updated = True
if first_append_made:
node.appendChild (project.createTextNode (' '))
return options_updated
def migrate_project (path):
with open (path, 'r') as fp:
eof_newline = fp.read ().endswith ('\n')
project = DOM.parse (path)
a = migrate_guid (project)
b = migrate_reference (project)
c = add_linker_options (project)
if not a and not b and not c:
return
xml = project.toxml ('utf-8')
xml = xml.replace ('"utf-8"?>', '"utf-8"?>\n')
xml = xml.replace ('/>', ' />')
with open (path, 'w') as fp:
fp.write (xml)
if eof_newline:
fp.write ('\n')
migrate_project (sys.argv[1])