forked from mirrors/gecko-dev
		
	Bug 1798283 - Add a subcommand cargo clippy to mach. r=glandium
Depends on D160749 Differential Revision: https://phabricator.services.mozilla.com/D160750
This commit is contained in:
		
							parent
							
								
									0b504d3991
								
							
						
					
					
						commit
						5a01512e0f
					
				
					 2 changed files with 134 additions and 0 deletions
				
			
		|  | @ -329,6 +329,9 @@ $(call RUN_CARGO,udeps) | ||||||
| endef | endef | ||||||
| endif | endif | ||||||
| 
 | 
 | ||||||
|  | define CARGO_CLIPPY | ||||||
|  | $(call RUN_CARGO,clippy) | ||||||
|  | endef | ||||||
| define CARGO_AUDIT | define CARGO_AUDIT | ||||||
| $(call RUN_CARGO,audit) | $(call RUN_CARGO,audit) | ||||||
| endef | endef | ||||||
|  | @ -466,6 +469,9 @@ endif | ||||||
| force-cargo-library-check: | force-cargo-library-check: | ||||||
| 	$(call CARGO_CHECK) --lib $(cargo_target_flag) $(rust_features_flag) | 	$(call CARGO_CHECK) --lib $(cargo_target_flag) $(rust_features_flag) | ||||||
| 
 | 
 | ||||||
|  | force-cargo-library-clippy: | ||||||
|  | 	$(call CARGO_CLIPPY) --lib $(cargo_target_flag) $(rust_features_flag) | ||||||
|  | 
 | ||||||
| force-cargo-library-audit: | force-cargo-library-audit: | ||||||
| 	$(call CARGO_AUDIT) | 	$(call CARGO_AUDIT) | ||||||
| 
 | 
 | ||||||
|  | @ -476,6 +482,8 @@ force-cargo-library-check: | ||||||
| 	@true | 	@true | ||||||
| force-cargo-library-udeps: | force-cargo-library-udeps: | ||||||
| 	@true | 	@true | ||||||
|  | force-cargo-library-clippy: | ||||||
|  | 	@true | ||||||
| force-cargo-library-audit: | force-cargo-library-audit: | ||||||
| 	@true | 	@true | ||||||
| endif # RUST_LIBRARY_FILE
 | endif # RUST_LIBRARY_FILE
 | ||||||
|  | @ -511,6 +519,9 @@ $(HOST_RUST_LIBRARY_FILE): force-cargo-host-library-build ; | ||||||
| force-cargo-host-library-check: | force-cargo-host-library-check: | ||||||
| 	$(call CARGO_CHECK) --lib $(cargo_host_flag) $(host_rust_features_flag) | 	$(call CARGO_CHECK) --lib $(cargo_host_flag) $(host_rust_features_flag) | ||||||
| 
 | 
 | ||||||
|  | force-cargo-host-library-clippy: | ||||||
|  | 	$(call CARGO_CLIPPY) --lib $(cargo_host_flag) $(host_rust_features_flag) | ||||||
|  | 
 | ||||||
| force-cargo-host-library-audit: | force-cargo-host-library-audit: | ||||||
| 	$(call CARGO_AUDIT) --lib $(filter-out --release $(cargo_target_flag)) $(host_rust_features_flag) | 	$(call CARGO_AUDIT) --lib $(filter-out --release $(cargo_target_flag)) $(host_rust_features_flag) | ||||||
| 
 | 
 | ||||||
|  | @ -519,6 +530,8 @@ force-cargo-host-library-udeps: | ||||||
| else | else | ||||||
| force-cargo-host-library-check: | force-cargo-host-library-check: | ||||||
| 	@true | 	@true | ||||||
|  | force-cargo-host-library-clippy: | ||||||
|  | 	@true | ||||||
| force-cargo-host-library-audit: | force-cargo-host-library-audit: | ||||||
| 	@true | 	@true | ||||||
| force-cargo-host-library-udeps: | force-cargo-host-library-udeps: | ||||||
|  | @ -535,6 +548,10 @@ $(RUST_PROGRAMS): force-cargo-program-build ; | ||||||
| 
 | 
 | ||||||
| force-cargo-program-check: | force-cargo-program-check: | ||||||
| 	$(call CARGO_CHECK) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag) | 	$(call CARGO_CHECK) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag) | ||||||
|  | 
 | ||||||
|  | force-cargo-program-clippy: | ||||||
|  | 	$(call CARGO_CLIPPY) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(cargo_target_flag) | ||||||
|  | 
 | ||||||
| force-cargo-program-audit: | force-cargo-program-audit: | ||||||
| 	$(call CARGO_AUDIT) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(filter-out --release $(cargo_target_flag)) | 	$(call CARGO_AUDIT) $(addprefix --bin ,$(RUST_CARGO_PROGRAMS)) $(filter-out --release $(cargo_target_flag)) | ||||||
| 
 | 
 | ||||||
|  | @ -543,6 +560,8 @@ force-cargo-program-udeps: | ||||||
| else | else | ||||||
| force-cargo-program-check: | force-cargo-program-check: | ||||||
| 	@true | 	@true | ||||||
|  | force-cargo-program-clippy: | ||||||
|  | 	@true | ||||||
| force-cargo-program-audit: | force-cargo-program-audit: | ||||||
| 	@true | 	@true | ||||||
| force-cargo-program-udeps: | force-cargo-program-udeps: | ||||||
|  | @ -559,6 +578,11 @@ $(HOST_RUST_PROGRAMS): force-cargo-host-program-build ; | ||||||
| force-cargo-host-program-check: | force-cargo-host-program-check: | ||||||
| 	$(REPORT_BUILD) | 	$(REPORT_BUILD) | ||||||
| 	$(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag) | 	$(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag) | ||||||
|  | 
 | ||||||
|  | force-cargo-host-program-clippy: | ||||||
|  | 	$(REPORT_BUILD) | ||||||
|  | 	$(call CARGO_CLIPPY) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(cargo_host_flag) | ||||||
|  | 
 | ||||||
| force-cargo-host-program-audit: | force-cargo-host-program-audit: | ||||||
| 	$(REPORT_BUILD) | 	$(REPORT_BUILD) | ||||||
| 	$(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(filter-out --release $(cargo_target_flag)) | 	$(call CARGO_CHECK) $(addprefix --bin ,$(HOST_RUST_CARGO_PROGRAMS)) $(filter-out --release $(cargo_target_flag)) | ||||||
|  | @ -569,6 +593,8 @@ force-cargo-host-program-udeps: | ||||||
| else | else | ||||||
| force-cargo-host-program-check: | force-cargo-host-program-check: | ||||||
| 	@true | 	@true | ||||||
|  | force-cargo-host-program-clippy: | ||||||
|  | 	@true | ||||||
| force-cargo-host-program-audit: | force-cargo-host-program-audit: | ||||||
| 	@true | 	@true | ||||||
| force-cargo-host-program-udeps: | force-cargo-host-program-udeps: | ||||||
|  |  | ||||||
|  | @ -386,6 +386,114 @@ def cargo_vet(command_context, arguments, stdout=None, env=os.environ): | ||||||
|     return res if stdout else res.returncode |     return res if stdout else res.returncode | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @SubCommand( | ||||||
|  |     "cargo", | ||||||
|  |     "clippy", | ||||||
|  |     description="Run `cargo clippy` on a given crate.  Defaults to gkrust.", | ||||||
|  |     metrics_path=MOZBUILD_METRICS_PATH, | ||||||
|  | ) | ||||||
|  | @CommandArgument( | ||||||
|  |     "--all-crates", | ||||||
|  |     default=None, | ||||||
|  |     action="store_true", | ||||||
|  |     help="Check all of the crates in the tree.", | ||||||
|  | ) | ||||||
|  | @CommandArgument("crates", default=None, nargs="*", help="The crate name(s) to check.") | ||||||
|  | @CommandArgument( | ||||||
|  |     "--jobs", | ||||||
|  |     "-j", | ||||||
|  |     default="1", | ||||||
|  |     nargs="?", | ||||||
|  |     metavar="jobs", | ||||||
|  |     type=int, | ||||||
|  |     help="Run the tests in parallel using multiple processes.", | ||||||
|  | ) | ||||||
|  | @CommandArgument("-v", "--verbose", action="store_true", help="Verbose output.") | ||||||
|  | @CommandArgument( | ||||||
|  |     "--message-format-json", | ||||||
|  |     action="store_true", | ||||||
|  |     help="Emit error messages as JSON.", | ||||||
|  | ) | ||||||
|  | def clippy( | ||||||
|  |     command_context, | ||||||
|  |     all_crates=None, | ||||||
|  |     crates=None, | ||||||
|  |     jobs=0, | ||||||
|  |     verbose=False, | ||||||
|  |     message_format_json=False, | ||||||
|  | ): | ||||||
|  |     from mozbuild.controller.building import BuildDriver | ||||||
|  | 
 | ||||||
|  |     command_context.log_manager.enable_all_structured_loggers() | ||||||
|  | 
 | ||||||
|  |     try: | ||||||
|  |         command_context.config_environment | ||||||
|  |     except BuildEnvironmentNotFoundException: | ||||||
|  |         build = command_context._spawn(BuildDriver) | ||||||
|  |         ret = build.build( | ||||||
|  |             command_context.metrics, | ||||||
|  |             what=["pre-export", "export"], | ||||||
|  |             jobs=jobs, | ||||||
|  |             verbose=verbose, | ||||||
|  |             mach_context=command_context._mach_context, | ||||||
|  |         ) | ||||||
|  |         if ret != 0: | ||||||
|  |             return ret | ||||||
|  |     # XXX duplication with `mach vendor rust` | ||||||
|  |     crates_and_roots = { | ||||||
|  |         "gkrust": "toolkit/library/rust", | ||||||
|  |         "gkrust-gtest": "toolkit/library/gtest/rust", | ||||||
|  |         "geckodriver": "testing/geckodriver", | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if all_crates: | ||||||
|  |         crates = crates_and_roots.keys() | ||||||
|  |     elif crates is None or crates == []: | ||||||
|  |         crates = ["gkrust"] | ||||||
|  | 
 | ||||||
|  |     final_ret = 0 | ||||||
|  | 
 | ||||||
|  |     for crate in crates: | ||||||
|  |         root = crates_and_roots.get(crate, None) | ||||||
|  |         if not root: | ||||||
|  |             print( | ||||||
|  |                 "Cannot locate crate %s.  Please check your spelling or " | ||||||
|  |                 "add the crate information to the list." % crate | ||||||
|  |             ) | ||||||
|  |             return 1 | ||||||
|  | 
 | ||||||
|  |         check_targets = [ | ||||||
|  |             "force-cargo-library-clippy", | ||||||
|  |             "force-cargo-host-library-clippy", | ||||||
|  |             "force-cargo-program-clippy", | ||||||
|  |             "force-cargo-host-program-clippy", | ||||||
|  |         ] | ||||||
|  | 
 | ||||||
|  |         append_env = {} | ||||||
|  |         if message_format_json: | ||||||
|  |             append_env["USE_CARGO_JSON_MESSAGE_FORMAT"] = "1" | ||||||
|  | 
 | ||||||
|  |         ret = 2 | ||||||
|  | 
 | ||||||
|  |         try: | ||||||
|  |             ret = command_context._run_make( | ||||||
|  |                 srcdir=False, | ||||||
|  |                 directory=root, | ||||||
|  |                 ensure_exit_code=0, | ||||||
|  |                 silent=not verbose, | ||||||
|  |                 print_directory=False, | ||||||
|  |                 target=check_targets, | ||||||
|  |                 num_jobs=jobs, | ||||||
|  |                 append_env=append_env, | ||||||
|  |             ) | ||||||
|  |         except Exception as e: | ||||||
|  |             print("%s" % e) | ||||||
|  |         if ret != 0: | ||||||
|  |             final_ret = ret | ||||||
|  | 
 | ||||||
|  |     return final_ret | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @SubCommand( | @SubCommand( | ||||||
|     "cargo", |     "cargo", | ||||||
|     "audit", |     "audit", | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Arthur Carcano
						Arthur Carcano