/[packages]/cauldron/cmake-rpm-macros/current/SOURCES/cmake.prov
ViewVC logotype

Contents of /cauldron/cmake-rpm-macros/current/SOURCES/cmake.prov

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1888601 - (show annotations) (download)
Wed Sep 14 20:08:55 2022 UTC (14 months, 3 weeks ago) by wally
File size: 3220 byte(s)
- add copyright (SILENT)
1 #!/usr/bin/python3
2 # -*- coding:utf-8 -*-
3 #
4 # Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
5 # Copyright (C) 2017 Daniel Vrátil <dvratil@fedoraproject.org>
6 # Copyright (C) 2022 Jani Välimaa <wally@mageia.org>
7 #
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU Library General Public License as
11 # published by the Free Software Foundation; either version 2 of the
12 # License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU Library General Public
20 # License along with this program; if not, write to the
21 # Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #
24
25 import os
26 import sys
27 import re
28 import glob
29
30 class CMakeParser:
31 def __init__(self, filelist = None):
32 if filelist == None:
33 filelist = sys.stdin
34
35 paths = map(lambda x: x.rstrip(), filelist.readlines())
36 for path in paths:
37 modulePath, cmakeModule, lowercase = self.parseCmakeModuleConfig(path)
38 if modulePath and cmakeModule:
39 version = self.resolveCMakeModuleVersion(modulePath, cmakeModule, lowercase)
40
41 if version:
42 string = "cmake(" + cmakeModule + ") = " + version
43 else:
44 string = "cmake(" + cmakeModule + ")"
45 if string == string.lower():
46 print(string)
47 else:
48 # Temporarily print both variants to satisfy requires
49 # by the old version of this generator which made mistakes
50 print(string)
51 print(string.lower())
52
53
54 def parseCmakeModuleConfig(self, configFile):
55 paths = configFile.rsplit("/", 1)
56
57 modulePath = paths[0]
58 cfgFile = paths[1]
59 if cfgFile.endswith("Config.cmake"):
60 return (modulePath, cfgFile[0:-len("Config.cmake")], False)
61 elif cfgFile.endswith("-config.cmake"):
62 return (modulePath, cfgFile[0:-len("-config.cmake")], True)
63 else:
64 return (None, None, False)
65
66 def resolveCMakeModuleVersion(self, modulePath, cmakeModule, lowercase):
67 versionFile = ("%s/%s-config-version.cmake" if lowercase else "%s/%sConfigVersion.cmake") % (modulePath, cmakeModule)
68
69 if not lowercase and os.path.isfile("%s/%sConfigVersionImpl.cmake" % (modulePath, cmakeModule)):
70 versionFile = "%s/%sConfigVersionImpl.cmake" % (modulePath, cmakeModule)
71
72 try:
73 f = open(versionFile, 'r')
74 except:
75 return None
76
77 for line in f:
78 line = line.strip()
79
80 # set(PACKAGE_VERSION <version>)
81 version = re.match(r"^set[\ ]*\([\ ]*PACKAGE_VERSION[\ ]+[\"]*([0-9\.]+)[\"]*[\ ]*[.]*\)", line)
82 if version:
83 return version.groups(1)[0]
84
85 return None
86
87 if __name__ == "__main__":
88 parser = CMakeParser()

  ViewVC Help
Powered by ViewVC 1.1.28