aot-compile-rpm.in 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python
  2. ## Copyright (C) 2005, 2006, 2007, 2011 Free Software Foundation
  3. ## Written by Gary Benson <gbenson@redhat.com>
  4. ##
  5. ## This program is free software; you can redistribute it and/or modify
  6. ## it under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2 of the License, or
  8. ## (at your option) any later version.
  9. ##
  10. ## This program is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ## GNU General Public License for more details.
  14. import sys
  15. sys.path.insert(0, "@python_mod_dir_expanded@")
  16. import aotcompile
  17. import os
  18. def libdir():
  19. cmd = "%s -p" % aotcompile.PATHS["dbtool"]
  20. dir = os.path.abspath(os.popen(cmd, "r").readline().rstrip())
  21. dir, base = os.path.split(dir)
  22. if base != "classmap.db":
  23. raise aotcompile.Error, "%s: unexpected output" % cmd
  24. dir, base = os.path.split(dir)
  25. if not base.startswith("gcj-"):
  26. raise aotcompile.Error, "%s: unexpected output" % cmd
  27. return dir
  28. def writeSourceList(srcdir, dstpath):
  29. def visit(fp, dir, items):
  30. for item in items:
  31. path = os.path.join(dir, item)
  32. if os.path.isfile(path):
  33. print >>fp, path
  34. dstdir = os.path.dirname(dstpath)
  35. if not os.path.isdir(dstdir):
  36. os.makedirs(dstdir)
  37. os.path.walk(srcdir, visit, open(dstpath, "w"))
  38. def copy(srcdir, dstdir, suffix):
  39. srcdir = os.path.join(srcdir, suffix.lstrip(os.sep))
  40. dstdir = os.path.join(dstdir, suffix.lstrip(os.sep))
  41. os.makedirs(os.path.dirname(dstdir))
  42. aotcompile.system(("/bin/cp", "-a", srcdir, dstdir))
  43. try:
  44. name = os.environ.get("RPM_PACKAGE_NAME")
  45. if name is None:
  46. raise aotcompile.Error, "not for use outside rpm specfiles"
  47. arch = os.environ.get("RPM_ARCH")
  48. if arch == "noarch":
  49. raise aotcompile.Error, "cannot be used on noarch packages"
  50. srcdir = os.environ.get("RPM_BUILD_ROOT")
  51. if srcdir in (None, "/"):
  52. raise aotcompile.Error, "bad $RPM_BUILD_ROOT"
  53. tmpdir = os.path.join(os.getcwd(), "aot-compile-rpm")
  54. if os.path.exists(tmpdir):
  55. raise aotcompile.Error, "%s exists" % tmpdir
  56. dstdir = os.path.join(libdir(), "gcj", name)
  57. compiler = aotcompile.Compiler(srcdir, dstdir, tmpdir)
  58. compiler.gcjflags[0:0] = os.environ.get("RPM_OPT_FLAGS", "").split()
  59. # XXX: This script should not accept options, because having
  60. # them it cannot be integrated into rpm. But, gcj cannot
  61. # build each and every jarfile yet, so we must be able to
  62. # exclude until it can.
  63. # XXX --exclude is also used in the jonas rpm to stop
  64. # everything being made a subset of the mammoth client
  65. # jarfile. Should adjust the subset checker's bias to
  66. # favour many small jarfiles over one big one.
  67. try:
  68. options, exclusions = sys.argv[1:], []
  69. while options:
  70. if options.pop(0) != "--exclude":
  71. raise ValueError
  72. compiler.exclusions.append(
  73. os.path.join(srcdir, options.pop(0).lstrip(os.sep)))
  74. except:
  75. print >>sys.stderr, "usage: %s [--exclude PATH]..." % (
  76. os.path.basename(sys.argv[0]))
  77. sys.exit(1)
  78. sourcelist = os.path.join(tmpdir, "sources.list")
  79. writeSourceList(os.getcwd(), sourcelist)
  80. compiler.gcjflags.append("-fsource-filename=" + sourcelist)
  81. compiler.compile()
  82. copy(tmpdir, srcdir, dstdir)
  83. except aotcompile.Error, e:
  84. print >>sys.stderr, "%s: error: %s" % (
  85. os.path.basename(sys.argv[0]), e)
  86. sys.exit(1)