| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | # Copyright 2012 Google Inc. All Rights Reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """Builds a set of target rules.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Examples: | 
					
						
							|  |  |  | # Build the given rules | 
					
						
							| 
									
										
										
										
											2012-04-11 10:58:07 +08:00
										 |  |  | anvil build :some_rule some/path:another_rule | 
					
						
							|  |  |  | # Force a full rebuild (essentially a 'anvil clean') | 
					
						
							|  |  |  | anvil build --rebuild :some_rule | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | __author__ = 'benvanik@google.com (Ben Vanik)' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import anvil.commands.util as commandutil | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  | from anvil.manage import ManageCommand | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  | class BuildCommand(ManageCommand): | 
					
						
							|  |  |  |   def __init__(self): | 
					
						
							|  |  |  |     super(BuildCommand, self).__init__( | 
					
						
							|  |  |  |         name='build', | 
					
						
							|  |  |  |         help_short='Builds target rules.', | 
					
						
							|  |  |  |         help_long=__doc__) | 
					
						
							| 
									
										
										
										
											2012-04-12 06:57:23 +08:00
										 |  |  |     self._add_common_build_hints() | 
					
						
							|  |  |  |     self.completion_hints.extend([ | 
					
						
							|  |  |  |         '--rebuild', | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |   def create_argument_parser(self): | 
					
						
							|  |  |  |     parser = super(BuildCommand, self).create_argument_parser() | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |     # Add all common args | 
					
						
							|  |  |  |     self._add_common_build_arguments(parser, targets=True) | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |     # 'build' specific | 
					
						
							|  |  |  |     parser.add_argument('--rebuild', | 
					
						
							|  |  |  |                         dest='rebuild', | 
					
						
							|  |  |  |                         action='store_true', | 
					
						
							|  |  |  |                         default=False, | 
					
						
							|  |  |  |                         help=('Cleans all output and caches before building.')) | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |     return parser | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |   def execute(self, args, cwd): | 
					
						
							|  |  |  |     # Handle --rebuild | 
					
						
							|  |  |  |     if args.rebuild: | 
					
						
							|  |  |  |       if not commandutil.clean_output(cwd): | 
					
						
							|  |  |  |         return False | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |     (result, all_target_outputs) = commandutil.run_build(cwd, args) | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-20 06:21:57 +08:00
										 |  |  |     print('result %s, %s outputs' % (result, len(all_target_outputs))) | 
					
						
							| 
									
										
										
										
											2012-06-14 09:04:35 +08:00
										 |  |  |     #print all_target_outputs | 
					
						
							| 
									
										
										
										
											2012-04-10 06:19:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 05:11:34 +08:00
										 |  |  |     return 0 if result else 1 |