mortimer 7 years ago
parent
commit
2f2327297d
3 changed files with 259 additions and 0 deletions
  1. 171 0
      Autobuild/build.py
  2. 43 0
      Autobuild/business.php
  3. 45 0
      Autobuild/package.php

+ 171 - 0
Autobuild/build.py

@@ -0,0 +1,171 @@
1
+import sys, getopt, os
2
+import commands
3
+import subprocess
4
+
5
+BUILD_PATH = ""
6
+BUILD_MODE = ""
7
+BUILD_VERSION = ""
8
+
9
+class color:
10
+   PURPLE = '\033[95m'
11
+   CYAN = '\033[96m'
12
+   DARKCYAN = '\033[36m'
13
+   BLUE = '\033[94m'
14
+   GREEN = '\033[92m'
15
+   YELLOW = '\033[93m'
16
+   RED = '\033[91m'
17
+   BOLD = '\033[1m'
18
+   UNDERLINE = '\033[4m'
19
+   END = '\033[0m'
20
+
21
+def usage():
22
+    print color.BOLD + "Usage:" + color.END
23
+    print color.BOLD + "Build:" + color.END + "python %s [-p|--path] [-m|mode] [Debug|Release] [-v|--version]" % sys.argv[0]
24
+
25
+def parserCommand(argv):
26
+    try:
27
+        opts, args = getopt.getopt(argv, "p:m:v:", ["path=mode=version="])
28
+        return opts, args
29
+    except getopt.GetoptError:
30
+        usage()
31
+        sys.exit(1)
32
+
33
+def validParamaters():
34
+    cmd = 'svn ls %s --username wangyongbin --password aabb1234 --no-auth-cache' % BUILD_PATH;
35
+    status, output = commands.getstatusoutput(cmd)
36
+    if status != 0 :
37
+        print "svn '(%s)' path not exist" % BUILD_PATH
38
+        sys.exit(1)
39
+    if BUILD_MODE not in ("Debug", "Release"):
40
+        print "build mode must be Debug|Release"
41
+        sys.exit(1)
42
+
43
+def rmTmpDir() :
44
+    status, output = commands.getstatusoutput('rm -rf .tmp')
45
+    if status != 0 :
46
+        print output
47
+        sys.exit(1)
48
+
49
+def mkTmpDir() :
50
+    status, output = commands.getstatusoutput('mkdir .tmp')
51
+    if status != 0 :
52
+        print output
53
+        sys.exit(1)
54
+
55
+def svnCheckout() :
56
+    cmd = 'svn co %s .tmp --username wangyongbin --password aabb1234 --force --no-auth-cache' % (BUILD_PATH);
57
+    if BUILD_VERSION != "Latest":
58
+        cmd = 'svn co -r %s %s .tmp --username wangyongbin --password aabb1234 --force --no-auth-cache' % (BUILD_VERSION, BUILD_PATH);
59
+    status = subprocess.call(cmd, shell=True)
60
+    # if status != 0 :
61
+    #     sys.exit(1)
62
+
63
+def unlockSign() :
64
+    status, output = commands.getstatusoutput('security unlock-keychain -p ascii');
65
+    status, output = commands.getstatusoutput('security unlock-keychain -p ascii /Users/ascii/Library/Keychains/login.keychain');
66
+    if status != 0 :
67
+        print output
68
+        sys.exit(1)
69
+
70
+def tmpDirPath() :
71
+    status, output = commands.getstatusoutput('pwd')
72
+    if status == 0 :
73
+        return output
74
+    else :
75
+        print output
76
+
77
+def buildDebug() :
78
+    status = subprocess.call('xcodebuild -workspace FirstLink.xcworkspace -scheme FirstLink -configuration Debug clean', shell=True)
79
+    # status = subprocess.call('xcodebuild -workspace FirstLink.xcworkspace -scheme FirstLink  SYMROOT=%s' % tmpDirPath(), shell=True)
80
+    status = subprocess.call('xcodebuild -workspace FirstLink.xcworkspace -scheme FirstLink  SYMROOT=%s -configuration Debug' % tmpDirPath(), shell=True)
81
+    if status != 0:
82
+        sys.exit(1)
83
+
84
+def buildArchive() :
85
+    status = subprocess.call('xcodebuild -workspace FirstLink.xcworkspace -scheme FirstLink -configuration Release clean', shell=True)
86
+    status = subprocess.call('xcodebuild -workspace FirstLink.xcworkspace -scheme FirstLink  DSTROOT=%s archive' % tmpDirPath(), shell=True)
87
+    if status != 0:
88
+        sys.exit(1)
89
+
90
+def packageForDebug():
91
+    cmd = 'cp -R ./Debug-iphoneos/FirstLink.app ./FirstLink.app'
92
+    status = subprocess.call(cmd, shell=True)
93
+    status, output = commands.getstatusoutput('date +%m%d%H%M')
94
+    if status != 0:
95
+        print output
96
+        sys.exit(1)
97
+    else :
98
+        filename = 'Debug_%s.tar.gz' % (output)
99
+        cmd = 'tar zcvf %s ./FirstLink.app' % (filename)
100
+        print '** START TAR PACKAGE **'
101
+        status = subprocess.call(cmd, shell=True)
102
+        if status == 0 :
103
+            print '** PACKAGE SUCCEEDED **'
104
+        else:
105
+            print '** PACKAGE FAILED **'
106
+
107
+        cmd = 'cp %s ../ipa/%s' % (filename, filename)
108
+        status, output = commands.getstatusoutput(cmd)
109
+        if status != 0:
110
+            print output
111
+            sys.exit(1)
112
+
113
+def packageForArchive():
114
+    cmd = 'cp -R ./Applications/FirstLink.app ./FirstLink.app'
115
+    status = subprocess.call(cmd, shell=True)
116
+    status, output = commands.getstatusoutput('date +%m%d%H%M')
117
+    if status != 0:
118
+        print output
119
+        sys.exit(1)
120
+    else :
121
+        filename = 'Release_%s.tar.gz' % (output)
122
+        cmd = 'tar zcvf %s ./FirstLink.app' % (filename)
123
+        print '** START TAR PACKAGE **'
124
+        status = subprocess.call(cmd, shell=True)
125
+        if status == 0 :
126
+            print '** PACKAGE SUCCEEDED **'
127
+        else:
128
+            print '** PACKAGE FAILED **'
129
+
130
+        cmd = 'cp %s ../ipa/%s' % (filename, filename)
131
+        status, output = commands.getstatusoutput(cmd)
132
+        if status != 0:
133
+            print output
134
+            sys.exit(1)
135
+
136
+
137
+if __name__ == "__main__":
138
+    opts, args = parserCommand(sys.argv[1:])
139
+    for opt, arg in opts:
140
+        if opt in ("-p", "--path"):
141
+            BUILD_PATH = arg;
142
+        if opt in ("-v", "--version"):
143
+            BUILD_VERSION = arg;
144
+        if opt in ("-m", "--mode"):
145
+            BUILD_MODE = arg;
146
+
147
+    validParamaters()
148
+
149
+    rmTmpDir()
150
+    mkTmpDir()
151
+    svnCheckout()
152
+    # unlockSign()
153
+
154
+    os.chdir(".tmp")
155
+    if BUILD_MODE == "Debug" :
156
+        buildDebug()
157
+        packageForDebug()
158
+        sys.exit(1)
159
+    elif BUILD_MODE == "Release":
160
+        buildArchive()
161
+        packageForArchive()
162
+        sys.exit(1)
163
+
164
+    usage()
165
+    sys.exit(1)
166
+
167
+
168
+
169
+
170
+
171
+

+ 43 - 0
Autobuild/business.php

@@ -0,0 +1,43 @@
1
+<html>
2
+<body>
3
+
4
+<?php
5
+
6
+$location   = $_GET['location'];
7
+$tagName    = $_GET['tag_name'];
8
+
9
+$mode       = $_GET['mode'];
10
+$version    = $_GET['version'];
11
+
12
+//echo "$location, $tagName, $mode, $version";
13
+
14
+$SVN_LOCATION       = "svn://firstlinkapp.com/repository/source/ios/";
15
+$WHOLE_TRUNK_PATH   = $SVN_LOCATION . "trunk/FirstLink";
16
+$PREFIX_TAG_PATH    = $SVN_LOCATION . "tags/";
17
+
18
+$path;
19
+if ($location == "trunk") {
20
+    $path = $WHOLE_TRUNK_PATH;
21
+} else {
22
+    $path = $PREFIX_TAG_PATH . $tagName . "/FirstLink";
23
+}
24
+
25
+$cmd = 'python build.py -p ' . $path . " -m " . $mode . " -v " . $version;
26
+//echo($cmd);
27
+
28
+//$output = shell_exec($cmd);
29
+//echo "<pre>$output</pre>";
30
+
31
+if( ($fp = popen($cmd, "r")) ) {
32
+    while(!feof($fp) ){
33
+        echo fread($fp, 512);
34
+        flush();
35
+        echo "<script> window.scrollTo(0,document.body.scrollHeight) </script>";
36
+    }
37
+    fclose($fp);
38
+}
39
+
40
+?>
41
+
42
+</body>
43
+</html>

+ 45 - 0
Autobuild/package.php

@@ -0,0 +1,45 @@
1
+<html>
2
+	<style type="text/css">
3
+		input[type=submit] {
4
+			width: 15em;  height: 4em;
5
+		}
6
+        input[id=version] {
7
+            text-align:center;
8
+        }
9
+	</style>
10
+	
11
+    <body>
12
+<!-- 	    <div align="center"> -->
13
+		    <form method="get" action="business.php">
14
+				<input type="radio" name="location" checked="true" value="trunk"/> trunk <input type="text" value="/repository/source/ios/trunk" readonly="readonly" size="32" /> <br/><br/>
15
+				<input type="radio" name="location" value="tag"/> tags&nbsp
16
+
17
+				<select name="tag_name">
18
+                    <?php
19
+                        $tags_cmd = "svn ls svn://firstlinkapp.com/repository/source/ios/tags --username wangyongbin --password aabb1234 --no-auth-cache";
20
+                        $output = shell_exec($tags_cmd);
21
+                        foreach (array_reverse(explode("/",$output))  as $value) {
22
+                            $string = str_replace(' ', '', $value);
23
+                            $string = str_replace("\n",'', $string);
24
+                            if (strlen($string)>0) {
25
+                                echo "<option value = ". $string ." > /tags/". $string ." </option>";
26
+                            }
27
+                        }
28
+                    ?>
29
+				</select>
30
+				
31
+				<br/><br/>
32
+                mode&nbsp&nbsp
33
+                <select name="mode">
34
+                    <option value = "Release" >Release</option>
35
+                    <option value = "Debug" >Debug</option>
36
+                </select>
37
+                <br/><br/>
38
+                version <input id="version" type="text" size="8" name="version" value="Latest" /> <br />
39
+			
40
+				<br/>
41
+				<input type="submit" value="Submit"/>
42
+			</form>
43
+<!-- 		</div> -->
44
+    </body>
45
+</html>