Skip to content

Commit

Permalink
Add @generated comment on top of generated files (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
diconico07 committed Feb 20, 2024
1 parent 3cb37f2 commit 54838c6
Show file tree
Hide file tree
Showing 11 changed files with 20 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 @@ -1031,6 +1031,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 @@ -1266,9 +1267,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 prost-types/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The version number of protocol compiler.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down
1 change: 1 addition & 0 deletions prost-types/src/protobuf.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This file is @generated by prost-build.
/// The protocol compiler can output a FileDescriptorSet containing the .proto
/// files it parses.
#[allow(clippy::derive_partial_eq_without_eq)]
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 54838c6

Please sign in to comment.