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