Skip to content

Commit

Permalink
Add @generated comment on top of generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
diconico07 committed Oct 19, 2023
1 parent 97cd4e2 commit 11b8bd1
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions prost-build/src/fixtures/alphabet/_expected_include.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
pub mod a {
include!("a.rs");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Container {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Container {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(derive_builder::Builder)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[derive(derive_builder::Builder)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
pub mod com {
pub mod prost_test {
pub mod test {
Expand Down
10 changes: 10 additions & 0 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ impl Config {
if let Some(ref include_file) = self.include_file {
trace!("Writing include file: {:?}", target.join(include_file));
let mut file = fs::File::create(target.join(include_file))?;
self.write_line(&mut file, 0, "// This file is @generated by prost-build.")?;
self.write_includes(
modules.keys().collect(),
&mut file,
Expand Down Expand Up @@ -1224,9 +1225,18 @@ impl Config {
self.fmt_modules(&mut modules);
}

self.add_generated_modules(&mut modules);

Ok(modules)
}

fn add_generated_modules(&mut self, modules: &mut HashMap<Module, String>) {
for buf in modules.values_mut() {
let with_generated = "// This file is @generated by prost-build.\n".to_string() + buf;
*buf = with_generated;
}
}

#[cfg(feature = "format")]
fn fmt_modules(&mut self, modules: &mut HashMap<Module, String>) {
for buf in modules.values_mut() {
Expand Down
1 change: 1 addition & 0 deletions tests/single-include/src/outdir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
pub mod outdir {
include!("outdir.rs");
}
1 change: 1 addition & 0 deletions tests/single-include/src/outdir/outdir.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OutdirRequest {
Expand Down

0 comments on commit 11b8bd1

Please sign in to comment.