build_java_with_error_prone.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import sys
  2. import os
  3. ERROR_PRONE_FLAGS = [
  4. '-Xep:FunctionalInterfaceMethodChanged:WARN',
  5. '-Xep:ReturnValueIgnored:WARN',
  6. ]
  7. JAVA10_EXPORTS = [
  8. '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
  9. '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED',
  10. '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
  11. '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
  12. '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
  13. '--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED',
  14. '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
  15. '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
  16. ]
  17. def just_do_it(argv):
  18. java, error_prone_tool, javac_cmd = argv[0], argv[1], argv[2:]
  19. if java.endswith('javac') or java.endswith('javac.exe'):
  20. for f in javac_cmd:
  21. if f.startswith('-Xep'):
  22. ERROR_PRONE_FLAGS.append(f)
  23. for f in ERROR_PRONE_FLAGS:
  24. if f in javac_cmd:
  25. javac_cmd.remove(f)
  26. os.execv(
  27. java,
  28. [java]
  29. + JAVA10_EXPORTS
  30. + ['-processorpath', error_prone_tool, '-XDcompilePolicy=byfile']
  31. + [(' '.join(['-Xplugin:ErrorProne'] + ERROR_PRONE_FLAGS))]
  32. + javac_cmd,
  33. )
  34. else:
  35. os.execv(
  36. java,
  37. [java, '-Xbootclasspath/p:' + error_prone_tool, 'com.google.errorprone.ErrorProneCompiler']
  38. + ERROR_PRONE_FLAGS
  39. + javac_cmd,
  40. )
  41. if __name__ == '__main__':
  42. just_do_it(sys.argv[1:])