1 | from __future__ import with_statement |
---|
2 | import sys |
---|
3 | import os |
---|
4 | from os.path import * |
---|
5 | import shutil |
---|
6 | from shutil import * |
---|
7 | from glob import * |
---|
8 | from subprocess import * |
---|
9 | from datetime import * |
---|
10 | |
---|
11 | |
---|
12 | output_dir = abspath("pelit") |
---|
13 | build_result_dir = abspath("build") |
---|
14 | lib_dir_x86 = abspath('lib\\x86') |
---|
15 | personal_dirs = [d for d in os.listdir(".") if isdir(d) and d not in ("lib", basename(output_dir), ".svn")] |
---|
16 | projects_that_did_not_build = [] |
---|
17 | msbuild = "msbuild" |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | def check_requirements(): |
---|
22 | global msbuild |
---|
23 | if not exists("lib\\x86\\Jypeli4.dll"): |
---|
24 | raise Exception("lib\\x86\\Jypeli4.dll expected") |
---|
25 | return_code = call(msbuild + " /? 1> NUL 2> NUL", shell=True) |
---|
26 | if return_code != 0: |
---|
27 | msbuild = join(os.getenv("SystemRoot"), "Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe") |
---|
28 | if not exists(msbuild): |
---|
29 | raise Exception("MSBuild not found in " + msbuild) |
---|
30 | |
---|
31 | |
---|
32 | def create_output_directory(): |
---|
33 | if not exists(output_dir): |
---|
34 | os.mkdir(output_dir) |
---|
35 | for d in personal_dirs: |
---|
36 | if not exists(join(output_dir, d)): |
---|
37 | os.mkdir(join(output_dir, d)) |
---|
38 | |
---|
39 | def create_build_result_directory(): |
---|
40 | if not exists(build_result_dir): |
---|
41 | os.mkdir(build_result_dir) |
---|
42 | |
---|
43 | |
---|
44 | def build_games(): |
---|
45 | for d in personal_dirs: |
---|
46 | path = abspath(d) |
---|
47 | time_of_update = datetime.now() |
---|
48 | if exists(join(path, ".svn")): |
---|
49 | call("svn update " + path, shell=True) |
---|
50 | build_games_in_personal_dir(path, time_of_update) |
---|
51 | |
---|
52 | |
---|
53 | counter = 1 |
---|
54 | |
---|
55 | |
---|
56 | def write_result(author, name, success, time_of_update): |
---|
57 | global counter |
---|
58 | with open(join(build_result_dir, str(counter)+".txt"), "w") as f: |
---|
59 | f.write(author+"\n") |
---|
60 | f.write(name+"\n") |
---|
61 | result = "success" |
---|
62 | if not success: |
---|
63 | result = "fail" |
---|
64 | f.write(result+"\n") |
---|
65 | f.write(str(time_of_update)+"\n") |
---|
66 | counter += 1 |
---|
67 | |
---|
68 | |
---|
69 | def build_games_in_personal_dir(personal_dir, time_of_update): |
---|
70 | for root, dirs, files in os.walk(personal_dir): |
---|
71 | if '.svn' in dirs: |
---|
72 | dirs.remove('.svn') |
---|
73 | projects = glob(join(root, '*.csproj')) |
---|
74 | if projects: |
---|
75 | if len(projects) > 1: |
---|
76 | print "NOTE: There is more than one project file in", root |
---|
77 | |
---|
78 | project_name = splitext(basename(projects[0]))[0] |
---|
79 | author = basename(personal_dir) |
---|
80 | |
---|
81 | success = build(projects[0]) |
---|
82 | write_result(author, project_name, success, time_of_update) |
---|
83 | |
---|
84 | if success: |
---|
85 | dst_dir = join(output_dir, author) |
---|
86 | copy_game(project_name, root, dst_dir) |
---|
87 | print author + ": " + project_name |
---|
88 | else: |
---|
89 | projects_that_did_not_build.append(projects[0]) |
---|
90 | |
---|
91 | |
---|
92 | def build(project_file_path): |
---|
93 | build_cmd = msbuild + ' /nologo /verbosity:quiet /p:XnaProfile=Reach /p:Configuration=Release /p:"ReferencePath=%s" /t:Build "%s"' % (lib_dir_x86, project_file_path) |
---|
94 | return call(build_cmd, shell=True) == 0 |
---|
95 | |
---|
96 | |
---|
97 | def copy_game(project_name, project_dir, dst_dir): |
---|
98 | bin = join(project_dir, "bin\\x86\\Release") |
---|
99 | if not exists(bin): |
---|
100 | print "NO BIN DIR FOUND IN", project_dir |
---|
101 | dst = join(dst_dir, project_name) |
---|
102 | if exists(dst): |
---|
103 | rmtree(dst) |
---|
104 | copytree(bin, dst, ignore=shutil.ignore_patterns('.svn', '*.pdb', 'jypeli4.xml')) |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | def main(): |
---|
109 | try: |
---|
110 | check_requirements() |
---|
111 | create_output_directory() |
---|
112 | create_build_result_directory() |
---|
113 | build_games() |
---|
114 | except KeyboardInterrupt: |
---|
115 | print "BUILD CANCELLED" |
---|
116 | except Exception, e: |
---|
117 | print |
---|
118 | print "NOT SUCCESSFUL:", e |
---|
119 | return 1 |
---|
120 | |
---|
121 | print |
---|
122 | print 'Projects that did not build (%d):' % len(projects_that_did_not_build) |
---|
123 | for p in projects_that_did_not_build: |
---|
124 | print p |
---|
125 | |
---|
126 | |
---|
127 | if __name__ == '__main__': |
---|
128 | sys.exit(main()) |
---|