pub fn prepare_build_cmd<'a, 'cfg>(
    cx: &mut Context<'a, 'cfg>,
    unit: &Unit<'a>,
) -> CargoResult<Preparation> {
    let _p = profile::start(format!("fingerprint build cmd: {}", unit.pkg.package_id()));
    let new = cx.files().fingerprint_dir(unit);
    let loc = new.join("build");

    debug!("fingerprint at: {}", loc.display());

    let (local, output_path) = build_script_local_fingerprints(cx, unit)?;
    let mut fingerprint = Fingerprint {
        local,
        rustc: util::hash_u64(&cx.bcx.rustc.verbose_version),
        ..Fingerprint::new()
    };
    let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use;
    let compare = compare_old_fingerprint(&loc, &fingerprint, mtime_on_use);
    log_compare(unit, &compare);

    // When we write out the fingerprint, we may want to actually change the
    // kind of fingerprint being recorded. If we started out, then the previous
    // run of the build script (or if it had never run before) may indicate to
    // use the `Precalculated` variant with the `pkg_fingerprint`. If the build
    // script then prints `rerun-if-changed`, however, we need to record what's
    // necessary for that fingerprint.
    //
    // Hence, if there were some `rerun-if-changed` directives forcibly change
    // the kind of fingerprint by reinterpreting the dependencies output by the
    // build script.
    let state = Arc::clone(&cx.build_state);
    let key = (unit.pkg.package_id(), unit.kind);
    let pkg_root = unit.pkg.root().to_path_buf();
    let target_root = cx.files().target_root().to_path_buf();
    let write_fingerprint = Work::new(move |_| {
        if let Some(output_path) = output_path {
            let outputs = state.outputs.lock().unwrap();
            let outputs = &outputs[&key];
            if !outputs.rerun_if_changed.is_empty() || !outputs.rerun_if_env_changed.is_empty() {
                let deps = BuildDeps::new(&output_path, Some(outputs));
                fingerprint.local = local_fingerprints_deps(&deps, &target_root, &pkg_root);
                fingerprint.update_local(&target_root)?;
            }
        }
        write_fingerprint(&loc, &fingerprint)
    });

    Ok((
        if compare.is_ok() { Fresh } else { Dirty },
        write_fingerprint,
        Work::noop(),
    ))
}
/// Prepare the necessary work for the fingerprint of a build command.
///
/// Build commands are located on packages, not on targets. Additionally, we
/// don't have --dep-info to drive calculation of the fingerprint of a build
/// command. This brings up an interesting predicament which gives us a few
/// options to figure out whether a build command is dirty or not:
///
/// 1. A build command is dirty if *any* file in a package changes. In theory
///    all files are candidate for being used by the build command.
/// 2. A build command is dirty if any file in a *specific directory* changes.
///    This may lose information as it may require files outside of the specific
///    directory.
/// 3. A build command must itself provide a dep-info-like file stating how it
///    should be considered dirty or not.
///
/// The currently implemented solution is option (1), although it is planned to
/// migrate to option (2) in the near future.
Prepare the necessary work for the fingerprint of a build command.
Build commands are located on packages, not on targets. Additionally, we
don't have --dep-info to drive calculation of the fingerprint of a build
command. This brings up an interesting predicament which gives us a few
options to figure out whether a build command is dirty or not.

1. A build command is dirty if *any* file in a package changes. In theory
all files are candidate for being used by the build command.
2. A build command is dirty if any file in a *specific directory* changes.
This may lose information as it may require files outside of the specific
directory.
3. A build command must itself provide a dep-info-like file stating how it
should be considered dirty or not.

The currently implemented solution is option (1), although it is planned to
migrate to option (2) in the near future.
Prepare the necessary work for the fingerprint of a build command . Build commands are located on packages not on targets . Additionally we don ' t have -- dep - info to drive calculation of the fingerprint of a build command . This brings up an interesting predicament which gives us a few options to figure out whether a build command is dirty or not . 1 . A build command is dirty if * any * file in a package changes . In theory all files are candidate for being used by the build command . 2 . A build command is dirty if any file in a * specific directory * changes . This may lose information as it may require files outside of the specific directory . 3 . A build command must itself provide a dep - info - like file stating how it should be considered dirty or not . The currently implemented solution is option ( 1 ) although it is planned to migrate to option ( 2 ) in the near future .
pub fn prepare_build_cmd<'a, 'cfg>(
    cx: &mut Context<'a, 'cfg>,
    unit: &Unit<'a>,
) -> CargoResult<Preparation> {
    let _p = profile::start(format!("fingerprint build cmd: {}", unit.pkg.package_id()));
    let new = cx.files().fingerprint_dir(unit);
    let loc = new.join("build");
    debug!("fingerprint at: {}", loc.display());
    let (local, output_path) = build_script_local_fingerprints(cx, unit)?;
    let mut fingerprint = Fingerprint {
        local,
        rustc: util::hash_u64(&cx.bcx.rustc.verbose_version),
        ..Fingerprint::new()
    };
    let mtime_on_use = cx.bcx.config.cli_unstable().mtime_on_use;
    let compare = compare_old_fingerprint(&loc, &fingerprint, mtime_on_use);
    log_compare(unit, &compare);
    // When we write out the fingerprint, we may want to actually change the
    // kind of fingerprint being recorded. If we started out, then the previous
    // run of the build script (or if it had never run before) may indicate to
    // use the `Precalculated` variant with the `pkg_fingerprint`. If the build
    // script then prints `rerun-if-changed`, however, we need to record what's
    // necessary for that fingerprint.
    //
    // Hence, if there were some `rerun-if-changed` directives forcibly change
    // the kind of fingerprint by reinterpreting the dependencies output by the
    // build script.
    let state = Arc::clone(&cx.build_state);
    let key = (unit.pkg.package_id(), unit.kind);
    let pkg_root = unit.pkg.root().to_path_buf();
    let target_root = cx.files().target_root().to_path_buf();
    let write_fingerprint = Work::new(move |_| {
        if let Some(output_path) = output_path {
            let outputs = state.outputs.lock().unwrap();
            let outputs = &outputs[&key];
            if !outputs.rerun_if_changed.is_empty() || !outputs.rerun_if_env_changed.is_empty() {
                let deps = BuildDeps::new(&output_path, Some(outputs));
                fingerprint.local = local_fingerprints_deps(&deps, &target_root, &pkg_root);
                fingerprint.update_local(&target_root)?;
            }
        }
        write_fingerprint(&loc, &fingerprint)
    });
    Ok((
        if compare.is_ok() { Fresh } else { Dirty },
        write_fingerprint,
        Work::noop(),
    ))
}
pub fn prepare_build_cmd < ' a , ' cfg > ( cx : & mut Context < ' a , ' cfg > , unit : & Unit < ' a > , ) -> CargoResult < Preparation > { let _p = profile :: start ( format ! ( " " unit pkg package_id ( ) ) ) ; let new = cx . files ( ) . fingerprint_dir ( unit ) ; let loc = new . join ( " " ) ; debug ! ( " " loc display ( ) ) ; let ( local , output_path ) = build_script_local_fingerprints ( cx , unit ) ? ; let mut fingerprint = Fingerprint { local , rustc : util :: hash_u64 ( & cx . bcx . rustc . verbose_version ) , .. Fingerprint :: new ( ) } ; let mtime_on_use = cx . bcx . config . cli_unstable ( ) . mtime_on_use ; let compare = compare_old_fingerprint ( & loc , & fingerprint , mtime_on_use ) ; log_compare ( unit , & compare ) ; // When we write out the fingerprint, we may want to actually change the // kind of fingerprint being recorded. If we started out, then the previous // run of the build script (or if it had never run before) may indicate to // use the `Precalculated` variant with the `pkg_fingerprint`. If the build // script then prints `rerun-if-changed`, however, we need to record what's // necessary for that fingerprint. // // Hence, if there were some `rerun-if-changed` directives forcibly change // the kind of fingerprint by reinterpreting the dependencies output by the // build script. let state = Arc :: clone ( & cx . build_state ) ; let key = ( unit . pkg . package_id ( ) , unit . kind ) ; let pkg_root = unit . pkg . root ( ) . to_path_buf ( ) ; let target_root = cx . files ( ) . target_root ( ) . to_path_buf ( ) ; let write_fingerprint = Work :: new ( move | _ | { if let Some ( output_path ) = output_path { let outputs = state . outputs . lock ( ) . unwrap ( ) ; let outputs = & outputs [ & key ] ; if ! outputs . rerun_if_changed . is_empty ( ) || ! outputs . rerun_if_env_changed . is_empty ( ) { let deps = BuildDeps :: new ( & output_path , Some ( outputs ) ) ; fingerprint . local = local_fingerprints_deps ( & deps , & target_root , & pkg_root ) ; fingerprint . update_local ( & target_root ) ? ; } } write_fingerprint ( & loc , & fingerprint ) } ) ; Ok ( ( if compare . is_ok ( ) { Fresh } else { Dirty } , write_fingerprint , Work :: noop ( ) , ) ) }
Prepare the necessary work for the fingerprint of a build command.
Prepare the necessary work for the fingerprint of a build command .
cx
&mut Context<'a, 'cfg>
unit
&Unit<'a>
cx
&mut Context<'a, 'cfg>
unit
&Unit<'a>