@@ -57,7 +57,7 @@ use crate::util::errors::{self, CargoResult, CargoResultExt, ProcessError, Verbo
5757use crate :: util:: interning:: InternedString ;
5858use crate :: util:: machine_message:: Message ;
5959use crate :: util:: { self , machine_message, ProcessBuilder } ;
60- use crate :: util:: { internal, join_paths, paths, profile} ;
60+ use crate :: util:: { add_path_args , internal, join_paths, paths, profile} ;
6161
6262const RUSTDOC_CRATE_VERSION_FLAG : & str = "--crate-version" ;
6363
@@ -582,7 +582,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
582582 let mut rustdoc = cx. compilation . rustdoc_process ( unit, None ) ?;
583583 rustdoc. inherit_jobserver ( & cx. jobserver ) ;
584584 rustdoc. arg ( "--crate-name" ) . arg ( & unit. target . crate_name ( ) ) ;
585- add_path_args ( bcx, unit, & mut rustdoc) ;
585+ add_path_args ( bcx. ws , unit, & mut rustdoc) ;
586586 add_cap_lints ( bcx, unit, & mut rustdoc) ;
587587
588588 if let CompileKind :: Target ( target) = unit. kind {
@@ -662,41 +662,6 @@ fn append_crate_version_flag(unit: &Unit, rustdoc: &mut ProcessBuilder) {
662662 . arg ( unit. pkg . version ( ) . to_string ( ) ) ;
663663}
664664
665- // The path that we pass to rustc is actually fairly important because it will
666- // show up in error messages (important for readability), debug information
667- // (important for caching), etc. As a result we need to be pretty careful how we
668- // actually invoke rustc.
669- //
670- // In general users don't expect `cargo build` to cause rebuilds if you change
671- // directories. That could be if you just change directories in the package or
672- // if you literally move the whole package wholesale to a new directory. As a
673- // result we mostly don't factor in `cwd` to this calculation. Instead we try to
674- // track the workspace as much as possible and we update the current directory
675- // of rustc/rustdoc where appropriate.
676- //
677- // The first returned value here is the argument to pass to rustc, and the
678- // second is the cwd that rustc should operate in.
679- fn path_args ( bcx : & BuildContext < ' _ , ' _ > , unit : & Unit ) -> ( PathBuf , PathBuf ) {
680- let ws_root = bcx. ws . root ( ) ;
681- let src = match unit. target . src_path ( ) {
682- TargetSourcePath :: Path ( path) => path. to_path_buf ( ) ,
683- TargetSourcePath :: Metabuild => unit. pkg . manifest ( ) . metabuild_path ( bcx. ws . target_dir ( ) ) ,
684- } ;
685- assert ! ( src. is_absolute( ) ) ;
686- if unit. pkg . package_id ( ) . source_id ( ) . is_path ( ) {
687- if let Ok ( path) = src. strip_prefix ( ws_root) {
688- return ( path. to_path_buf ( ) , ws_root. to_path_buf ( ) ) ;
689- }
690- }
691- ( src, unit. pkg . root ( ) . to_path_buf ( ) )
692- }
693-
694- fn add_path_args ( bcx : & BuildContext < ' _ , ' _ > , unit : & Unit , cmd : & mut ProcessBuilder ) {
695- let ( arg, cwd) = path_args ( bcx, unit) ;
696- cmd. arg ( arg) ;
697- cmd. cwd ( cwd) ;
698- }
699-
700665fn add_cap_lints ( bcx : & BuildContext < ' _ , ' _ > , unit : & Unit , cmd : & mut ProcessBuilder ) {
701666 // If this is an upstream dep we don't want warnings from, turn off all
702667 // lints.
@@ -786,7 +751,7 @@ fn build_base_args(
786751 cmd. arg ( format ! ( "--edition={}" , edition) ) ;
787752 }
788753
789- add_path_args ( bcx, unit, cmd) ;
754+ add_path_args ( bcx. ws , unit, cmd) ;
790755 add_error_format_and_color ( cx, cmd, cx. rmeta_required ( unit) ) ;
791756
792757 if !test {
0 commit comments