| 
									
										
										
										
											2020-04-21 10:07:29 +09:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 21:19:41 -06:00
										 |  |  | here="$(dirname "$0")" | 
					
						
							|  |  |  | cargo="$(readlink -f "${here}/../cargo")" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 10:07:29 +09:00
										 |  |  | set -e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | shifted_args=() | 
					
						
							|  |  |  | while [[ -n $1 ]]; do | 
					
						
							|  |  |  |   if [[ $1 = -- ]]; then | 
					
						
							|  |  |  |     escape_marker=found | 
					
						
							|  |  |  |     shift | 
					
						
							|  |  |  |     break | 
					
						
							| 
									
										
										
										
											2020-07-03 18:08:12 +09:00
										 |  |  |   elif [[ $1 = "--ignore-exit-code" ]]; then | 
					
						
							|  |  |  |     ignore=1 | 
					
						
							|  |  |  |     shift | 
					
						
							| 
									
										
										
										
											2020-04-21 10:07:29 +09:00
										 |  |  |   else | 
					
						
							|  |  |  |     shifted_args+=("$1") | 
					
						
							|  |  |  |     shift | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # When "--" appear at the first and shifted_args is empty, consume it here | 
					
						
							|  |  |  | # to unambiguously pass and use any other "--" for cargo | 
					
						
							|  |  |  | if [[ -n $escape_marker && ${#shifted_args[@]} -gt 0 ]]; then | 
					
						
							|  |  |  |   files="${shifted_args[*]}" | 
					
						
							|  |  |  |   for file in $files; do | 
					
						
							|  |  |  |     if [[ $file = "${file%Cargo.lock}" ]]; then | 
					
						
							|  |  |  |       echo "$0: unrecognizable as Cargo.lock path (prepend \"--\"?): $file" >&2 | 
					
						
							|  |  |  |       exit 1 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   done | 
					
						
							|  |  |  |   shifted_args=() | 
					
						
							|  |  |  | else | 
					
						
							| 
									
										
										
										
											2020-05-01 17:12:51 -07:00
										 |  |  |   files="$(git ls-files :**Cargo.lock)" | 
					
						
							| 
									
										
										
										
											2020-04-21 10:07:29 +09:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for lock_file in $files; do | 
					
						
							| 
									
										
										
										
											2020-06-09 12:25:39 +09:00
										 |  |  |   if [[ -n $CI ]]; then | 
					
						
							|  |  |  |     echo "--- [$lock_file]: cargo " "${shifted_args[@]}" "$@" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2020-07-03 18:08:12 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 21:19:41 -06:00
										 |  |  |   if (set -x && cd "$(dirname "$lock_file")" && "$cargo" "${shifted_args[@]}" "$@"); then | 
					
						
							| 
									
										
										
										
											2020-07-03 18:08:12 +09:00
										 |  |  |     # noop | 
					
						
							|  |  |  |     true | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     failed_exit_code=$? | 
					
						
							|  |  |  |     if [[ -n $ignore ]]; then | 
					
						
							|  |  |  |       echo "$0: WARN: ignoring last cargo command failed exit code as requested:" $failed_exit_code | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       exit $failed_exit_code | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2020-04-21 10:07:29 +09:00
										 |  |  | done |