0ee124
#!/usr/bin/python3
0ee124
# -*- coding:utf-8 -*-
0ee124
#
0ee124
# Copyright (C) 2017 Björn Esser <besser82@fedoraproject.org>
0ee124
#
0ee124
# based on cmake.prov, which is
0ee124
# Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
0ee124
# Copyright (C) 2017 Daniel Vrátil <dvratil@fedoraproject.org>
0ee124
#
0ee124
#
0ee124
# This program is free software; you can redistribute it and/or modify
0ee124
# it under the terms of the GNU Library General Public License as
0ee124
# published by the Free Software Foundation; either version 2 of the
0ee124
# License, or (at your option) any later version.
0ee124
#
0ee124
# This program is distributed in the hope that it will be useful,
0ee124
# but WITHOUT ANY WARRANTY; without even the implied warranty of
0ee124
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0ee124
# GNU General Public License for more details.
0ee124
#
0ee124
# You should have received a copy of the GNU Library General Public
0ee124
# License along with this program; if not, write to the
0ee124
# Free Software Foundation, Inc.,
0ee124
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0ee124
#
0ee124
0ee124
import sys
0ee124
import re
0ee124
import subprocess
0ee124
0ee124
class CMakeParser:
0ee124
    def __init__(self, filelist = None):
0ee124
        if filelist == None:
0ee124
            filelist = sys.stdin
0ee124
0ee124
        has_module = False
0ee124
        is_arched = False
0ee124
0ee124
        isa_suf = subprocess.check_output(["/usr/bin/rpm", "-E %{?_isa}"]).decode().strip()
0ee124
0ee124
        paths = map(lambda x: x.rstrip(), filelist.readlines())
0ee124
        for path in paths:
0ee124
            modulePath, cmakeModule, lowercase = self.parseCmakeModuleConfig(path)
0ee124
            if modulePath and cmakeModule:
0ee124
                has_module = True
0ee124
                if re.match(".*/usr/lib(64)?/cmake/.*", modulePath):
0ee124
                    is_arched = True
0ee124
0ee124
        if has_module:
0ee124
            if is_arched:
0ee124
                print("cmake-filesystem%s" % isa_suf)
0ee124
            else:
0ee124
                print("cmake-filesystem")
0ee124
0ee124
0ee124
    def parseCmakeModuleConfig(self, configFile):
0ee124
        paths = configFile.rsplit("/", 3)
0ee124
0ee124
        modulePath = "%s/cmake/%s" % (paths[0], paths[2])
0ee124
        cfgFile = paths[3]
0ee124
        if cfgFile.endswith("Config.cmake"):
0ee124
           return (modulePath, cfgFile[0:-len("Config.cmake")], False)
0ee124
        elif cfgFile.endswith("-config.cmake"):
0ee124
           return (modulePath, cfgFile[0:-len("-config.cmake")], True)
0ee124
        else:
0ee124
            return (None, None, False)
0ee124
0ee124
0ee124
if __name__ == "__main__":
0ee124
    parser = CMakeParser()