Blame build/GenVer.py

Packit 1244b8
#! /usr/bin/env python3
Packit 1244b8
"""
Packit 1244b8
 * Copyright (C) 2013 Intel Corporation. All rights reserved.
Packit 1244b8
 *
Packit 1244b8
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1244b8
 * you may not use this file except in compliance with the License.
Packit 1244b8
 * You may obtain a copy of the License at
Packit 1244b8
 *
Packit 1244b8
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1244b8
 *
Packit 1244b8
 * Unless required by applicable law or agreed to in writing, software
Packit 1244b8
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1244b8
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1244b8
 * See the License for the specific language governing permissions and
Packit 1244b8
 * limitations under the License.
Packit 1244b8
"""
Packit 1244b8
Packit 1244b8
import re
Packit 1244b8
import os.path as path
Packit 1244b8
Packit 1244b8
def query(config, name):
Packit 1244b8
     m = re.search('m4_define\\(\\[' + name + '\\], *([0-9]*)\\)', config)
Packit 1244b8
     return m.group(1)
Packit 1244b8
Packit 1244b8
def replace(tpl, config, dest, src):
Packit 1244b8
    v = query(config, src)
Packit 1244b8
    return tpl.replace(dest, v)
Packit 1244b8
Packit 1244b8
cur = path.dirname(__file__)
Packit 1244b8
root = path.abspath(path.join(cur, ".."))
Packit 1244b8
with open(path.join(root, "interface/YamiVersion.h.in")) as f:
Packit 1244b8
    tpl = f.read()
Packit 1244b8
with open(path.join(root, "configure.ac")) as f:
Packit 1244b8
    config = f.read()
Packit 1244b8
tpl = replace(tpl, config, '@YAMI_API_MAJOR_VERSION@', 'yami_api_major_version')
Packit 1244b8
tpl = replace(tpl, config, '@YAMI_API_MINOR_VERSION@', 'yami_api_minor_version')
Packit 1244b8
tpl = replace(tpl, config, '@YAMI_API_MICRO_VERSION@', 'yami_api_micro_version')
Packit 1244b8
Packit 1244b8
with open(path.join(root, "interface/YamiVersion.h"), "w") as f:
Packit 1244b8
     f.write(tpl)