|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# Copyright (c) 2018, Intel Corporation |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | +# copy of this software and associated documentation files (the "Software"), |
| 7 | +# to deal in the Software without restriction, including without limitation |
| 8 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | +# and/or sell copies of the Software, and to permit persons to whom the |
| 10 | +# Software is furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included |
| 13 | +# in all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 | +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 | +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 | +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 | +# OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + |
| 23 | +# Usage: |
| 24 | +# ./scripts/build_spec.py manifests/manifest.yml scripts/fedora.spec.in <version> <revision> |
| 25 | +# |
| 26 | + |
| 27 | +import datetime |
| 28 | +import git |
| 29 | +import re |
| 30 | +import sys |
| 31 | +import yaml |
| 32 | + |
| 33 | +if len(sys.argv) < 5: |
| 34 | + print "ERROR! invalid number of parameters" |
| 35 | + print |
| 36 | + print "Usage:" |
| 37 | + print " ./scripts/build_spec.py <manifest> <spec.in> <version> <revision>" |
| 38 | + print |
| 39 | + sys.exit(1) |
| 40 | + |
| 41 | +manifest_file = sys.argv[1] |
| 42 | + |
| 43 | +repo = git.Repo(".") |
| 44 | +neo_revision = repo.head.commit |
| 45 | + |
| 46 | +with open(manifest_file, 'r') as f: |
| 47 | + manifest = yaml.load(f) |
| 48 | + |
| 49 | +gmmlib_revision = manifest['components']['gmmlib']['revision'] |
| 50 | + |
| 51 | +c = repo.commit(neo_revision) |
| 52 | +cd = datetime.datetime.fromtimestamp(c.committed_date) |
| 53 | + |
| 54 | +with open("CMakeLists.txt", "r") as f: |
| 55 | + for line in f.readlines(): |
| 56 | + m = re.match("^(pkg_check_modules)(\s*\(\s*)(\S+)\s+(\S+[^>\s])(>?=)([^=\s]\S+)(\s*\)\s*)$", line.strip()) |
| 57 | + if not m is None: |
| 58 | + if m.groups()[3] == 'igc-opencl': |
| 59 | + igc_revision = m.groups()[5] |
| 60 | + |
| 61 | +pkg_version = "%s.%s.%s" %(str(cd.isocalendar()[0])[-2:], cd.isocalendar()[1], sys.argv[3]) |
| 62 | + |
| 63 | +with open(sys.argv[2], 'r') as f: |
| 64 | + for line in f.readlines(): |
| 65 | + if not re.match(".*__NEO_COMMIT_ID__$", line.strip()) is None: |
| 66 | + print "%s" % (line.rstrip().replace("__NEO_COMMIT_ID__", "%s" % neo_revision)) |
| 67 | + continue |
| 68 | + |
| 69 | + if not re.match(".*__GMMLIB_COMMIT_ID__$", line.strip()) is None: |
| 70 | + print "%s" % (line.rstrip().replace("__GMMLIB_COMMIT_ID__", "%s" % gmmlib_revision)) |
| 71 | + continue |
| 72 | + |
| 73 | + if not re.match(".*__NEO_PACKAGE_VERSION__$", line.strip()) is None: |
| 74 | + print "%s" % (line.rstrip().replace("__NEO_PACKAGE_VERSION__", "%s" % pkg_version)) |
| 75 | + continue |
| 76 | + |
| 77 | + if not re.match(".*__NEO_PACKAGE_RELEASE__.*", line.strip()) is None: |
| 78 | + print "%s" % (line.rstrip().replace("__NEO_PACKAGE_RELEASE__", "%s" % sys.argv[4])) |
| 79 | + continue |
| 80 | + |
| 81 | + if not re.match(".*__IGC_VERSION_REQUIRED__$", line.strip()) is None: |
| 82 | + print "%s" % (line.rstrip().replace("__IGC_VERSION_REQUIRED__", "%s" % igc_revision)) |
| 83 | + continue |
| 84 | + |
| 85 | + print line.rstrip() |
| 86 | + |
0 commit comments