forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-on-top-of-internal
executable file
·119 lines (104 loc) · 4.38 KB
/
run-on-top-of-internal
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
#
# Wire
# Copyright (C) 2016 Wire Swiss GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
import os
import re
from tempfile import mkstemp
from shutil import move
from os import remove, close
import subprocess
import argparse
_PROJECT_FILE="Wire-iOS.xcodeproj/project.pbxproj"
_JENKINS_INTERNAL_XCCONFIG = "ConfigurationSets/Jenkins-Internal.xcconfig"
_JENKINS_DEV_XCCONFIG = "ConfigurationSets/Jenkins-Development.xcconfig"
_DEV_XCCONFIG = "ConfigurationSets/Development.xcconfig"
_UNCOMMENT_IN_JENKINS_XCCONFIG = "//#include \"Development.xcconfig\""
_COMMENT_IN_JENKINS_XCCONFIG = [
"CODE_SIGN_IDENTITY = ",
"PROVISIONING_PROFILE_APP = ",
"PROVISIONING_PROFILE_FMWK =",
"PROVISIONING_PROFILE_SHARE_EXT =",
"CODE_SIGN_ENTITLEMENTS_APP = ",
"CODE_SIGN_ENTITLEMENTS_SHARE_EXT = ",
]
_COMMENT_IN_DEV_XCONFIG = [
"CODE_SIGN_ENTITLEMENTS_APP = Wire-iOS/Entitlements-Dev.entitlements",
"CODE_SIGN_ENTITLEMENTS_SHARE_EXT = Wire-Sharing-Extension-iOS/Wire-Sharing-Extension-iOS.entitlements"
]
_PROJECT_ORIGINAL_CONFIG = "baseConfigurationReference = 8FC85546199246EF0008B66B /* Development.xcconfig */;"
_PROJECT_INT_CONFIG = " baseConfigurationReference = 8FC85549199246EF0008B66B /* Jenkins-Internal.xcconfig */;"
_PROJECT_DEV_CONFIG = " baseConfigurationReference = DBA4ADCE1A30C4CD00CB12C6 /* Jenkins-Development.xcconfig */;"
def replace_in_file(source_file, replace_function):
changes = False
fh, abs_path = mkstemp()
with open(abs_path,'w') as new_file:
with open(source_file) as old_file:
for line in old_file.readlines():
replaced_line = replace_function(line)
new_file.write(replaced_line)
if replaced_line != line:
changes = True
close(fh)
#Move new file
if changes:
print("Modified file", source_file)
move(abs_path, source_file)
else:
print "No line replaced in", source_file
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Replace the project settings to that XCode can run on top of the internal or development version")
parser.add_argument("--dev", action="store_true", help="Run on top of DEV instead")
parser.add_argument("--reset", action="store_true", help="Reset to the defaults settings")
args = parser.parse_args()
internal = not args.dev
reset = args.reset
# Check files and reset them
for path in [_JENKINS_INTERNAL_XCCONFIG, _PROJECT_FILE, _DEV_XCCONFIG, _JENKINS_DEV_XCCONFIG]:
if not os.path.isfile(path):
print "Can't find",path,", please run from project root folder"
exit(1)
# reset file
subprocess.check_call(["/usr/bin/git", "checkout", "--", path])
if reset:
exit(0)
def jekins_xcconfig_lines(line):
for match in _COMMENT_IN_JENKINS_XCCONFIG:
if line.startswith(match):
return "//"+line
if line.strip() == _UNCOMMENT_IN_JENKINS_XCCONFIG:
return line.strip()[2:]
return line
def dev_xcconfig_lines(line):
for match in _COMMENT_IN_DEV_XCONFIG:
if line.startswith(match):
return "//"+line
return line
def project_lines(line):
if line.strip() == _PROJECT_ORIGINAL_CONFIG:
if internal:
return _PROJECT_INT_CONFIG+"\n"
else:
return _PROJECT_DEV_CONFIG+"\n"
return line
# Replace
if internal:
replace_in_file(_JENKINS_INTERNAL_XCCONFIG, jekins_xcconfig_lines)
else:
replace_in_file(_JENKINS_DEV_XCCONFIG, jekins_xcconfig_lines)
replace_in_file(_DEV_XCCONFIG, dev_xcconfig_lines)
replace_in_file(_PROJECT_FILE, project_lines)