@@ -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 ,
@@ -304,6 +305,17 @@ impl Language {
304305 )
305306 }
306307
308+ pub fn to_c_preprocessed_language ( self ) -> Option < Language > {
309+ match self {
310+ Language :: AssemblerToPreprocess => Some ( Language :: Assembler ) ,
311+ Language :: C => Some ( Language :: CPreprocessed ) ,
312+ Language :: Cxx => Some ( Language :: CxxPreprocessed ) ,
313+ Language :: ObjectiveC => Some ( Language :: ObjectiveCPreprocessed ) ,
314+ Language :: ObjectiveCxx => Some ( Language :: ObjectiveCxxPreprocessed ) ,
315+ _ => None ,
316+ }
317+ }
318+
307319 /// Common implementation for GCC and Clang language argument mapping
308320 fn to_compiler_arg ( self , cuda_arg : & ' static str ) -> Option < & ' static str > {
309321 match self {
@@ -1856,13 +1868,39 @@ mod test {
18561868 use crate :: mock_command:: * ;
18571869 use crate :: test:: mock_storage:: MockStorage ;
18581870 use crate :: test:: utils:: * ;
1871+ use enum_iterator:: all;
18591872 use fs:: File ;
18601873 use std:: io:: { Cursor , Write } ;
18611874 use std:: sync:: Arc ;
18621875 use std:: time:: Duration ;
18631876 use test_case:: test_case;
18641877 use tokio:: runtime:: Runtime ;
18651878
1879+ #[ test]
1880+ fn test_c_preprocessing_consistent ( ) {
1881+ for lang in all :: < Language > ( ) {
1882+ let maybe_processed = lang. to_c_preprocessed_language ( ) ;
1883+
1884+ if let Some ( processed) = maybe_processed {
1885+ assert ! (
1886+ !processed. needs_c_preprocessing( ) ,
1887+ "{:?} should not need preprocessing - it is a result of {:?} processing" ,
1888+ processed,
1889+ lang
1890+ ) ;
1891+ }
1892+
1893+ if !lang. needs_c_preprocessing ( ) {
1894+ assert ! (
1895+ maybe_processed. is_none( ) ,
1896+ "{:?} should not be processed, but it is produce the {:?} as a C preprocessing result" ,
1897+ lang,
1898+ maybe_processed. unwrap( )
1899+ ) ;
1900+ }
1901+ }
1902+ }
1903+
18661904 #[ test]
18671905 fn test_detect_compiler_kind_gcc ( ) {
18681906 let f = TestFixture :: new ( ) ;
0 commit comments