From d0f5d8f86bc01928a07b2804eeeab9eb33bbbe75 Mon Sep 17 00:00:00 2001 From: Nicolas Belouin Date: Thu, 19 Oct 2023 14:01:05 +0200 Subject: [PATCH] Add @generated comment on top of generated files --- prost-build/src/fixtures/alphabet/_expected_include.rs | 1 + .../field_attributes/_expected_field_attributes.rs | 1 + .../_expected_field_attributes_formatted.rs | 1 + .../src/fixtures/helloworld/_expected_helloworld.rs | 1 + .../helloworld/_expected_helloworld_formatted.rs | 1 + .../src/fixtures/imports_empty/_expected_include.rs | 1 + prost-build/src/lib.rs | 10 ++++++++++ prost-types/src/compiler.rs | 1 + prost-types/src/protobuf.rs | 1 + tests/single-include/src/outdir/mod.rs | 1 + tests/single-include/src/outdir/outdir.rs | 1 + 11 files changed, 20 insertions(+) diff --git a/prost-build/src/fixtures/alphabet/_expected_include.rs b/prost-build/src/fixtures/alphabet/_expected_include.rs index 8f42b561e..87de4feed 100644 --- a/prost-build/src/fixtures/alphabet/_expected_include.rs +++ b/prost-build/src/fixtures/alphabet/_expected_include.rs @@ -1,3 +1,4 @@ +// This file is @generated by prost-build. pub mod a { include!("a.rs"); } diff --git a/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs b/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs index 04860e63d..95fb05d86 100644 --- a/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs +++ b/prost-build/src/fixtures/field_attributes/_expected_field_attributes.rs @@ -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 { diff --git a/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs b/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs index 8c329f902..f1eaee751 100644 --- a/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs +++ b/prost-build/src/fixtures/field_attributes/_expected_field_attributes_formatted.rs @@ -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 { diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs index 2f05c46ed..401ee90cd 100644 --- a/prost-build/src/fixtures/helloworld/_expected_helloworld.rs +++ b/prost-build/src/fixtures/helloworld/_expected_helloworld.rs @@ -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)] diff --git a/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs index a64c4da3c..3f688c7e0 100644 --- a/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs +++ b/prost-build/src/fixtures/helloworld/_expected_helloworld_formatted.rs @@ -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)] diff --git a/prost-build/src/fixtures/imports_empty/_expected_include.rs b/prost-build/src/fixtures/imports_empty/_expected_include.rs index 6deb45f07..a9dcc9386 100644 --- a/prost-build/src/fixtures/imports_empty/_expected_include.rs +++ b/prost-build/src/fixtures/imports_empty/_expected_include.rs @@ -1,3 +1,4 @@ +// This file is @generated by prost-build. pub mod com { pub mod prost_test { pub mod test { diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 3fdec73b8..d0c5df51c 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -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, @@ -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) { + 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) { for buf in modules.values_mut() { diff --git a/prost-types/src/compiler.rs b/prost-types/src/compiler.rs index 81cdcfa55..0a3b46804 100644 --- a/prost-types/src/compiler.rs +++ b/prost-types/src/compiler.rs @@ -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)] diff --git a/prost-types/src/protobuf.rs b/prost-types/src/protobuf.rs index fcbe430df..edc1361be 100644 --- a/prost-types/src/protobuf.rs +++ b/prost-types/src/protobuf.rs @@ -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)] diff --git a/tests/single-include/src/outdir/mod.rs b/tests/single-include/src/outdir/mod.rs index 8cf70ccb6..400d90465 100644 --- a/tests/single-include/src/outdir/mod.rs +++ b/tests/single-include/src/outdir/mod.rs @@ -1,3 +1,4 @@ +// This file is @generated by prost-build. pub mod outdir { include!("outdir.rs"); } diff --git a/tests/single-include/src/outdir/outdir.rs b/tests/single-include/src/outdir/outdir.rs index eee461c1b..577245e5f 100644 --- a/tests/single-include/src/outdir/outdir.rs +++ b/tests/single-include/src/outdir/outdir.rs @@ -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 {