Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: utils/compile_gwt_clients.py

Issue 1595019: Merge remote branch 'origin/upstream' into tempbranch (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « utils/build_externals.py ('k') | utils/unittest_suite.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 import common 2 import common
3 import sys, os, shutil, errno, optparse, logging 3 import sys, os, shutil, errno, optparse, logging
4 from autotest_lib.client.common_lib import error, utils 4 from autotest_lib.client.common_lib import error, utils
5 from autotest_lib.client.common_lib import logging_config, logging_manager
5 """ 6 """
6 Compile All Autotest GWT Clients Living in autotest/frontend/client/src 7 Compile All Autotest GWT Clients Living in autotest/frontend/client/src
7 """ 8 """
8 9
9
10 logging.basicConfig(level=logging.DEBUG)
11 _AUTOTEST_DIR = common.autotest_dir 10 _AUTOTEST_DIR = common.autotest_dir
12 _DEFAULT_GWT_DIR = '/usr/local/lib/gwt' 11 _DEFAULT_GWT_DIR = '/usr/local/lib/gwt'
13 _DEFAULT_APP_DIR = os.path.join(_AUTOTEST_DIR, 'frontend/client') 12 _DEFAULT_APP_DIR = os.path.join(_AUTOTEST_DIR, 'frontend/client')
14 _DEFAULT_INSTALL_DIR = os.path.join(_DEFAULT_APP_DIR, 'www') 13 _DEFAULT_INSTALL_DIR = os.path.join(_DEFAULT_APP_DIR, 'www')
15 _TMP_COMPILE_DIR = _DEFAULT_INSTALL_DIR + '.new' 14 _TMP_COMPILE_DIR = _DEFAULT_INSTALL_DIR + '.new'
16 15
17 _COMPILE_LINE = ('java -Xmx512M ' 16 _COMPILE_LINE = ('java -Xmx512M '
18 '-cp "%(app_dir)s/src:%(app_dir)s/bin:%(gwt_dir)s/gwt-user.jar' 17 '-cp "%(app_dir)s/src:%(app_dir)s/bin:%(gwt_dir)s/gwt-user.jar'
19 ':%(gwt_dir)s/gwt-dev-linux.jar" ' 18 ':%(gwt_dir)s/gwt-dev-linux.jar" '
20 '-Djava.awt.headless=true com.google.gwt.dev.Compiler ' 19 '-Djava.awt.headless=true com.google.gwt.dev.Compiler '
21 '-war "%(compile_dir)s" %(extra_args)s %(project_client)s') 20 '-war "%(compile_dir)s" %(extra_args)s %(project_client)s')
22 21
22 class CompileClientsLoggingConfig(logging_config.LoggingConfig):
23 def configure_logging(self, results_dir=None, verbose=False):
24 super(CompileClientsLoggingConfig, self).configure_logging(
25 use_console=True,
26 verbose=verbose)
23 27
24 def enumerate_projects(): 28 def enumerate_projects():
25 """List projects in _DEFAULT_APP_DIR.""" 29 """List projects in _DEFAULT_APP_DIR."""
26 src_path = os.path.join(_DEFAULT_APP_DIR, 'src') 30 src_path = os.path.join(_DEFAULT_APP_DIR, 'src')
27 projects = {} 31 projects = {}
28 for project in os.listdir(src_path): 32 for project in os.listdir(src_path):
29 projects[project] = [] 33 projects[project] = []
30 project_path = os.path.join(src_path, project) 34 project_path = os.path.join(src_path, project)
31 for file in os.listdir(project_path): 35 for file in os.listdir(project_path):
32 if file.endswith('.gwt.xml'): 36 if file.endswith('.gwt.xml'):
33 projects[project].append(file[:-8]) 37 projects[project].append(file[:-8])
34 return projects 38 return projects
35 39
36 40
37 def find_gwt_dir(): 41 def find_gwt_dir():
38 """See if GWT is installed in site-packages or in the system, 42 """See if GWT is installed in site-packages or in the system,
39 site-packages is favored over a system install. 43 site-packages is favored over a system install.
40 """ 44 """
41 site_gwt = os.path.join(_AUTOTEST_DIR, 'site-packages', 'gwt') 45 site_gwt = os.path.join(_AUTOTEST_DIR, 'site-packages', 'gwt')
42 46
43 if os.path.isdir(site_gwt): 47 if os.path.isdir(site_gwt):
44 return site_gwt 48 return site_gwt
45 49
46 if not os.path.isdir(_DEFAULT_GWT_DIR): 50 if not os.path.isdir(_DEFAULT_GWT_DIR):
47 print 'Error: Unable to find GWT, is GWT installed?\n' 51 logging.error('Unable to find GWT. '
52 'You can use utils/build_externals.py to install it.')
48 sys.exit(1) 53 sys.exit(1)
49 54
50 return _DEFAULT_GWT_DIR 55 return _DEFAULT_GWT_DIR
51 56
52 57
53 def install_completed_client(compiled_dir, project_client): 58 def install_completed_client(compiled_dir, project_client):
54 """Remove old client directory if it exists, move installed client to the 59 """Remove old client directory if it exists, move installed client to the
55 old directory and move newly compield client to the installed client 60 old directory and move newly compield client to the installed client
56 dir. 61 dir.
57 @param compiled_dir: Where the new client was compiled 62 @param compiled_dir: Where the new client was compiled
(...skipping 13 matching lines...) Expand all
71 if os.path.isdir(install_dir): 76 if os.path.isdir(install_dir):
72 os.rename(install_dir, old_install_dir) 77 os.rename(install_dir, old_install_dir)
73 try: 78 try:
74 os.rename(tmp_client_dir, install_dir) 79 os.rename(tmp_client_dir, install_dir)
75 return True 80 return True
76 except Exception, err: 81 except Exception, err:
77 # If we can't rename the client raise an exception 82 # If we can't rename the client raise an exception
78 # and put the old client back 83 # and put the old client back
79 shutil.rmtree(install_dir) 84 shutil.rmtree(install_dir)
80 shutil.copytree(old_install_dir, install_dir) 85 shutil.copytree(old_install_dir, install_dir)
81 print 'Error: copying old client:', err 86 logging.error('Copying old client: %s', err)
82 else: 87 else:
83 print 'Error: Compiled directory is gone, something went wrong' 88 logging.error('Compiled directory is gone, something went wrong')
84 89
85 return False 90 return False
86 91
87 92
88 def compile_and_install_client(project_client, extra_args='', 93 def compile_and_install_client(project_client, extra_args='',
89 install_client=True): 94 install_client=True):
90 """Compile the client into a temporary directory, if successful 95 """Compile the client into a temporary directory, if successful
91 call install_completed_client to install the new client. 96 call install_completed_client to install the new client.
92 @param project_client: project.client pair e.g. autotest.AfeClient 97 @param project_client: project.client pair e.g. autotest.AfeClient
93 @param install_client: Boolean, if True install the clients 98 @param install_client: Boolean, if True install the clients
94 @return True if install and compile was successful False if it failed 99 @return True if install and compile was successful False if it failed
95 """ 100 """
96 java_args = {} 101 java_args = {}
97 java_args['compile_dir'] = _TMP_COMPILE_DIR 102 java_args['compile_dir'] = _TMP_COMPILE_DIR
98 java_args['app_dir'] = _DEFAULT_APP_DIR 103 java_args['app_dir'] = _DEFAULT_APP_DIR
99 java_args['gwt_dir'] = find_gwt_dir() 104 java_args['gwt_dir'] = find_gwt_dir()
100 java_args['extra_args'] = extra_args 105 java_args['extra_args'] = extra_args
101 java_args['project_client'] = project_client 106 java_args['project_client'] = project_client
102 cmd = _COMPILE_LINE % java_args 107 cmd = _COMPILE_LINE % java_args
103 108
104 print 'Compiling client %s' % project_client 109 logging.info('Compiling client %s', project_client)
105 try: 110 try:
106 utils.run(cmd, verbose=True) 111 utils.run(cmd, verbose=True)
107 if install_client: 112 if install_client:
108 return install_completed_client(java_args['compile_dir'], 113 return install_completed_client(java_args['compile_dir'],
109 project_client) 114 project_client)
110 return True 115 return True
111 except error.CmdError: 116 except error.CmdError:
112 print 'Error compiling %s, leaving old client' % project_client 117 logging.info('Error compiling %s, leaving old client', project_client)
113 118
114 return False 119 return False
115 120
116 121
117 def compile_all_projects(projects, extra_args=''): 122 def compile_all_projects(projects, extra_args=''):
118 """Compile all projects available as defined by enumerate_projects. 123 """Compile all projects available as defined by enumerate_projects.
119 @returns list of failed client installations 124 @returns list of failed client installations
120 """ 125 """
121 failed_clients = [] 126 failed_clients = []
122 for project,clients in enumerate_projects().iteritems(): 127 for project,clients in enumerate_projects().iteritems():
123 for client in clients: 128 for client in clients:
124 project_client = '%s.%s' % (project, client) 129 project_client = '%s.%s' % (project, client)
125 if not compile_and_install_client(project_client, extra_args): 130 if not compile_and_install_client(project_client, extra_args):
126 failed_clients.append(project_client) 131 failed_clients.append(project_client)
127 132
128 return failed_clients 133 return failed_clients
129 134
130 135
131 def print_projects(): 136 def print_projects():
132 print 'Projects that can be compiled:' 137 logging.info('Projects that can be compiled:')
133 for project,clients in enumerate_projects().iteritems(): 138 for project,clients in enumerate_projects().iteritems():
134 for client in clients: 139 for client in clients:
135 print '%s.%s' % (project, client) 140 logging.info('%s.%s', project, client)
136 141
137 142
138 def main(): 143 def main():
144 logging_manager.configure_logging(CompileClientsLoggingConfig(),
145 verbose=True)
139 parser = optparse.OptionParser() 146 parser = optparse.OptionParser()
140 parser.add_option('-l', '--list-projects', 147 parser.add_option('-l', '--list-projects',
141 action='store_true', dest='list_projects', 148 action='store_true', dest='list_projects',
142 default=False, 149 default=False,
143 help='List all projects and clients that can be compiled') 150 help='List all projects and clients that can be compiled')
144 parser.add_option('-a', '--compile-all', 151 parser.add_option('-a', '--compile-all',
145 action='store_true', dest='compile_all', 152 action='store_true', dest='compile_all',
146 default=False, 153 default=False,
147 help='Compile all available projects and clients') 154 help='Compile all available projects and clients')
148 parser.add_option('-c', '--compile', 155 parser.add_option('-c', '--compile',
149 dest='compile_list', action='store', 156 dest='compile_list', action='store',
150 help='List of clients to compiled (e.g. -c "x.X c.C")') 157 help='List of clients to compiled (e.g. -c "x.X c.C")')
151 parser.add_option('-e', '--extra-args', 158 parser.add_option('-e', '--extra-args',
152 dest='extra_args', action='store', 159 dest='extra_args', action='store',
153 default='', 160 default='',
154 help='Extra arguments to pass to java') 161 help='Extra arguments to pass to java')
155 parser.add_option('-d', '--no-install', dest='install_client', 162 parser.add_option('-d', '--no-install', dest='install_client',
156 action='store_false', default=True, 163 action='store_false', default=True,
157 help='Do not install the clients just compile them') 164 help='Do not install the clients just compile them')
158 options, args = parser.parse_args() 165 options, args = parser.parse_args()
159 166
160 if len(sys.argv) < 2: 167 if len(sys.argv) < 2:
161 parser.print_help() 168 parser.print_help()
162 sys.exit(0) 169 sys.exit(0)
163 elif options.list_projects: 170 elif options.list_projects:
164 print_projects() 171 print_projects()
165 sys.exit(0) 172 sys.exit(0)
166 elif options.compile_all and options.compile_list: 173 elif options.compile_all and options.compile_list:
167 print '-c and -a are mutually exclusive' 174 logging.error('Options -c and -a are mutually exclusive')
168 parser.print_help() 175 parser.print_help()
169 sys.exit(1) 176 sys.exit(1)
170 177
171 failed_clients = [] 178 failed_clients = []
172 if options.compile_all: 179 if options.compile_all:
173 failed_clients = compile_all_projects(options.extra_args) 180 failed_clients = compile_all_projects(options.extra_args)
174 elif options.compile_list: 181 elif options.compile_list:
175 for client in options.compile_list.split(): 182 for client in options.compile_list.split():
176 if not compile_and_install_client(client, options.extra_args, 183 if not compile_and_install_client(client, options.extra_args,
177 options.install_client): 184 options.install_client):
178 failed_clients.append(client) 185 failed_clients.append(client)
179 186
180 if os.path.exists(_TMP_COMPILE_DIR): 187 if os.path.exists(_TMP_COMPILE_DIR):
181 shutil.rmtree(_TMP_COMPILE_DIR) 188 shutil.rmtree(_TMP_COMPILE_DIR)
182 189
183 if failed_clients: 190 if failed_clients:
184 print ('Error: The following clients failed: %s' 191 logging.error('The following clients failed: %s',
185 % '\n'.join(failed_clients)) 192 '\n'.join(failed_clients))
186 sys.exit(1) 193 sys.exit(1)
187 194
188 195
189 if __name__ == '__main__': 196 if __name__ == '__main__':
190 main() 197 main()
OLDNEW
« no previous file with comments | « utils/build_externals.py ('k') | utils/unittest_suite.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698