@@ -38,6 +38,7 @@ use crate::server;
3838use crate :: util:: { fmt_duration_as_secs, run_input_output} ;
3939use crate :: { counted_array, dist} ;
4040use async_trait:: async_trait;
41+ use enum_iterator:: Sequence ;
4142use filetime:: FileTime ;
4243use fs:: File ;
4344use fs_err as fs;
@@ -212,7 +213,7 @@ pub enum CompilerKind {
212213 Rust ,
213214}
214215
215- #[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
216+ #[ derive( Debug , PartialEq , Eq , Clone , Copy , Sequence ) ]
216217pub enum Language {
217218 AssemblerToPreprocess ,
218219 Assembler ,
@@ -305,6 +306,17 @@ impl Language {
305306 )
306307 }
307308
309+ pub fn to_c_preprocessed_language ( self ) -> Option < Language > {
310+ match self {
311+ Language :: AssemblerToPreprocess => Some ( Language :: Assembler ) ,
312+ Language :: C => Some ( Language :: CPreprocessed ) ,
313+ Language :: Cxx => Some ( Language :: CxxPreprocessed ) ,
314+ Language :: ObjectiveC => Some ( Language :: ObjectiveCPreprocessed ) ,
315+ Language :: ObjectiveCxx => Some ( Language :: ObjectiveCxxPreprocessed ) ,
316+ _ => None ,
317+ }
318+ }
319+
308320 /// Common implementation for GCC and Clang language argument mapping
309321 fn to_compiler_arg ( self , cuda_arg : & ' static str ) -> Option < & ' static str > {
310322 match self {
@@ -1859,13 +1871,39 @@ mod test {
18591871 use crate :: mock_command:: * ;
18601872 use crate :: test:: mock_storage:: MockStorage ;
18611873 use crate :: test:: utils:: * ;
1874+ use enum_iterator:: all;
18621875 use fs:: File ;
18631876 use std:: io:: { Cursor , Write } ;
18641877 use std:: sync:: Arc ;
18651878 use std:: time:: Duration ;
18661879 use test_case:: test_case;
18671880 use tokio:: runtime:: Runtime ;
18681881
1882+ #[ test]
1883+ fn test_c_preprocessing_consistent ( ) {
1884+ for lang in all :: < Language > ( ) {
1885+ let maybe_processed = lang. to_c_preprocessed_language ( ) ;
1886+
1887+ if let Some ( processed) = maybe_processed {
1888+ assert ! (
1889+ !processed. needs_c_preprocessing( ) ,
1890+ "{:?} should not need preprocessing - it is a result of {:?} processing" ,
1891+ processed,
1892+ lang
1893+ ) ;
1894+ }
1895+
1896+ if !lang. needs_c_preprocessing ( ) {
1897+ assert ! (
1898+ maybe_processed. is_none( ) ,
1899+ "{:?} should not be processed, but it is produce the {:?} as a C preprocessing result" ,
1900+ lang,
1901+ maybe_processed. unwrap( )
1902+ ) ;
1903+ }
1904+ }
1905+ }
1906+
18691907 #[ test]
18701908 fn test_detect_compiler_kind_gcc ( ) {
18711909 let f = TestFixture :: new ( ) ;
0 commit comments