summaryrefslogtreecommitdiff
authorMichael Krelin <hacker@klever.net>2014-06-30 19:23:23 (UTC)
committer Michael Krelin <hacker@klever.net>2014-06-30 19:23:23 (UTC)
commitb9ee39b810aae10da83534776028585309b53a24 (patch) (unidiff)
tree02de66579bbc322cc10bcb5727ef69d03775783e
parent7a1f88f679d1574b93fba3415aa11fc4471eacbf (diff)
downloadclipperz-b9ee39b810aae10da83534776028585309b53a24.zip
clipperz-b9ee39b810aae10da83534776028585309b53a24.tar.gz
clipperz-b9ee39b810aae10da83534776028585309b53a24.tar.bz2
builder: add --force-dirty flag
Besides being good for development, it seems to be a necessity in case we are checked out as a submodule
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/builder/main.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/scripts/builder/main.py b/scripts/builder/main.py
index ecdbf6a..47e10a0 100755
--- a/scripts/builder/main.py
+++ b/scripts/builder/main.py
@@ -1,196 +1,199 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2# -*- coding: UTF-8 -*- 2# -*- coding: UTF-8 -*-
3 3
4import sys 4import sys
5import os 5import os
6import json 6import json
7import shutil 7import shutil
8import pprint 8import pprint
9import codecs 9import codecs
10import itertools 10import itertools
11from collections import deque 11from collections import deque
12 12
13#import frontendBuilder 13#import frontendBuilder
14import repository 14import repository
15 15
16pp = pprint.PrettyPrinter(indent=4, depth=4) 16pp = pprint.PrettyPrinter(indent=4, depth=4)
17 17
18#-------------------------------------------------------------------- 18#--------------------------------------------------------------------
19 19
20def scriptDir (): 20def scriptDir ():
21 return os.path.dirname(sys.argv[0]) 21 return os.path.dirname(sys.argv[0])
22 22
23def projectBaseDir (): 23def projectBaseDir ():
24 return os.path.abspath(scriptDir() + '/../..') 24 return os.path.abspath(scriptDir() + '/../..')
25 25
26def projectTargetDir(): 26def projectTargetDir():
27 return projectBaseDir() + '/target/' 27 return projectBaseDir() + '/target/'
28 28
29#-------------------------------------------------------------------- 29#--------------------------------------------------------------------
30 30
31def createFolder (path): 31def createFolder (path):
32 if not os.path.exists(path): 32 if not os.path.exists(path):
33 os.makedirs(path) 33 os.makedirs(path)
34 34
35#-------------------------------------------------------------------- 35#--------------------------------------------------------------------
36 36
37def loadSettings (component, module): 37def loadSettings (component, module):
38 # print "MODULE: " + module 38 # print "MODULE: " + module
39 39
40 if '.' in module: 40 if '.' in module:
41 moduleComponents = module.split('.') 41 moduleComponents = module.split('.')
42 module = moduleComponents[0] 42 module = moduleComponents[0]
43 submodule = moduleComponents[1] 43 submodule = moduleComponents[1]
44 else: 44 else:
45 submodule = module 45 submodule = module
46 46
47 #settings = codecs.open(projectBaseDir() + os.sep + component + os.sep + module + os.sep + 'properties' + os.sep + 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') 48 settings = codecs.open(os.path.join(projectBaseDir(), component, module, 'properties', submodule + '.properties.json'), 'r', 'utf-8')
49 result = json.load(settings) 49 result = json.load(settings)
50 settings.close 50 settings.close
51 51
52 return result 52 return result
53 53
54#==================================================================== 54#====================================================================
55# 55#
56# def assembleFrontend (frontend, versions): 56# def assembleFrontend (frontend, versions):
57 # result = {} 57 # result = {}
58 # settings = loadSettings('frontend', frontend) 58 # settings = loadSettings('frontend', frontend)
59 # builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir()) 59 # builder = frontendBuilder.FrontendBuilder(frontend, settings, projectBaseDir())
60 # 60 #
61 # for version in versions: 61 # for version in versions:
62 # if version == 'install': 62 # if version == 'install':
63 # result[version] = builder.assembleInstallVersion() 63 # result[version] = builder.assembleInstallVersion()
64 # elif version == 'debug': 64 # elif version == 'debug':
65 # result[version] = builder.assembleDebugVersion() 65 # result[version] = builder.assembleDebugVersion()
66 # else: 66 # else:
67 # raise Exception('unrecognized version: ' + version) 67 # raise Exception('unrecognized version: ' + version)
68 # 68 #
69 # return result 69 # return result
70# 70#
71#==================================================================== 71#====================================================================
72 72
73def assembleBackend (backend, frontends, versions): 73def assembleBackend (backend, frontends, versions):
74 settings = loadSettings('backend', backend) 74 settings = loadSettings('backend', backend)
75 75
76 builderModuleName = backend + 'Builder' 76 builderModuleName = backend + 'Builder'
77 builderClassName = backend.capitalize() + 'Builder' 77 builderClassName = backend.capitalize() + 'Builder'
78 #print ("BUILD BACKENDS - module: " + builderModuleName + " , class: " + builderClassName) 78 #print ("BUILD BACKENDS - module: " + builderModuleName + " , class: " + builderClassName)
79 builderModule = __import__(builderModuleName) 79 builderModule = __import__(builderModuleName)
80 builderClass = getattr(builderModule, builderClassName) 80 builderClass = getattr(builderModule, builderClassName)
81 81
82 backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings) 82 backendBuilder = builderClass(projectTargetDir(), frontends, versions, settings)
83 backendBuilder.run() 83 backendBuilder.run()
84 84
85#==================================================================== 85#====================================================================
86 86
87def build (settings, repository): 87def build (settings, repository):
88 frontends = [] 88 frontends = []
89 89
90 if repository.areTherePendingChanges(): 90 if repository.areTherePendingChanges():
91 if 'install' in settings['versions']: 91 if 'install' in settings['versions'] and not settings['forcedirty']:
92 raise Exception("repository has pending changes, can't 'install'") 92 raise Exception("repository has pending changes, can't 'install'")
93 else: 93 else:
94 print "\nWARNING: repository has pending changes\n" 94 print "\nWARNING: repository has pending changes\n"
95 95
96 for frontend in settings['frontends']: 96 for frontend in settings['frontends']:
97 normalizedFrontendName = frontend.replace(".", "_") 97 normalizedFrontendName = frontend.replace(".", "_")
98 builderModuleName = normalizedFrontendName + 'Builder' 98 builderModuleName = normalizedFrontendName + 'Builder'
99 builderClassName = normalizedFrontendName.title() + 'Builder' 99 builderClassName = normalizedFrontendName.title() + 'Builder'
100 100
101 #print ("BUILD FRONTEND - module: " + builderModuleName + " , class: " + builderClassName) 101 #print ("BUILD FRONTEND - module: " + builderModuleName + " , class: " + builderClassName)
102 builderModule = __import__(builderModuleName) 102 builderModule = __import__(builderModuleName)
103 builderClass = getattr(builderModule, builderClassName) 103 builderClass = getattr(builderModule, builderClassName)
104 builder = builderClass(frontend, loadSettings('frontend', frontend), repository.version()) 104 builder = builderClass(frontend, loadSettings('frontend', frontend), repository.version())
105 #builder = frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version()) 105 #builder = frontendBuilder.FrontendBuilder(frontend, loadSettings('frontend', frontend), repository.version())
106 frontends.append(builder) 106 frontends.append(builder)
107 107
108 for backend in settings['backends']: 108 for backend in settings['backends']:
109 assembleBackend(backend, frontends, settings['versions']) 109 assembleBackend(backend, frontends, settings['versions'])
110 110
111#-------------------------------------------------------------------- 111#--------------------------------------------------------------------
112 112
113def clean (): 113def clean ():
114 # print "cleaning up …" 114 # print "cleaning up …"
115 if os.path.exists(projectTargetDir()): 115 if os.path.exists(projectTargetDir()):
116 shutil.rmtree(projectTargetDir()) 116 shutil.rmtree(projectTargetDir())
117 117
118#-------------------------------------------------------------------- 118#--------------------------------------------------------------------
119 119
120def usage (message): 120def usage (message):
121 if message != None: 121 if message != None:
122 print "ERROR: " + message 122 print "ERROR: " + message
123 123
124 print 124 print
125 # print "build clean" 125 # print "build clean"
126 # print "build clean install" 126 # print "build clean install"
127 print "build install --ALL" 127 print "build install --ALL"
128 print "build install debug --ALL" 128 print "build install debug --ALL"
129 print "build install debug development --ALL" 129 print "build install debug development --ALL"
130 # print "build clean install debug --ALL" 130 # print "build clean install debug --ALL"
131 print "build install debug --backends php python --frontends beta gamma" 131 print "build install debug --backends php python --frontends beta gamma"
132 print "build install debug development --backends php python --frontends beta gamma gamma.mobile" 132 print "build install debug development --backends php python --frontends beta gamma gamma.mobile"
133 exit(1) 133 exit(1)
134 134
135#-------------------------------------------------------------------- 135#--------------------------------------------------------------------
136 136
137def allFrontends (): 137def allFrontends ():
138 return ['beta', 'gamma', 'gamma.mobile'] 138 return ['beta', 'gamma', 'gamma.mobile']
139 139
140def allBackends (): 140def allBackends ():
141 return ['php', 'python'] 141 return ['php', 'python']
142 142
143#-------------------------------------------------------------------- 143#--------------------------------------------------------------------
144 144
145def main (): 145def main ():
146 settings = {} 146 settings = {}
147 parameters = list(itertools.islice(sys.argv, 1, None)) 147 parameters = list(itertools.islice(sys.argv, 1, None))
148 148
149 sys.path.append(os.path.join(scriptDir(), 'backends')) 149 sys.path.append(os.path.join(scriptDir(), 'backends'))
150 sys.path.append(os.path.join(scriptDir(), 'frontends')) 150 sys.path.append(os.path.join(scriptDir(), 'frontends'))
151 currentRepository = repository.repositoryWithPath(projectBaseDir()) 151 currentRepository = repository.repositoryWithPath(projectBaseDir())
152 152
153 settings['forcedirty'] = len(parameters)
154 parameters = list(itertools.ifilter(lambda x: not x=='--force-dirty', parameters))
155 settings['forcedirty'] = len(parameters)==settings['forcedirty']
153 clean() 156 clean()
154 versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) 157 versions = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
155 settings['versions'] = versions; #['debug', 'install', 'development', 'checksum'] 158 settings['versions'] = versions; #['debug', 'install', 'development', 'checksum']
156 parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) 159 parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
157 160
158 if len(parameters) > 0: 161 if len(parameters) > 0:
159 parameter = parameters.popleft() 162 parameter = parameters.popleft()
160 if parameter == "--ALL": 163 if parameter == "--ALL":
161 settings['frontends'] = allFrontends() 164 settings['frontends'] = allFrontends()
162 settings['backends'] = allBackends() 165 settings['backends'] = allBackends()
163 else: 166 else:
164 while parameter != None: 167 while parameter != None:
165 values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters)) 168 values = list(itertools.takewhile(lambda x: not x.startswith('--'), parameters))
166 169
167 if parameter == "--backends": 170 if parameter == "--backends":
168 settings['backends'] = values 171 settings['backends'] = values
169 elif parameter == "--frontends": 172 elif parameter == "--frontends":
170 settings['frontends'] = values 173 settings['frontends'] = values
171 174
172 parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters)) 175 parameters = deque(itertools.dropwhile(lambda x: not x.startswith('--'), parameters))
173 if parameters: 176 if parameters:
174 parameter = parameters.popleft() 177 parameter = parameters.popleft()
175 else: 178 else:
176 parameter = None 179 parameter = None
177 180
178 if 'checksum' in settings['versions']: 181 if 'checksum' in settings['versions']:
179 if not 'backends' in settings: 182 if not 'backends' in settings:
180 settings['backends'] = [] 183 settings['backends'] = []
181 settings['backends'].append('checksum') 184 settings['backends'].append('checksum')
182 185
183 if (not settings.has_key('versions')): 186 if (not settings.has_key('versions')):
184 usage("missing 'versions'") 187 usage("missing 'versions'")
185 if (not settings.has_key('frontends')): 188 if (not settings.has_key('frontends')):
186 usage("missing 'frontends'") 189 usage("missing 'frontends'")
187 if (not settings.has_key('backends')): 190 if (not settings.has_key('backends')):
188 usage("missing 'backends'") 191 usage("missing 'backends'")
189 192
190 build(settings, currentRepository) 193 build(settings, currentRepository)
191 else: 194 else:
192 usage("Suggestions on how to call the 'build' script:") 195 usage("Suggestions on how to call the 'build' script:")
193 196
194 197
195if __name__ == "__main__": 198if __name__ == "__main__":
196 main() 199 main()