# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#----------------------------------------------------------------------
# Modifications Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Notified per clause 4(b) of the license.
#
#----------------------------------------------------------------------

import os
Matches = []
def SearchYamlFiles(ExtensionType,TargetYamlFileName):
    TargetYamlFile = open(TargetYamlFileName, 'w')
    for Root, Dirnames, FileNames in os.walk("."):
        for FileName in FileNames:
            if FileName.endswith(ExtensionType):
                Matches.append(os.path.join(Root, FileName))
                YAMLFile=os.path.join(Root, FileName)
                print(os.path.join(Root, FileName))
                TargetYamlFile.write(open(YAMLFile).read())
    TargetYamlFile.close()
    if os.stat(TargetYamlFileName).st_size == 0:
        os.remove(TargetYamlFileName)



if __name__ == '__main__':
    ExtensionType=".opt.yaml"
    TargetYamlFileName="optimization_database.yaml"
    SearchYamlFiles(ExtensionType,TargetYamlFileName)

    ExtensionType=".opt.ld.yaml"
    TargetYamlFileName="optimization_database.ld.yaml"
    SearchYamlFiles(ExtensionType,TargetYamlFileName)
