| 
									
										
										
										
											2022-01-06 03:57:48 +08:00
										 |  |  | load("@rules_erlang//:erlang_home.bzl", "ErlangVersionProvider") | 
					
						
							| 
									
										
										
										
											2021-09-08 18:01:38 +08:00
										 |  |  | load(":rabbitmq_home.bzl", "RabbitmqHomeInfo", "rabbitmq_home_short_path") | 
					
						
							| 
									
										
										
										
											2021-03-29 17:01:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def _impl(ctx): | 
					
						
							|  |  |  |     erlang_version = ctx.attr._erlang_version[ErlangVersionProvider].version | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 18:01:38 +08:00
										 |  |  |     rabbitmq_home_path = rabbitmq_home_short_path(ctx.attr.home) | 
					
						
							| 
									
										
										
										
											2021-03-29 17:01:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     script = """
 | 
					
						
							| 
									
										
										
										
											2021-05-26 21:40:20 +08:00
										 |  |  |     exec ./{home}/sbin/{cmd} $@ | 
					
						
							|  |  |  |     """.format(
 | 
					
						
							| 
									
										
										
										
											2021-09-08 18:01:38 +08:00
										 |  |  |         home = rabbitmq_home_path, | 
					
						
							| 
									
										
										
										
											2021-05-26 21:40:20 +08:00
										 |  |  |         cmd = ctx.label.name, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2021-03-29 17:01:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ctx.actions.write( | 
					
						
							|  |  |  |         output = ctx.outputs.executable, | 
					
						
							|  |  |  |         content = script, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return [DefaultInfo( | 
					
						
							|  |  |  |         runfiles = ctx.runfiles(ctx.attr.home[DefaultInfo].files.to_list()), | 
					
						
							|  |  |  |     )] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | rabbitmqctl = rule( | 
					
						
							|  |  |  |     implementation = _impl, | 
					
						
							|  |  |  |     attrs = { | 
					
						
							| 
									
										
										
										
											2022-01-06 03:57:48 +08:00
										 |  |  |         "_erlang_version": attr.label(default = Label("@rules_erlang//:erlang_version")), | 
					
						
							| 
									
										
										
										
											2021-03-29 17:01:43 +08:00
										 |  |  |         "home": attr.label(providers = [RabbitmqHomeInfo]), | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     executable = True, | 
					
						
							|  |  |  | ) |