| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import glob |
|---|
| 4 | import os |
|---|
| 5 | import sys |
|---|
| 6 | import errno |
|---|
| 7 | |
|---|
| 8 | from distutils import core, ccompiler, log, sysconfig |
|---|
| 9 | from distutils.command import build, sdist, build_py |
|---|
| 10 | from stat import ST_MODE |
|---|
| 11 | |
|---|
| 12 | class mysdist(sdist.sdist): |
|---|
| 13 | default_format = dict(sdist.sdist.default_format) |
|---|
| 14 | default_format["posix"] = "bztar" |
|---|
| 15 | |
|---|
| 16 | def get_file_list(self): |
|---|
| 17 | for key, globs in self.distribution.package_data.iteritems(): |
|---|
| 18 | for pattern in globs: |
|---|
| 19 | self.filelist.extend(glob.glob(os.path.join(key, pattern))) |
|---|
| 20 | self.filelist.append("ChangeLog") |
|---|
| 21 | self.filelist.append("AUTHORS") |
|---|
| 22 | self.filelist.append("sandbox/test.py") |
|---|
| 23 | self.filelist.extend(glob.glob("sandbox/test-plugins/*")) |
|---|
| 24 | self.filelist.extend(glob.glob('doc/*.rst')) |
|---|
| 25 | self.filelist.extend(glob.glob('dev-notes/*.rst')) |
|---|
| 26 | self.filelist.extend(glob.glob('dev-notes/reimplementation/*.rst')) |
|---|
| 27 | self.filelist.extend(glob.glob('dev-notes/framework/*.rst')) |
|---|
| 28 | self.filelist.append('build_docs.py') |
|---|
| 29 | self.filelist.exclude_pattern("pkgcore/bin/ebuild-env/filter-env") |
|---|
| 30 | # XXX HACK: if you run "setup.py sdist" with python 2.5 this |
|---|
| 31 | # does not get packaged without this. |
|---|
| 32 | self.filelist.append('pkgcore/util/_functoolsmodule.c') |
|---|
| 33 | sdist.sdist.get_file_list(self) |
|---|
| 34 | |
|---|
| 35 | def run(self): |
|---|
| 36 | print "regenning ChangeLog (may take a while)" |
|---|
| 37 | os.system("bzr log --verbose > ChangeLog") |
|---|
| 38 | sdist.sdist.run(self) |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class build_filter_env(core.Command): |
|---|
| 42 | |
|---|
| 43 | """Build the filter-env utility. |
|---|
| 44 | |
|---|
| 45 | This rips a bunch of code from the distutils build_clib command. |
|---|
| 46 | """ |
|---|
| 47 | |
|---|
| 48 | user_options = [ |
|---|
| 49 | ('debug', 'g', 'compile with debugging information'), |
|---|
| 50 | ('force', 'f', 'compile everything (ignore timestamps)'), |
|---|
| 51 | ('compiler=', 'c', 'specify the compiler type'), |
|---|
| 52 | ] |
|---|
| 53 | |
|---|
| 54 | boolean_options = ['debug', 'force'] |
|---|
| 55 | |
|---|
| 56 | help_options = [ |
|---|
| 57 | ('help-compiler', None, |
|---|
| 58 | 'list available compilers', ccompiler.show_compilers), |
|---|
| 59 | ] |
|---|
| 60 | |
|---|
| 61 | def initialize_options(self): |
|---|
| 62 | """If we had any options we would initialize them here.""" |
|---|
| 63 | self.debug = None |
|---|
| 64 | self.force = 0 |
|---|
| 65 | self.compiler = None |
|---|
| 66 | |
|---|
| 67 | def finalize_options(self): |
|---|
| 68 | """If we had any options we would finalize them here.""" |
|---|
| 69 | self.set_undefined_options( |
|---|
| 70 | 'build', |
|---|
| 71 | ('debug', 'debug'), |
|---|
| 72 | ('force', 'force'), |
|---|
| 73 | ('compiler', 'compiler')) |
|---|
| 74 | |
|---|
| 75 | def run(self): |
|---|
| 76 | compiler = ccompiler.new_compiler( |
|---|
| 77 | compiler=self.compiler, dry_run=self.dry_run, force=self.force) |
|---|
| 78 | cc = "%s %s" % (os.environ.get("CC", "cc"), os.environ.get("CFLAGS", "")) |
|---|
| 79 | compiler.set_executables(compiler=cc, compiler_so=cc, linker_exe=cc) |
|---|
| 80 | objects = compiler.compile(list( |
|---|
| 81 | os.path.join('src', 'filter-env', name) |
|---|
| 82 | for name in ('main.c', 'bmh_search.c')), debug=self.debug) |
|---|
| 83 | compiler.link(compiler.EXECUTABLE, objects, os.path.join( |
|---|
| 84 | 'pkgcore', 'bin', 'ebuild-env', 'filter-env')) |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | build.build.sub_commands.append(('build_filter_env', None)) |
|---|
| 88 | |
|---|
| 89 | class hacked_build_py(build_py.build_py): |
|---|
| 90 | |
|---|
| 91 | def run(self): |
|---|
| 92 | build_py.build_py.run(self) |
|---|
| 93 | |
|---|
| 94 | fp = os.path.join(self.build_lib, "pkgcore", "bin", "ebuild-helpers") |
|---|
| 95 | for f in os.listdir(fp): |
|---|
| 96 | self.set_chmod(os.path.join(fp, f)) |
|---|
| 97 | fp = os.path.join(self.build_lib, "pkgcore", "bin", "ebuild-env") |
|---|
| 98 | for f in ("ebuild.sh", "ebuild-daemon.sh"): |
|---|
| 99 | self.set_chmod(os.path.join(fp, f)) |
|---|
| 100 | if os.path.exists(os.path.join(fp, "filter-env")): |
|---|
| 101 | self.set_chmod(os.path.join(fp, "filter-env")) |
|---|
| 102 | |
|---|
| 103 | def set_chmod(self, path): |
|---|
| 104 | if self.dry_run: |
|---|
| 105 | log.info("changing mode of %s", path) |
|---|
| 106 | else: |
|---|
| 107 | mode = ((os.stat(path)[ST_MODE]) | 0555) & 07777 |
|---|
| 108 | log.info("changing mode of %s to %o", path, mode) |
|---|
| 109 | os.chmod(path, mode) |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | packages = [] |
|---|
| 113 | |
|---|
| 114 | for root, dirs, files in os.walk('pkgcore'): |
|---|
| 115 | if '__init__.py' in files: |
|---|
| 116 | package = root.replace(os.path.sep, '.') |
|---|
| 117 | print 'adding package %r' % (package,) |
|---|
| 118 | packages.append(package) |
|---|
| 119 | |
|---|
| 120 | try: |
|---|
| 121 | os.unlink("MANIFEST") |
|---|
| 122 | except OSError, oe: |
|---|
| 123 | if oe.errno != errno.ENOENT: |
|---|
| 124 | raise |
|---|
| 125 | del oe |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | extra_flags = ['-Wall'] |
|---|
| 129 | |
|---|
| 130 | extensions = [] |
|---|
| 131 | if sys.version_info < (2, 5): |
|---|
| 132 | # Almost unmodified copy from the python 2.5 source. |
|---|
| 133 | extensions.append(core.Extension( |
|---|
| 134 | 'pkgcore.util._functools', ['pkgcore/util/_functoolsmodule.c'], |
|---|
| 135 | extra_compile_args=extra_flags)) |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | core.setup( |
|---|
| 139 | name='pkgcore', |
|---|
| 140 | version='0.1.3', |
|---|
| 141 | description='package managing framework', |
|---|
| 142 | url='http://gentooexperimental.org/~ferringb/bzr/pkgcore/', |
|---|
| 143 | packages=packages, |
|---|
| 144 | package_data={ |
|---|
| 145 | 'pkgcore': [ |
|---|
| 146 | 'data/*', |
|---|
| 147 | 'bin/ebuild-env/*', |
|---|
| 148 | 'bin/ebuild-helpers/*', |
|---|
| 149 | 'heapdef.h', |
|---|
| 150 | ], |
|---|
| 151 | 'src': [ |
|---|
| 152 | 'filter-env/*.c', |
|---|
| 153 | 'filter-env/*.h', |
|---|
| 154 | 'bsd-flags/*', |
|---|
| 155 | 'tbz2tool.c' |
|---|
| 156 | ], |
|---|
| 157 | }, |
|---|
| 158 | # booo, no glob support in distutils for this one |
|---|
| 159 | scripts=( |
|---|
| 160 | glob.glob('pkgcore/bin/utilities/*.py') + |
|---|
| 161 | glob.glob('bin/*')), |
|---|
| 162 | ext_modules=[ |
|---|
| 163 | core.Extension('pkgcore.util._caching', ['pkgcore/util/_caching.c'], |
|---|
| 164 | extra_compile_args=extra_flags), |
|---|
| 165 | core.Extension('pkgcore.util._lists', ['pkgcore/util/_lists.c'], |
|---|
| 166 | extra_compile_args=extra_flags), |
|---|
| 167 | core.Extension('pkgcore.ebuild._cpv', ['pkgcore/ebuild/_cpv.c'], |
|---|
| 168 | extra_compile_args=extra_flags), |
|---|
| 169 | core.Extension('pkgcore.util.osutils._readdir', |
|---|
| 170 | ['pkgcore/util/osutils/_readdir.c'], |
|---|
| 171 | extra_compile_args=extra_flags), |
|---|
| 172 | ] + extensions, |
|---|
| 173 | cmdclass={'build_filter_env': build_filter_env, |
|---|
| 174 | 'sdist': mysdist, |
|---|
| 175 | 'build_py': hacked_build_py}, |
|---|
| 176 | ) |
|---|