build_java_with_error_prone.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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(java, [java] + JAVA10_EXPORTS + ['-processorpath', error_prone_tool, '-XDcompilePolicy=byfile'] + [(' '.join(['-Xplugin:ErrorProne'] + ERROR_PRONE_FLAGS))] + javac_cmd)
  27. else:
  28. os.execv(java, [java, '-Xbootclasspath/p:' + error_prone_tool, 'com.google.errorprone.ErrorProneCompiler'] + ERROR_PRONE_FLAGS + javac_cmd)
  29. if __name__ == '__main__':
  30. just_do_it(sys.argv[1:])