mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #84029 - drahnr:master, r=petrochenkov
add `track_path::path` fn for usage in `proc_macro`s Adds a way to declare a dependency on external files without including them, to either re-trigger the build of a file as well as covering the use case of including dependencies within the `rustc` invocation, such that tools like `sccache`/`cachepot` are able to handle references to external files which are not included. Ref #73921
This commit is contained in:
commit
45470a3bcd
@ -411,6 +411,10 @@ impl server::FreeFunctions for Rustc<'_> {
|
||||
fn track_env_var(&mut self, var: &str, value: Option<&str>) {
|
||||
self.sess.env_depinfo.borrow_mut().insert((Symbol::intern(var), value.map(Symbol::intern)));
|
||||
}
|
||||
|
||||
fn track_path(&mut self, path: &str) {
|
||||
self.sess.file_depinfo.borrow_mut().insert(Symbol::intern(path));
|
||||
}
|
||||
}
|
||||
|
||||
impl server::TokenStream for Rustc<'_> {
|
||||
|
@ -28,18 +28,18 @@ use rustc_passes::{self, hir_stats, layout_test};
|
||||
use rustc_plugin_impl as plugin;
|
||||
use rustc_query_impl::Queries as TcxQueries;
|
||||
use rustc_resolve::{Resolver, ResolverArenas};
|
||||
use rustc_serialize::json;
|
||||
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType, PpMode, PpSourceMode};
|
||||
use rustc_session::lint;
|
||||
use rustc_session::output::{filename_for_input, filename_for_metadata};
|
||||
use rustc_session::search_paths::PathKind;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::{Ident, Symbol};
|
||||
use rustc_span::FileName;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_typeck as typeck;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use rustc_serialize::json;
|
||||
use tempfile::Builder as TempFileBuilder;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
@ -594,6 +594,16 @@ fn write_out_deps(
|
||||
.map(|fmap| escape_dep_filename(&fmap.name.prefer_local().to_string()))
|
||||
.collect();
|
||||
|
||||
// Account for explicitly marked-to-track files
|
||||
// (e.g. accessed in proc macros).
|
||||
let file_depinfo = sess.parse_sess.file_depinfo.borrow();
|
||||
let extra_tracked_files = file_depinfo.iter().map(|path_sym| {
|
||||
let path = PathBuf::from(&*path_sym.as_str());
|
||||
let file = FileName::from(path);
|
||||
escape_dep_filename(&file.prefer_local().to_string())
|
||||
});
|
||||
files.extend(extra_tracked_files);
|
||||
|
||||
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
|
||||
files.push(backend.to_string());
|
||||
}
|
||||
|
@ -133,6 +133,8 @@ pub struct ParseSess {
|
||||
pub reached_eof: Lock<bool>,
|
||||
/// Environment variables accessed during the build and their values when they exist.
|
||||
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
|
||||
/// File paths accessed during the build.
|
||||
pub file_depinfo: Lock<FxHashSet<Symbol>>,
|
||||
/// All the type ascriptions expressions that have had a suggestion for likely path typo.
|
||||
pub type_ascription_path_suggestions: Lock<FxHashSet<Span>>,
|
||||
/// Whether cfg(version) should treat the current release as incomplete
|
||||
@ -165,6 +167,7 @@ impl ParseSess {
|
||||
symbol_gallery: SymbolGallery::default(),
|
||||
reached_eof: Lock::new(false),
|
||||
env_depinfo: Default::default(),
|
||||
file_depinfo: Default::default(),
|
||||
type_ascription_path_suggestions: Default::default(),
|
||||
assume_incomplete_release: false,
|
||||
proc_macro_quoted_spans: Default::default(),
|
||||
|
@ -55,6 +55,7 @@ macro_rules! with_api {
|
||||
FreeFunctions {
|
||||
fn drop($self: $S::FreeFunctions);
|
||||
fn track_env_var(var: &str, value: Option<&str>);
|
||||
fn track_path(path: &str);
|
||||
},
|
||||
TokenStream {
|
||||
fn drop($self: $S::TokenStream);
|
||||
|
@ -1234,3 +1234,17 @@ pub mod tracked_env {
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracked access to additional files.
|
||||
#[unstable(feature = "track_path", issue = "73921")]
|
||||
pub mod tracked_path {
|
||||
|
||||
/// Track a file explicitly.
|
||||
///
|
||||
/// Commonly used for tracking asset preprocessing.
|
||||
#[unstable(feature = "track_path", issue = "73921")]
|
||||
pub fn path<P: AsRef<str>>(path: P) {
|
||||
let path: &str = path.as_ref();
|
||||
crate::bridge::client::FreeFunctions::track_path(path);
|
||||
}
|
||||
}
|
||||
|
13
src/test/run-make/track-path-dep-info/Makefile
Normal file
13
src/test/run-make/track-path-dep-info/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
-include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
|
||||
# instead of hardcoding them everywhere they're needed.
|
||||
ifeq ($(IS_MUSL_HOST),1)
|
||||
ADDITIONAL_ARGS := $(RUSTFLAGS)
|
||||
endif
|
||||
|
||||
all:
|
||||
# Proc macro
|
||||
$(BARE_RUSTC) $(ADDITIONAL_ARGS) --out-dir $(TMPDIR) macro_def.rs
|
||||
EXISTING_PROC_MACRO_ENV=1 $(RUSTC) --emit dep-info macro_use.rs
|
||||
$(CGREP) "emojis.txt:" < $(TMPDIR)/macro_use.d
|
1
src/test/run-make/track-path-dep-info/emojis.txt
Normal file
1
src/test/run-make/track-path-dep-info/emojis.txt
Normal file
@ -0,0 +1 @@
|
||||
👾👾👾👾👾👾
|
11
src/test/run-make/track-path-dep-info/macro_def.rs
Normal file
11
src/test/run-make/track-path-dep-info/macro_def.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![feature(track_path)]
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::*;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn access_tracked_paths(_: TokenStream) -> TokenStream {
|
||||
tracked_path::path("emojis.txt");
|
||||
TokenStream::new()
|
||||
}
|
6
src/test/run-make/track-path-dep-info/macro_use.rs
Normal file
6
src/test/run-make/track-path-dep-info/macro_use.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#[macro_use]
|
||||
extern crate macro_def;
|
||||
|
||||
access_tracked_paths!();
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user