| 1 | n/a | """distutils.command.bdist_rpm |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | Implements the Distutils 'bdist_rpm' command (create RPM source and binary |
|---|
| 4 | n/a | distributions).""" |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | import subprocess, sys, os |
|---|
| 7 | n/a | from distutils.core import Command |
|---|
| 8 | n/a | from distutils.debug import DEBUG |
|---|
| 9 | n/a | from distutils.util import get_platform |
|---|
| 10 | n/a | from distutils.file_util import write_file |
|---|
| 11 | n/a | from distutils.errors import * |
|---|
| 12 | n/a | from distutils.sysconfig import get_python_version |
|---|
| 13 | n/a | from distutils import log |
|---|
| 14 | n/a | |
|---|
| 15 | n/a | class bdist_rpm(Command): |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | description = "create an RPM distribution" |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | user_options = [ |
|---|
| 20 | n/a | ('bdist-base=', None, |
|---|
| 21 | n/a | "base directory for creating built distributions"), |
|---|
| 22 | n/a | ('rpm-base=', None, |
|---|
| 23 | n/a | "base directory for creating RPMs (defaults to \"rpm\" under " |
|---|
| 24 | n/a | "--bdist-base; must be specified for RPM 2)"), |
|---|
| 25 | n/a | ('dist-dir=', 'd', |
|---|
| 26 | n/a | "directory to put final RPM files in " |
|---|
| 27 | n/a | "(and .spec files if --spec-only)"), |
|---|
| 28 | n/a | ('python=', None, |
|---|
| 29 | n/a | "path to Python interpreter to hard-code in the .spec file " |
|---|
| 30 | n/a | "(default: \"python\")"), |
|---|
| 31 | n/a | ('fix-python', None, |
|---|
| 32 | n/a | "hard-code the exact path to the current Python interpreter in " |
|---|
| 33 | n/a | "the .spec file"), |
|---|
| 34 | n/a | ('spec-only', None, |
|---|
| 35 | n/a | "only regenerate spec file"), |
|---|
| 36 | n/a | ('source-only', None, |
|---|
| 37 | n/a | "only generate source RPM"), |
|---|
| 38 | n/a | ('binary-only', None, |
|---|
| 39 | n/a | "only generate binary RPM"), |
|---|
| 40 | n/a | ('use-bzip2', None, |
|---|
| 41 | n/a | "use bzip2 instead of gzip to create source distribution"), |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | # More meta-data: too RPM-specific to put in the setup script, |
|---|
| 44 | n/a | # but needs to go in the .spec file -- so we make these options |
|---|
| 45 | n/a | # to "bdist_rpm". The idea is that packagers would put this |
|---|
| 46 | n/a | # info in setup.cfg, although they are of course free to |
|---|
| 47 | n/a | # supply it on the command line. |
|---|
| 48 | n/a | ('distribution-name=', None, |
|---|
| 49 | n/a | "name of the (Linux) distribution to which this " |
|---|
| 50 | n/a | "RPM applies (*not* the name of the module distribution!)"), |
|---|
| 51 | n/a | ('group=', None, |
|---|
| 52 | n/a | "package classification [default: \"Development/Libraries\"]"), |
|---|
| 53 | n/a | ('release=', None, |
|---|
| 54 | n/a | "RPM release number"), |
|---|
| 55 | n/a | ('serial=', None, |
|---|
| 56 | n/a | "RPM serial number"), |
|---|
| 57 | n/a | ('vendor=', None, |
|---|
| 58 | n/a | "RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") " |
|---|
| 59 | n/a | "[default: maintainer or author from setup script]"), |
|---|
| 60 | n/a | ('packager=', None, |
|---|
| 61 | n/a | "RPM packager (eg. \"Jane Doe <jane@example.net>\")" |
|---|
| 62 | n/a | "[default: vendor]"), |
|---|
| 63 | n/a | ('doc-files=', None, |
|---|
| 64 | n/a | "list of documentation files (space or comma-separated)"), |
|---|
| 65 | n/a | ('changelog=', None, |
|---|
| 66 | n/a | "RPM changelog"), |
|---|
| 67 | n/a | ('icon=', None, |
|---|
| 68 | n/a | "name of icon file"), |
|---|
| 69 | n/a | ('provides=', None, |
|---|
| 70 | n/a | "capabilities provided by this package"), |
|---|
| 71 | n/a | ('requires=', None, |
|---|
| 72 | n/a | "capabilities required by this package"), |
|---|
| 73 | n/a | ('conflicts=', None, |
|---|
| 74 | n/a | "capabilities which conflict with this package"), |
|---|
| 75 | n/a | ('build-requires=', None, |
|---|
| 76 | n/a | "capabilities required to build this package"), |
|---|
| 77 | n/a | ('obsoletes=', None, |
|---|
| 78 | n/a | "capabilities made obsolete by this package"), |
|---|
| 79 | n/a | ('no-autoreq', None, |
|---|
| 80 | n/a | "do not automatically calculate dependencies"), |
|---|
| 81 | n/a | |
|---|
| 82 | n/a | # Actions to take when building RPM |
|---|
| 83 | n/a | ('keep-temp', 'k', |
|---|
| 84 | n/a | "don't clean up RPM build directory"), |
|---|
| 85 | n/a | ('no-keep-temp', None, |
|---|
| 86 | n/a | "clean up RPM build directory [default]"), |
|---|
| 87 | n/a | ('use-rpm-opt-flags', None, |
|---|
| 88 | n/a | "compile with RPM_OPT_FLAGS when building from source RPM"), |
|---|
| 89 | n/a | ('no-rpm-opt-flags', None, |
|---|
| 90 | n/a | "do not pass any RPM CFLAGS to compiler"), |
|---|
| 91 | n/a | ('rpm3-mode', None, |
|---|
| 92 | n/a | "RPM 3 compatibility mode (default)"), |
|---|
| 93 | n/a | ('rpm2-mode', None, |
|---|
| 94 | n/a | "RPM 2 compatibility mode"), |
|---|
| 95 | n/a | |
|---|
| 96 | n/a | # Add the hooks necessary for specifying custom scripts |
|---|
| 97 | n/a | ('prep-script=', None, |
|---|
| 98 | n/a | "Specify a script for the PREP phase of RPM building"), |
|---|
| 99 | n/a | ('build-script=', None, |
|---|
| 100 | n/a | "Specify a script for the BUILD phase of RPM building"), |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | ('pre-install=', None, |
|---|
| 103 | n/a | "Specify a script for the pre-INSTALL phase of RPM building"), |
|---|
| 104 | n/a | ('install-script=', None, |
|---|
| 105 | n/a | "Specify a script for the INSTALL phase of RPM building"), |
|---|
| 106 | n/a | ('post-install=', None, |
|---|
| 107 | n/a | "Specify a script for the post-INSTALL phase of RPM building"), |
|---|
| 108 | n/a | |
|---|
| 109 | n/a | ('pre-uninstall=', None, |
|---|
| 110 | n/a | "Specify a script for the pre-UNINSTALL phase of RPM building"), |
|---|
| 111 | n/a | ('post-uninstall=', None, |
|---|
| 112 | n/a | "Specify a script for the post-UNINSTALL phase of RPM building"), |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | ('clean-script=', None, |
|---|
| 115 | n/a | "Specify a script for the CLEAN phase of RPM building"), |
|---|
| 116 | n/a | |
|---|
| 117 | n/a | ('verify-script=', None, |
|---|
| 118 | n/a | "Specify a script for the VERIFY phase of the RPM build"), |
|---|
| 119 | n/a | |
|---|
| 120 | n/a | # Allow a packager to explicitly force an architecture |
|---|
| 121 | n/a | ('force-arch=', None, |
|---|
| 122 | n/a | "Force an architecture onto the RPM build process"), |
|---|
| 123 | n/a | |
|---|
| 124 | n/a | ('quiet', 'q', |
|---|
| 125 | n/a | "Run the INSTALL phase of RPM building in quiet mode"), |
|---|
| 126 | n/a | ] |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode', |
|---|
| 129 | n/a | 'no-autoreq', 'quiet'] |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | negative_opt = {'no-keep-temp': 'keep-temp', |
|---|
| 132 | n/a | 'no-rpm-opt-flags': 'use-rpm-opt-flags', |
|---|
| 133 | n/a | 'rpm2-mode': 'rpm3-mode'} |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | |
|---|
| 136 | n/a | def initialize_options(self): |
|---|
| 137 | n/a | self.bdist_base = None |
|---|
| 138 | n/a | self.rpm_base = None |
|---|
| 139 | n/a | self.dist_dir = None |
|---|
| 140 | n/a | self.python = None |
|---|
| 141 | n/a | self.fix_python = None |
|---|
| 142 | n/a | self.spec_only = None |
|---|
| 143 | n/a | self.binary_only = None |
|---|
| 144 | n/a | self.source_only = None |
|---|
| 145 | n/a | self.use_bzip2 = None |
|---|
| 146 | n/a | |
|---|
| 147 | n/a | self.distribution_name = None |
|---|
| 148 | n/a | self.group = None |
|---|
| 149 | n/a | self.release = None |
|---|
| 150 | n/a | self.serial = None |
|---|
| 151 | n/a | self.vendor = None |
|---|
| 152 | n/a | self.packager = None |
|---|
| 153 | n/a | self.doc_files = None |
|---|
| 154 | n/a | self.changelog = None |
|---|
| 155 | n/a | self.icon = None |
|---|
| 156 | n/a | |
|---|
| 157 | n/a | self.prep_script = None |
|---|
| 158 | n/a | self.build_script = None |
|---|
| 159 | n/a | self.install_script = None |
|---|
| 160 | n/a | self.clean_script = None |
|---|
| 161 | n/a | self.verify_script = None |
|---|
| 162 | n/a | self.pre_install = None |
|---|
| 163 | n/a | self.post_install = None |
|---|
| 164 | n/a | self.pre_uninstall = None |
|---|
| 165 | n/a | self.post_uninstall = None |
|---|
| 166 | n/a | self.prep = None |
|---|
| 167 | n/a | self.provides = None |
|---|
| 168 | n/a | self.requires = None |
|---|
| 169 | n/a | self.conflicts = None |
|---|
| 170 | n/a | self.build_requires = None |
|---|
| 171 | n/a | self.obsoletes = None |
|---|
| 172 | n/a | |
|---|
| 173 | n/a | self.keep_temp = 0 |
|---|
| 174 | n/a | self.use_rpm_opt_flags = 1 |
|---|
| 175 | n/a | self.rpm3_mode = 1 |
|---|
| 176 | n/a | self.no_autoreq = 0 |
|---|
| 177 | n/a | |
|---|
| 178 | n/a | self.force_arch = None |
|---|
| 179 | n/a | self.quiet = 0 |
|---|
| 180 | n/a | |
|---|
| 181 | n/a | def finalize_options(self): |
|---|
| 182 | n/a | self.set_undefined_options('bdist', ('bdist_base', 'bdist_base')) |
|---|
| 183 | n/a | if self.rpm_base is None: |
|---|
| 184 | n/a | if not self.rpm3_mode: |
|---|
| 185 | n/a | raise DistutilsOptionError( |
|---|
| 186 | n/a | "you must specify --rpm-base in RPM 2 mode") |
|---|
| 187 | n/a | self.rpm_base = os.path.join(self.bdist_base, "rpm") |
|---|
| 188 | n/a | |
|---|
| 189 | n/a | if self.python is None: |
|---|
| 190 | n/a | if self.fix_python: |
|---|
| 191 | n/a | self.python = sys.executable |
|---|
| 192 | n/a | else: |
|---|
| 193 | n/a | self.python = "python3" |
|---|
| 194 | n/a | elif self.fix_python: |
|---|
| 195 | n/a | raise DistutilsOptionError( |
|---|
| 196 | n/a | "--python and --fix-python are mutually exclusive options") |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | if os.name != 'posix': |
|---|
| 199 | n/a | raise DistutilsPlatformError("don't know how to create RPM " |
|---|
| 200 | n/a | "distributions on platform %s" % os.name) |
|---|
| 201 | n/a | if self.binary_only and self.source_only: |
|---|
| 202 | n/a | raise DistutilsOptionError( |
|---|
| 203 | n/a | "cannot supply both '--source-only' and '--binary-only'") |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | # don't pass CFLAGS to pure python distributions |
|---|
| 206 | n/a | if not self.distribution.has_ext_modules(): |
|---|
| 207 | n/a | self.use_rpm_opt_flags = 0 |
|---|
| 208 | n/a | |
|---|
| 209 | n/a | self.set_undefined_options('bdist', ('dist_dir', 'dist_dir')) |
|---|
| 210 | n/a | self.finalize_package_data() |
|---|
| 211 | n/a | |
|---|
| 212 | n/a | def finalize_package_data(self): |
|---|
| 213 | n/a | self.ensure_string('group', "Development/Libraries") |
|---|
| 214 | n/a | self.ensure_string('vendor', |
|---|
| 215 | n/a | "%s <%s>" % (self.distribution.get_contact(), |
|---|
| 216 | n/a | self.distribution.get_contact_email())) |
|---|
| 217 | n/a | self.ensure_string('packager') |
|---|
| 218 | n/a | self.ensure_string_list('doc_files') |
|---|
| 219 | n/a | if isinstance(self.doc_files, list): |
|---|
| 220 | n/a | for readme in ('README', 'README.txt'): |
|---|
| 221 | n/a | if os.path.exists(readme) and readme not in self.doc_files: |
|---|
| 222 | n/a | self.doc_files.append(readme) |
|---|
| 223 | n/a | |
|---|
| 224 | n/a | self.ensure_string('release', "1") |
|---|
| 225 | n/a | self.ensure_string('serial') # should it be an int? |
|---|
| 226 | n/a | |
|---|
| 227 | n/a | self.ensure_string('distribution_name') |
|---|
| 228 | n/a | |
|---|
| 229 | n/a | self.ensure_string('changelog') |
|---|
| 230 | n/a | # Format changelog correctly |
|---|
| 231 | n/a | self.changelog = self._format_changelog(self.changelog) |
|---|
| 232 | n/a | |
|---|
| 233 | n/a | self.ensure_filename('icon') |
|---|
| 234 | n/a | |
|---|
| 235 | n/a | self.ensure_filename('prep_script') |
|---|
| 236 | n/a | self.ensure_filename('build_script') |
|---|
| 237 | n/a | self.ensure_filename('install_script') |
|---|
| 238 | n/a | self.ensure_filename('clean_script') |
|---|
| 239 | n/a | self.ensure_filename('verify_script') |
|---|
| 240 | n/a | self.ensure_filename('pre_install') |
|---|
| 241 | n/a | self.ensure_filename('post_install') |
|---|
| 242 | n/a | self.ensure_filename('pre_uninstall') |
|---|
| 243 | n/a | self.ensure_filename('post_uninstall') |
|---|
| 244 | n/a | |
|---|
| 245 | n/a | # XXX don't forget we punted on summaries and descriptions -- they |
|---|
| 246 | n/a | # should be handled here eventually! |
|---|
| 247 | n/a | |
|---|
| 248 | n/a | # Now *this* is some meta-data that belongs in the setup script... |
|---|
| 249 | n/a | self.ensure_string_list('provides') |
|---|
| 250 | n/a | self.ensure_string_list('requires') |
|---|
| 251 | n/a | self.ensure_string_list('conflicts') |
|---|
| 252 | n/a | self.ensure_string_list('build_requires') |
|---|
| 253 | n/a | self.ensure_string_list('obsoletes') |
|---|
| 254 | n/a | |
|---|
| 255 | n/a | self.ensure_string('force_arch') |
|---|
| 256 | n/a | |
|---|
| 257 | n/a | def run(self): |
|---|
| 258 | n/a | if DEBUG: |
|---|
| 259 | n/a | print("before _get_package_data():") |
|---|
| 260 | n/a | print("vendor =", self.vendor) |
|---|
| 261 | n/a | print("packager =", self.packager) |
|---|
| 262 | n/a | print("doc_files =", self.doc_files) |
|---|
| 263 | n/a | print("changelog =", self.changelog) |
|---|
| 264 | n/a | |
|---|
| 265 | n/a | # make directories |
|---|
| 266 | n/a | if self.spec_only: |
|---|
| 267 | n/a | spec_dir = self.dist_dir |
|---|
| 268 | n/a | self.mkpath(spec_dir) |
|---|
| 269 | n/a | else: |
|---|
| 270 | n/a | rpm_dir = {} |
|---|
| 271 | n/a | for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'): |
|---|
| 272 | n/a | rpm_dir[d] = os.path.join(self.rpm_base, d) |
|---|
| 273 | n/a | self.mkpath(rpm_dir[d]) |
|---|
| 274 | n/a | spec_dir = rpm_dir['SPECS'] |
|---|
| 275 | n/a | |
|---|
| 276 | n/a | # Spec file goes into 'dist_dir' if '--spec-only specified', |
|---|
| 277 | n/a | # build/rpm.<plat> otherwise. |
|---|
| 278 | n/a | spec_path = os.path.join(spec_dir, |
|---|
| 279 | n/a | "%s.spec" % self.distribution.get_name()) |
|---|
| 280 | n/a | self.execute(write_file, |
|---|
| 281 | n/a | (spec_path, |
|---|
| 282 | n/a | self._make_spec_file()), |
|---|
| 283 | n/a | "writing '%s'" % spec_path) |
|---|
| 284 | n/a | |
|---|
| 285 | n/a | if self.spec_only: # stop if requested |
|---|
| 286 | n/a | return |
|---|
| 287 | n/a | |
|---|
| 288 | n/a | # Make a source distribution and copy to SOURCES directory with |
|---|
| 289 | n/a | # optional icon. |
|---|
| 290 | n/a | saved_dist_files = self.distribution.dist_files[:] |
|---|
| 291 | n/a | sdist = self.reinitialize_command('sdist') |
|---|
| 292 | n/a | if self.use_bzip2: |
|---|
| 293 | n/a | sdist.formats = ['bztar'] |
|---|
| 294 | n/a | else: |
|---|
| 295 | n/a | sdist.formats = ['gztar'] |
|---|
| 296 | n/a | self.run_command('sdist') |
|---|
| 297 | n/a | self.distribution.dist_files = saved_dist_files |
|---|
| 298 | n/a | |
|---|
| 299 | n/a | source = sdist.get_archive_files()[0] |
|---|
| 300 | n/a | source_dir = rpm_dir['SOURCES'] |
|---|
| 301 | n/a | self.copy_file(source, source_dir) |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | if self.icon: |
|---|
| 304 | n/a | if os.path.exists(self.icon): |
|---|
| 305 | n/a | self.copy_file(self.icon, source_dir) |
|---|
| 306 | n/a | else: |
|---|
| 307 | n/a | raise DistutilsFileError( |
|---|
| 308 | n/a | "icon file '%s' does not exist" % self.icon) |
|---|
| 309 | n/a | |
|---|
| 310 | n/a | # build package |
|---|
| 311 | n/a | log.info("building RPMs") |
|---|
| 312 | n/a | rpm_cmd = ['rpm'] |
|---|
| 313 | n/a | if os.path.exists('/usr/bin/rpmbuild') or \ |
|---|
| 314 | n/a | os.path.exists('/bin/rpmbuild'): |
|---|
| 315 | n/a | rpm_cmd = ['rpmbuild'] |
|---|
| 316 | n/a | |
|---|
| 317 | n/a | if self.source_only: # what kind of RPMs? |
|---|
| 318 | n/a | rpm_cmd.append('-bs') |
|---|
| 319 | n/a | elif self.binary_only: |
|---|
| 320 | n/a | rpm_cmd.append('-bb') |
|---|
| 321 | n/a | else: |
|---|
| 322 | n/a | rpm_cmd.append('-ba') |
|---|
| 323 | n/a | rpm_cmd.extend(['--define', '__python %s' % self.python]) |
|---|
| 324 | n/a | if self.rpm3_mode: |
|---|
| 325 | n/a | rpm_cmd.extend(['--define', |
|---|
| 326 | n/a | '_topdir %s' % os.path.abspath(self.rpm_base)]) |
|---|
| 327 | n/a | if not self.keep_temp: |
|---|
| 328 | n/a | rpm_cmd.append('--clean') |
|---|
| 329 | n/a | |
|---|
| 330 | n/a | if self.quiet: |
|---|
| 331 | n/a | rpm_cmd.append('--quiet') |
|---|
| 332 | n/a | |
|---|
| 333 | n/a | rpm_cmd.append(spec_path) |
|---|
| 334 | n/a | # Determine the binary rpm names that should be built out of this spec |
|---|
| 335 | n/a | # file |
|---|
| 336 | n/a | # Note that some of these may not be really built (if the file |
|---|
| 337 | n/a | # list is empty) |
|---|
| 338 | n/a | nvr_string = "%{name}-%{version}-%{release}" |
|---|
| 339 | n/a | src_rpm = nvr_string + ".src.rpm" |
|---|
| 340 | n/a | non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm" |
|---|
| 341 | n/a | q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % ( |
|---|
| 342 | n/a | src_rpm, non_src_rpm, spec_path) |
|---|
| 343 | n/a | |
|---|
| 344 | n/a | out = os.popen(q_cmd) |
|---|
| 345 | n/a | try: |
|---|
| 346 | n/a | binary_rpms = [] |
|---|
| 347 | n/a | source_rpm = None |
|---|
| 348 | n/a | while True: |
|---|
| 349 | n/a | line = out.readline() |
|---|
| 350 | n/a | if not line: |
|---|
| 351 | n/a | break |
|---|
| 352 | n/a | l = line.strip().split() |
|---|
| 353 | n/a | assert(len(l) == 2) |
|---|
| 354 | n/a | binary_rpms.append(l[1]) |
|---|
| 355 | n/a | # The source rpm is named after the first entry in the spec file |
|---|
| 356 | n/a | if source_rpm is None: |
|---|
| 357 | n/a | source_rpm = l[0] |
|---|
| 358 | n/a | |
|---|
| 359 | n/a | status = out.close() |
|---|
| 360 | n/a | if status: |
|---|
| 361 | n/a | raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) |
|---|
| 362 | n/a | |
|---|
| 363 | n/a | finally: |
|---|
| 364 | n/a | out.close() |
|---|
| 365 | n/a | |
|---|
| 366 | n/a | self.spawn(rpm_cmd) |
|---|
| 367 | n/a | |
|---|
| 368 | n/a | if not self.dry_run: |
|---|
| 369 | n/a | if self.distribution.has_ext_modules(): |
|---|
| 370 | n/a | pyversion = get_python_version() |
|---|
| 371 | n/a | else: |
|---|
| 372 | n/a | pyversion = 'any' |
|---|
| 373 | n/a | |
|---|
| 374 | n/a | if not self.binary_only: |
|---|
| 375 | n/a | srpm = os.path.join(rpm_dir['SRPMS'], source_rpm) |
|---|
| 376 | n/a | assert(os.path.exists(srpm)) |
|---|
| 377 | n/a | self.move_file(srpm, self.dist_dir) |
|---|
| 378 | n/a | filename = os.path.join(self.dist_dir, source_rpm) |
|---|
| 379 | n/a | self.distribution.dist_files.append( |
|---|
| 380 | n/a | ('bdist_rpm', pyversion, filename)) |
|---|
| 381 | n/a | |
|---|
| 382 | n/a | if not self.source_only: |
|---|
| 383 | n/a | for rpm in binary_rpms: |
|---|
| 384 | n/a | rpm = os.path.join(rpm_dir['RPMS'], rpm) |
|---|
| 385 | n/a | if os.path.exists(rpm): |
|---|
| 386 | n/a | self.move_file(rpm, self.dist_dir) |
|---|
| 387 | n/a | filename = os.path.join(self.dist_dir, |
|---|
| 388 | n/a | os.path.basename(rpm)) |
|---|
| 389 | n/a | self.distribution.dist_files.append( |
|---|
| 390 | n/a | ('bdist_rpm', pyversion, filename)) |
|---|
| 391 | n/a | |
|---|
| 392 | n/a | def _dist_path(self, path): |
|---|
| 393 | n/a | return os.path.join(self.dist_dir, os.path.basename(path)) |
|---|
| 394 | n/a | |
|---|
| 395 | n/a | def _make_spec_file(self): |
|---|
| 396 | n/a | """Generate the text of an RPM spec file and return it as a |
|---|
| 397 | n/a | list of strings (one per line). |
|---|
| 398 | n/a | """ |
|---|
| 399 | n/a | # definitions and headers |
|---|
| 400 | n/a | spec_file = [ |
|---|
| 401 | n/a | '%define name ' + self.distribution.get_name(), |
|---|
| 402 | n/a | '%define version ' + self.distribution.get_version().replace('-','_'), |
|---|
| 403 | n/a | '%define unmangled_version ' + self.distribution.get_version(), |
|---|
| 404 | n/a | '%define release ' + self.release.replace('-','_'), |
|---|
| 405 | n/a | '', |
|---|
| 406 | n/a | 'Summary: ' + self.distribution.get_description(), |
|---|
| 407 | n/a | ] |
|---|
| 408 | n/a | |
|---|
| 409 | n/a | # Workaround for #14443 which affects some RPM based systems such as |
|---|
| 410 | n/a | # RHEL6 (and probably derivatives) |
|---|
| 411 | n/a | vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}') |
|---|
| 412 | n/a | # Generate a potential replacement value for __os_install_post (whilst |
|---|
| 413 | n/a | # normalizing the whitespace to simplify the test for whether the |
|---|
| 414 | n/a | # invocation of brp-python-bytecompile passes in __python): |
|---|
| 415 | n/a | vendor_hook = '\n'.join([' %s \\' % line.strip() |
|---|
| 416 | n/a | for line in vendor_hook.splitlines()]) |
|---|
| 417 | n/a | problem = "brp-python-bytecompile \\\n" |
|---|
| 418 | n/a | fixed = "brp-python-bytecompile %{__python} \\\n" |
|---|
| 419 | n/a | fixed_hook = vendor_hook.replace(problem, fixed) |
|---|
| 420 | n/a | if fixed_hook != vendor_hook: |
|---|
| 421 | n/a | spec_file.append('# Workaround for http://bugs.python.org/issue14443') |
|---|
| 422 | n/a | spec_file.append('%define __os_install_post ' + fixed_hook + '\n') |
|---|
| 423 | n/a | |
|---|
| 424 | n/a | # put locale summaries into spec file |
|---|
| 425 | n/a | # XXX not supported for now (hard to put a dictionary |
|---|
| 426 | n/a | # in a config file -- arg!) |
|---|
| 427 | n/a | #for locale in self.summaries.keys(): |
|---|
| 428 | n/a | # spec_file.append('Summary(%s): %s' % (locale, |
|---|
| 429 | n/a | # self.summaries[locale])) |
|---|
| 430 | n/a | |
|---|
| 431 | n/a | spec_file.extend([ |
|---|
| 432 | n/a | 'Name: %{name}', |
|---|
| 433 | n/a | 'Version: %{version}', |
|---|
| 434 | n/a | 'Release: %{release}',]) |
|---|
| 435 | n/a | |
|---|
| 436 | n/a | # XXX yuck! this filename is available from the "sdist" command, |
|---|
| 437 | n/a | # but only after it has run: and we create the spec file before |
|---|
| 438 | n/a | # running "sdist", in case of --spec-only. |
|---|
| 439 | n/a | if self.use_bzip2: |
|---|
| 440 | n/a | spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2') |
|---|
| 441 | n/a | else: |
|---|
| 442 | n/a | spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz') |
|---|
| 443 | n/a | |
|---|
| 444 | n/a | spec_file.extend([ |
|---|
| 445 | n/a | 'License: ' + self.distribution.get_license(), |
|---|
| 446 | n/a | 'Group: ' + self.group, |
|---|
| 447 | n/a | 'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot', |
|---|
| 448 | n/a | 'Prefix: %{_prefix}', ]) |
|---|
| 449 | n/a | |
|---|
| 450 | n/a | if not self.force_arch: |
|---|
| 451 | n/a | # noarch if no extension modules |
|---|
| 452 | n/a | if not self.distribution.has_ext_modules(): |
|---|
| 453 | n/a | spec_file.append('BuildArch: noarch') |
|---|
| 454 | n/a | else: |
|---|
| 455 | n/a | spec_file.append( 'BuildArch: %s' % self.force_arch ) |
|---|
| 456 | n/a | |
|---|
| 457 | n/a | for field in ('Vendor', |
|---|
| 458 | n/a | 'Packager', |
|---|
| 459 | n/a | 'Provides', |
|---|
| 460 | n/a | 'Requires', |
|---|
| 461 | n/a | 'Conflicts', |
|---|
| 462 | n/a | 'Obsoletes', |
|---|
| 463 | n/a | ): |
|---|
| 464 | n/a | val = getattr(self, field.lower()) |
|---|
| 465 | n/a | if isinstance(val, list): |
|---|
| 466 | n/a | spec_file.append('%s: %s' % (field, ' '.join(val))) |
|---|
| 467 | n/a | elif val is not None: |
|---|
| 468 | n/a | spec_file.append('%s: %s' % (field, val)) |
|---|
| 469 | n/a | |
|---|
| 470 | n/a | |
|---|
| 471 | n/a | if self.distribution.get_url() != 'UNKNOWN': |
|---|
| 472 | n/a | spec_file.append('Url: ' + self.distribution.get_url()) |
|---|
| 473 | n/a | |
|---|
| 474 | n/a | if self.distribution_name: |
|---|
| 475 | n/a | spec_file.append('Distribution: ' + self.distribution_name) |
|---|
| 476 | n/a | |
|---|
| 477 | n/a | if self.build_requires: |
|---|
| 478 | n/a | spec_file.append('BuildRequires: ' + |
|---|
| 479 | n/a | ' '.join(self.build_requires)) |
|---|
| 480 | n/a | |
|---|
| 481 | n/a | if self.icon: |
|---|
| 482 | n/a | spec_file.append('Icon: ' + os.path.basename(self.icon)) |
|---|
| 483 | n/a | |
|---|
| 484 | n/a | if self.no_autoreq: |
|---|
| 485 | n/a | spec_file.append('AutoReq: 0') |
|---|
| 486 | n/a | |
|---|
| 487 | n/a | spec_file.extend([ |
|---|
| 488 | n/a | '', |
|---|
| 489 | n/a | '%description', |
|---|
| 490 | n/a | self.distribution.get_long_description() |
|---|
| 491 | n/a | ]) |
|---|
| 492 | n/a | |
|---|
| 493 | n/a | # put locale descriptions into spec file |
|---|
| 494 | n/a | # XXX again, suppressed because config file syntax doesn't |
|---|
| 495 | n/a | # easily support this ;-( |
|---|
| 496 | n/a | #for locale in self.descriptions.keys(): |
|---|
| 497 | n/a | # spec_file.extend([ |
|---|
| 498 | n/a | # '', |
|---|
| 499 | n/a | # '%description -l ' + locale, |
|---|
| 500 | n/a | # self.descriptions[locale], |
|---|
| 501 | n/a | # ]) |
|---|
| 502 | n/a | |
|---|
| 503 | n/a | # rpm scripts |
|---|
| 504 | n/a | # figure out default build script |
|---|
| 505 | n/a | def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0])) |
|---|
| 506 | n/a | def_build = "%s build" % def_setup_call |
|---|
| 507 | n/a | if self.use_rpm_opt_flags: |
|---|
| 508 | n/a | def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build |
|---|
| 509 | n/a | |
|---|
| 510 | n/a | # insert contents of files |
|---|
| 511 | n/a | |
|---|
| 512 | n/a | # XXX this is kind of misleading: user-supplied options are files |
|---|
| 513 | n/a | # that we open and interpolate into the spec file, but the defaults |
|---|
| 514 | n/a | # are just text that we drop in as-is. Hmmm. |
|---|
| 515 | n/a | |
|---|
| 516 | n/a | install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT ' |
|---|
| 517 | n/a | '--record=INSTALLED_FILES') % def_setup_call |
|---|
| 518 | n/a | |
|---|
| 519 | n/a | script_options = [ |
|---|
| 520 | n/a | ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"), |
|---|
| 521 | n/a | ('build', 'build_script', def_build), |
|---|
| 522 | n/a | ('install', 'install_script', install_cmd), |
|---|
| 523 | n/a | ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), |
|---|
| 524 | n/a | ('verifyscript', 'verify_script', None), |
|---|
| 525 | n/a | ('pre', 'pre_install', None), |
|---|
| 526 | n/a | ('post', 'post_install', None), |
|---|
| 527 | n/a | ('preun', 'pre_uninstall', None), |
|---|
| 528 | n/a | ('postun', 'post_uninstall', None), |
|---|
| 529 | n/a | ] |
|---|
| 530 | n/a | |
|---|
| 531 | n/a | for (rpm_opt, attr, default) in script_options: |
|---|
| 532 | n/a | # Insert contents of file referred to, if no file is referred to |
|---|
| 533 | n/a | # use 'default' as contents of script |
|---|
| 534 | n/a | val = getattr(self, attr) |
|---|
| 535 | n/a | if val or default: |
|---|
| 536 | n/a | spec_file.extend([ |
|---|
| 537 | n/a | '', |
|---|
| 538 | n/a | '%' + rpm_opt,]) |
|---|
| 539 | n/a | if val: |
|---|
| 540 | n/a | spec_file.extend(open(val, 'r').read().split('\n')) |
|---|
| 541 | n/a | else: |
|---|
| 542 | n/a | spec_file.append(default) |
|---|
| 543 | n/a | |
|---|
| 544 | n/a | |
|---|
| 545 | n/a | # files section |
|---|
| 546 | n/a | spec_file.extend([ |
|---|
| 547 | n/a | '', |
|---|
| 548 | n/a | '%files -f INSTALLED_FILES', |
|---|
| 549 | n/a | '%defattr(-,root,root)', |
|---|
| 550 | n/a | ]) |
|---|
| 551 | n/a | |
|---|
| 552 | n/a | if self.doc_files: |
|---|
| 553 | n/a | spec_file.append('%doc ' + ' '.join(self.doc_files)) |
|---|
| 554 | n/a | |
|---|
| 555 | n/a | if self.changelog: |
|---|
| 556 | n/a | spec_file.extend([ |
|---|
| 557 | n/a | '', |
|---|
| 558 | n/a | '%changelog',]) |
|---|
| 559 | n/a | spec_file.extend(self.changelog) |
|---|
| 560 | n/a | |
|---|
| 561 | n/a | return spec_file |
|---|
| 562 | n/a | |
|---|
| 563 | n/a | def _format_changelog(self, changelog): |
|---|
| 564 | n/a | """Format the changelog correctly and convert it to a list of strings |
|---|
| 565 | n/a | """ |
|---|
| 566 | n/a | if not changelog: |
|---|
| 567 | n/a | return changelog |
|---|
| 568 | n/a | new_changelog = [] |
|---|
| 569 | n/a | for line in changelog.strip().split('\n'): |
|---|
| 570 | n/a | line = line.strip() |
|---|
| 571 | n/a | if line[0] == '*': |
|---|
| 572 | n/a | new_changelog.extend(['', line]) |
|---|
| 573 | n/a | elif line[0] == '-': |
|---|
| 574 | n/a | new_changelog.append(line) |
|---|
| 575 | n/a | else: |
|---|
| 576 | n/a | new_changelog.append(' ' + line) |
|---|
| 577 | n/a | |
|---|
| 578 | n/a | # strip trailing newline inserted by first changelog entry |
|---|
| 579 | n/a | if not new_changelog[0]: |
|---|
| 580 | n/a | del new_changelog[0] |
|---|
| 581 | n/a | |
|---|
| 582 | n/a | return new_changelog |
|---|