2018-01-03 13:25:52 +01:00
|
|
|
#!/usr/bin/python3
|
2015-04-04 21:47:04 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Library General Public License as
|
|
|
|
# published by the Free Software Foundation; either version 2 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import glob
|
|
|
|
|
|
|
|
class CMakeParser:
|
|
|
|
def __init__(self, filelist = None):
|
|
|
|
if filelist == None:
|
|
|
|
filelist = sys.stdin
|
|
|
|
|
|
|
|
paths = map(lambda x: x.rstrip(), filelist.readlines())
|
|
|
|
for path in paths:
|
2016-11-15 11:31:10 +01:00
|
|
|
for (modulePath, cmakeModule, lowercase) in self.parseCmakeModuleConfig(path):
|
2016-11-18 14:14:56 +01:00
|
|
|
version = self.resolveCMakeModuleVersion(modulePath, cmakeModule, lowercase)
|
|
|
|
|
2015-04-04 21:47:04 +02:00
|
|
|
if version:
|
2016-11-15 11:31:10 +01:00
|
|
|
print("cmake(%s) = %s" % (cmakeModule, version))
|
2015-04-04 21:47:04 +02:00
|
|
|
else:
|
2016-11-15 11:31:10 +01:00
|
|
|
print("cmake(%s)" % cmakeModule)
|
2015-04-04 21:47:04 +02:00
|
|
|
|
|
|
|
def parseCmakeModuleConfig(self, configFile):
|
|
|
|
paths = configFile.rsplit("/", 3)
|
|
|
|
|
|
|
|
modulePath = "%s/cmake/%s" % (paths[0], paths[2])
|
|
|
|
|
2016-11-15 11:31:10 +01:00
|
|
|
result = []
|
|
|
|
for configFile in glob.glob("%s/*Config.cmake" % modulePath):
|
2016-11-18 14:14:56 +01:00
|
|
|
moduleName = configFile[len(modulePath) + 1:-len("Config.cmake")]
|
|
|
|
result.append( (modulePath, moduleName, False) )
|
2015-04-04 21:47:04 +02:00
|
|
|
|
2016-11-15 11:31:10 +01:00
|
|
|
for configFile in glob.glob("%s/*-config.cmake" % modulePath):
|
2016-11-18 14:14:56 +01:00
|
|
|
moduleName = configFile[len(modulePath) + 1:-len("-config.cmake")]
|
2016-11-15 11:31:10 +01:00
|
|
|
if (modulePath, moduleName, False) not in result:
|
2016-11-18 14:14:56 +01:00
|
|
|
result.append( (modulePath, moduleName, True) )
|
2015-04-04 21:47:04 +02:00
|
|
|
|
2016-11-18 14:14:56 +01:00
|
|
|
return result
|
2015-04-04 21:47:04 +02:00
|
|
|
|
|
|
|
def resolveCMakeModuleVersion(self, modulePath, cmakeModule, lowercase):
|
|
|
|
versionFile = ("%s/%s-config-version.cmake" if lowercase else "%s/%sConfigVersion.cmake") % (modulePath, cmakeModule)
|
|
|
|
try:
|
|
|
|
f = open(versionFile, 'r')
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
|
|
|
|
# set(PACKAGE_VERSION <version>)
|
|
|
|
version = re.match(r"^set[\ ]*\([\ ]*PACKAGE_VERSION[\ ]+[\"]*([0-9\.]+)[\"]*[\ ]*[.]*\)", line)
|
|
|
|
if version:
|
2021-09-06 11:32:21 +02:00
|
|
|
_version = version.groups(1)[0]
|
|
|
|
if _version == '..':
|
|
|
|
sys.stderr.write("error: Version pattern found without values - '%s' was created incorrectly\n" % versionFile)
|
|
|
|
return _version
|
|
|
|
|
2015-04-04 21:47:04 +02:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = CMakeParser()
|