author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:34:25 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2012-02-11 23:34:25 (UTC) |
commit | 185949cb778dd13a566781bbfa8ef7ed344cc705 (patch) (unidiff) | |
tree | 8fc4ff8cf1efead7610e4141041dd440eb9febbd /scripts/builder/main.py | |
parent | 17efce23d9f205f56f5ebbe8e4f4ca581ea47bcb (diff) | |
download | clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.zip clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.tar.gz clipperz-185949cb778dd13a566781bbfa8ef7ed344cc705.tar.bz2 |
Improved build scripts
Signed-off-by: Giulio Cesare Solaroli <giulio.cesare@clipperz.com>
-rwxr-xr-x | scripts/builder/main.py | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/scripts/builder/main.py b/scripts/builder/main.py index 94f738f..6fce65d 100755 --- a/scripts/builder/main.py +++ b/scripts/builder/main.py | |||
@@ -1,166 +1,177 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # -*- coding: UTF-8 -*- | 2 | # -*- coding: UTF-8 -*- |
3 | 3 | ||
4 | import sys, os, json | 4 | import sys |
5 | import os | ||
6 | import json | ||
5 | import shutil | 7 | import shutil |
6 | import pprint | 8 | import pprint |
7 | import frontendBuilder | ||
8 | import codecs | 9 | import codecs |
9 | import itertools | 10 | import itertools |
10 | |||
11 | from collections import deque | 11 | from collections import deque |
12 | from phpBuilder import PhpBuilder | 12 | |
13 | from pythonBuilder import PythonBuilder | 13 | import frontendBuilder |
14 | import repository | ||
14 | 15 | ||
15 | pp = pprint.PrettyPrinter(indent=4, depth=4) | 16 | pp = pprint.PrettyPrinter(indent=4, depth=4) |
16 | 17 | ||
17 | #-------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------- |
18 | 19 | ||
19 | def scriptDir (): | 20 | def scriptDir (): |
20 | return os.path.dirname(sys.argv[0]) | 21 | return os.path.dirname(sys.argv[0]) |
21 | 22 | ||
22 | def projectBaseDir (): | 23 | def projectBaseDir (): |
23 | return os.path.abspath(scriptDir() + '/../..') | 24 | return os.path.abspath(scriptDir() + '/../..') |
24 | 25 | ||
25 | def projectTargetDir(): | 26 | def projectTargetDir(): |
26 | return projectBaseDir() + '/target/' | 27 | return projectBaseDir() + '/target/' |
27 | 28 | ||
28 | #-------------------------------------------------------------------- | 29 | #-------------------------------------------------------------------- |
29 | 30 | ||
30 | def createFolder (path): | 31 | def createFolder (path): |
31 | if not os.path.exists(path): | 32 | if not os.path.exists(path): |
32 | os.makedirs(path) | 33 | os.makedirs(path) |
33 | 34 | ||
34 | #-------------------------------------------------------------------- | 35 | #-------------------------------------------------------------------- |
35 | 36 | ||
36 | def loadSettings (component, module): | 37 | def loadSettings (component, module): |
37 | print "MODULE: " + module | 38 | # print "MODULE: " + module |
38 | 39 | ||
39 | if '.' in module: | 40 | if '.' in module: |
40 | moduleComponents = module.split('.') | 41 | moduleComponents = module.split('.') |
41 | module = moduleComponents[0] | 42 | module = moduleComponents[0] |
42 | submodule = moduleComponents[1] | 43 | submodule = moduleComponents[1] |
43 | else: | 44 | else: |
44 | submodule = module | 45 | submodule = module |
45 | 46 | ||
46 | settings = codecs.open(projectBaseDir() + '/' + component + '/' + module + '/properties/' + submodule + '.properties.json', 'r', 'utf-8') | 47 | #settings = codecs.open(projectBaseDir() + os.sep + component + os.sep + module + os.sep + 'properties' + os.sep + submodule + '.properties.json', 'r', 'utf-8') |
48 | settings = codecs.open(os.path.join(projectBaseDir(), component, module, 'properties', submodule + '.properties.json'), 'r', 'utf-8') | ||
47 | result = json.load(settings) | 49 | result = json.load(settings) |
48 | settings.close | 50 | settings.close |
49 | 51 | ||
50 | return result | 52 | return result |
51 | 53 | ||
52 | #==================================================================== | 54 | #==================================================================== |
53 | # | 55 | # |
54 | # def assembleFrontend (frontend, versions): | 56 | # def assembleFrontend (frontend, versions): |
55 | # result = {} | 57 | # result = {} |
56 | # settings = loadSettings('frontend', frontend) | 58 | # settings = loadSettings('frontend', frontend) |
57 | # builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir()) | 59 | # builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir()) |
58 | # | 60 | # |
59 | # for version in versions: | 61 | # for version in versions: |
60 | # if version == 'install': | 62 | # if version == 'install': |
61 | # result[version] = builder.assembleInstallVersion() | 63 | # result[version] = builder.assembleInstallVersion() |
62 | # elif version == 'debug': | 64 | # elif version == 'debug': |
63 | # result[version] = builder.assembleDebugVersion() | 65 | # result[version] = builder.assembleDebugVersion() |
64 | # else: | 66 | # else: |
65 | # raise Exception('unrecognized version: ' + version) | 67 | # raise Exception('unrecognized version: ' + version) |
66 | # | 68 | # |
67 | # return result | 69 | # return result |
68 | # | 70 | # |
69 | #==================================================================== | 71 | #==================================================================== |
70 | 72 | ||
71 | def assembleBackend (backend, frontends, versions): | 73 | def assembleBackend (backend, frontends, versions): |
72 | settings = loadSettings('backend', backend) | 74 | settings = loadSettings('backend', backend) |
73 | 75 | ||
74 | if backend == 'php': | 76 | builderModuleName = backend + 'Builder' |
75 | backendBuilder = PhpBuilder(projectTargetDir(), frontends, versions, settings) | 77 | builderClassName = backend.capitalize() + 'Builder' |
76 | elif backend == 'python': | 78 | |
77 | backendBuilder = PythonBuilder(projectTargetDir(), frontends, versions, settings) | 79 | builderModule = __import__(builderModuleName) |
78 | #elif backend == 'java': | 80 | builderClass = getattr(builderModule, builderClassName) |
79 | #buildJavaBackend (frontends, versions, settings) | 81 | |
80 | else: | 82 | backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) |
81 | raise Exception('unrecognized backend: ' + backend) | ||
82 | |||
83 | backendBuilder.run() | 83 | backendBuilder.run() |
84 | 84 | ||
85 | #==================================================================== | 85 | #==================================================================== |
86 | 86 | ||
87 | def build (settings): | 87 | def build (settings, repository): |
88 | frontends = [] | 88 | frontends = [] |
89 | 89 | ||
90 | if repository.areTherePendingChanges(): | ||
91 | print "\nWARNING: repository has pending changes\n" | ||
92 | |||
90 | for frontend in settings['frontends']: | 93 | for frontend in settings['frontends']: |
91 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend))) | 94 | frontends.append(frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())) |
92 | 95 | ||
93 | for backend in settings['backends']: | 96 | for backend in settings['backends']: |
94 | assembleBackend(backend, frontends, settings['versions']) | 97 | assembleBackend(backend, frontends, settings['versions']) |
95 | 98 | ||
96 | #-------------------------------------------------------------------- | 99 | #-------------------------------------------------------------------- |
97 | 100 | ||
98 | def clean (): | 101 | def clean (): |
99 | print "cleaning up …" | 102 | # print "cleaning up …" |
100 | if os.path.exists(projectTargetDir()): | 103 | if os.path.exists(projectTargetDir()): |
101 | shutil.rmtree(projectTargetDir()) | 104 | shutil.rmtree(projectTargetDir()) |
102 | 105 | ||
103 | #-------------------------------------------------------------------- | 106 | #-------------------------------------------------------------------- |
104 | 107 | ||
105 | def usage (message): | 108 | def usage (message): |
106 | if message != None: | 109 | if message != None: |
107 | print "ERROR: " + message | 110 | print "ERROR: " + message |
108 | 111 | ||
109 | 112 | ||
110 | print "build.py clean" | 113 | # print "build clean" |
111 | print "build.py clean install" | 114 | # print "build clean install" |
112 | print "build.py install --ALL" | 115 | print "build install --ALL" |
113 | print "build.py install debug --ALL" | 116 | print "build install debug --ALL" |
114 | print "build.py clean install debug --ALL" | 117 | # print "build clean install debug --ALL" |
115 | print "build.ph install, debug --backends php java --frontends beta gamma" | 118 | print "build install debug --backends php python --frontends beta gamma" |
116 | print "build.ph install, debug --backends php java --frontends beta gamma gamma.mobile" | 119 | print "build install debug development --backends php python --frontends beta gamma gamma.mobile" |
117 | exit(1) | 120 | exit(1) |
118 | 121 | ||
119 | #-------------------------------------------------------------------- | 122 | #-------------------------------------------------------------------- |
120 | 123 | ||
124 | def allFrontends (): | ||
125 | return ['beta', 'gamma', 'mobile'] | ||
126 | |||
127 | def allBackends (): | ||
128 | return ['php', 'python'] | ||
129 | |||
130 | #-------------------------------------------------------------------- | ||
131 | |||
121 | def main (): | 132 | def main (): |
122 | settings = {} | 133 | settings = {} |
123 | parameters = list(itertools.islice(sys.argv, 1, None)) | 134 | parameters = list(itertools.islice(sys.argv, 1, None)) |
124 | 135 | ||
125 | shouldClean = len(filter(lambda x: x == 'clean', parameters)) > 0 | 136 | sys.path.append(os.path.join(scriptDir(), 'backends')) |
126 | if (shouldClean): | 137 | currentRepository = repository.repositoryWithPath(projectBaseDir()) |
127 | clean () | 138 | |
128 | 139 | clean() | |
129 | parameters = filter(lambda x: x != 'clean', parameters) | ||
130 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 140 | versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
131 | settings['versions'] = versions; #['debug', 'install'] | 141 | settings['versions'] = versions; #['debug', 'install', 'development'] |
132 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | 142 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) |
133 | 143 | ||
134 | if len(parameters) > 0: | 144 | if len(parameters) > 0: |
135 | parameter = parameters.popleft() | 145 | parameter = parameters.popleft() |
136 | if parameter == "--ALL": | 146 | if parameter == "--ALL": |
137 | settings['frontends'] = ['beta', 'gamma', 'mobile'] | 147 | settings['frontends'] = allFrontends() |
138 | settings['backends'] = ['php', 'python', 'java'] | 148 | settings['backends'] = allBackends() |
139 | else: | 149 | else: |
140 | while parameter != None: | 150 | while parameter != None: |
141 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) | 151 | values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) |
142 | 152 | ||
143 | if parameter == "--backends": | 153 | if parameter == "--backends": |
144 | settings['backends'] = values | 154 | settings['backends'] = values |
145 | elif parameter == "--frontends": | 155 | elif parameter == "--frontends": |
146 | settings['frontends'] = values | 156 | settings['frontends'] = values |
147 | 157 | ||
148 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) | 158 | parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) |
149 | if parameters: | 159 | if parameters: |
150 | parameter = parameters.popleft() | 160 | parameter = parameters.popleft() |
151 | else: | 161 | else: |
152 | parameter = None | 162 | parameter = None |
153 | 163 | ||
154 | if (not settings.has_key('versions')): | 164 | if (not settings.has_key('versions')): |
155 | usage("missing 'versions'") | 165 | usage("missing 'versions'") |
156 | if (not settings.has_key('frontends')): | 166 | if (not settings.has_key('frontends')): |
157 | usage("missing 'frontends'") | 167 | usage("missing 'frontends'") |
158 | if (not settings.has_key('backends')): | 168 | if (not settings.has_key('backends')): |
159 | usage("missing 'backends'") | 169 | usage("missing 'backends'") |
160 | 170 | ||
161 | build (settings) | 171 | build(settings, currentRepository) |
162 | 172 | else: | |
173 | usage("Suggestions on how to call the 'build' script:") | ||
163 | 174 | ||
164 | 175 | ||
165 | if __name__ == "__main__": | 176 | if __name__ == "__main__": |
166 | main() | 177 | main() |