@@ -521,9 +521,20 @@ private void generateCApiSource(List<CApiBuiltinDesc> javaBuiltins, List<String>
521521 lines .add ("}" );
522522
523523 var origins = javaBuiltins .stream ().map ((jb ) -> jb .origin ).toArray (Element []::new );
524- var file = processingEnv .getFiler ().createResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.c.h" , origins );
525- try (var w = file .openWriter ()) {
526- w .append (String .join (System .lineSeparator (), lines ));
524+ String oldContents = "" ;
525+ String newContents = String .join (System .lineSeparator (), lines );
526+ try {
527+ oldContents = processingEnv .getFiler ().getResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.c.h" ).getCharContent (true ).toString ();
528+ } catch (IOException e ) {
529+ // pass to regenerate
530+ }
531+ if (!oldContents .equals (newContents )) {
532+ var file = processingEnv .getFiler ().createResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.c.h" , origins );
533+ try (var w = file .openWriter ()) {
534+ w .append (newContents );
535+ }
536+ } else {
537+ processingEnv .getMessager ().printNote ("Python capi.gen.c.h is up to date" );
527538 }
528539 }
529540
@@ -585,9 +596,20 @@ private void generateCApiHeader(List<CApiBuiltinDesc> javaBuiltins, Map<String,
585596 }
586597
587598 var origins = javaBuiltins .stream ().map ((jb ) -> jb .origin ).toArray (Element []::new );
588- var file = processingEnv .getFiler ().createResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.h" , origins );
589- try (var w = file .openWriter ()) {
590- w .append (String .join (System .lineSeparator (), lines ));
599+ String oldContents = "" ;
600+ String newContents = String .join (System .lineSeparator (), lines );
601+ try {
602+ oldContents = processingEnv .getFiler ().getResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.c.h" ).getCharContent (true ).toString ();
603+ } catch (IOException e ) {
604+ // pass to regenerate
605+ }
606+ if (!oldContents .equals (newContents )) {
607+ var file = processingEnv .getFiler ().createResource (StandardLocation .NATIVE_HEADER_OUTPUT , "" , "capi.gen.h" , origins );
608+ try (var w = file .openWriter ()) {
609+ w .append (String .join (System .lineSeparator (), lines ));
610+ }
611+ } else {
612+ processingEnv .getMessager ().printNote ("Python capi.gen.h is up to date" );
591613 }
592614 }
593615
0 commit comments