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