Skip to content

Commit

Permalink
Add --toplevel option to query_version_info.py
Browse files Browse the repository at this point in the history
for using changed cmake build directory
  • Loading branch information
mastersin committed Jan 5, 2019
1 parent c48aa83 commit 8f8787c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ elseif(PROVIDED_VERSION_INFO)
message(STATUS "Variable-provided version info: BRANCH=${GIT_BRANCH}")
else()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py" "--mode=cmake_version_info_tbht"
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py" "--mode=cmake_version_info_tbht" "--toplevel=${CMAKE_SOURCE_DIR}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_DEFINITIONS
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/kumir2/kumir2_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else()
# The script exists only if build from main sources tree, but not using SDK
if(EXISTS "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py")
execute_process(
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py" "--mode=cmake_disabled_modules"
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/scripts/query_version_info.py" "--mode=cmake_disabled_modules" "--toplevel=${CMAKE_SOURCE_DIR}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE DISABLED_SUBDIRS
)
Expand Down
40 changes: 22 additions & 18 deletions scripts/query_version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ def _add_path_env(value):
sys.stderr.write("Git executable not found!\n")
sys.exit(1)

TOP_LEVEL_DIR = os.getcwd()

def get_version_information(top_level_dir):
assert isinstance(top_level_dir, str)
def get_version_information():
assert isinstance(TOP_LEVEL_DIR, str)
result = {
"taggedRelease": False,
"version": None,
"hash": None,
"branch": None,
"date": get_date(top_level_dir)
"date": get_date()
}

if os.path.exists(top_level_dir + os.path.sep + ".git"):
if os.path.exists(TOP_LEVEL_DIR + os.path.sep + ".git"):
try:
version_info = subprocess.check_output(
"git describe --abbrev=0 --tags --exact-match",
Expand Down Expand Up @@ -116,7 +117,7 @@ def get_version_information(top_level_dir):
result["hash"] = hash_tag

else:
dir_name = os.path.basename(top_level_dir)
dir_name = os.path.basename(TOP_LEVEL_DIR)
match = re.match(r"kumir2-(.+)", dir_name)
version_info = match.group(1)
if version_info.startswith("2"):
Expand All @@ -126,16 +127,16 @@ def get_version_information(top_level_dir):
return result


def get_date(top_level_dir):
timestamp = int(get_timestamp(top_level_dir))
def get_date():
timestamp = int(get_timestamp())
localtime = time.localtime(timestamp)
assert isinstance(localtime, time.struct_time)
return "{:04}{:02}{:02}".format(localtime.tm_year, localtime.tm_mon, localtime.tm_mday)


def get_timestamp(top_level_dir):
assert isinstance(top_level_dir, str)
if os.path.exists(top_level_dir + os.path.sep + ".git"):
def get_timestamp():
assert isinstance(TOP_LEVEL_DIR, str)
if os.path.exists(TOP_LEVEL_DIR + os.path.sep + ".git"):
return to_str(subprocess.check_output(
"git --no-pager log -1 --pretty=format:%ct",
shell=True,
Expand All @@ -150,7 +151,7 @@ def is_tag(version):


def find_suitable_list_file_name(version_info):
base = os.getcwd() + os.path.sep + "subdirs-disabled-{}.txt"
base = TOP_LEVEL_DIR + os.path.sep + "subdirs-disabled-{}.txt"
if version_info["taggedRelease"]:
name = base.format(version_info["version"])
else:
Expand All @@ -169,7 +170,7 @@ def find_suitable_list_file_name(version_info):


def disabled_modules():
version_info = get_version_information(os.getcwd())
version_info = get_version_information()
disabled_list_file_name = find_suitable_list_file_name(version_info)
disabled_list = []
if disabled_list_file_name:
Expand All @@ -191,9 +192,9 @@ def cmake_disabled_modules():


def cmake_version_info():
version_name = get_version_information(os.getcwd())
version_name = get_version_information()
assert isinstance(version_name, dict)
timestamp = get_timestamp(os.getcwd())
timestamp = get_timestamp()
output = ""
if version_name["taggedRelease"]:
output += "-DGIT_TAG=\"{}\";".format(version_name["version"])
Expand All @@ -208,9 +209,9 @@ def cmake_version_info():


def cmake_version_info_tbht():
version_name = get_version_information(os.getcwd())
version_name = get_version_information()
assert isinstance(version_name, dict)
timestamp = get_timestamp(os.getcwd())
timestamp = get_timestamp()
output_values = []
if version_name["taggedRelease"]:
output_values += to_str(version_name["version"])
Expand All @@ -224,7 +225,7 @@ def cmake_version_info_tbht():


def source_file_name(prefix: str, suffix: str):
version_info = get_version_information(os.getcwd())
version_info = get_version_information()
if version_info["taggedRelease"]:
version_name = version_info["version"]
else:
Expand Down Expand Up @@ -253,7 +254,7 @@ def package_bundle_name():


def nsis_include_file():
version_info = get_version_information(os.getcwd())
version_info = get_version_information()
data = ""
if version_info["taggedRelease"]:
data += "OutFile \"kumir2-" + version_info["version"] + "-install.exe\"\r\n"
Expand Down Expand Up @@ -295,13 +296,16 @@ def get_changelog(max_count=1000, after=(2015, 5, 1)):

def main():
global OUT_FILE
global TOP_LEVEL_DIR
mode = "package_bundle_name"
out_file_name = None
for arg in sys.argv:
if arg.startswith("--mode="):
mode = arg[7:]
elif arg.startswith("--out="):
out_file_name = arg[6:]
elif arg.startswith("--toplevel="):
TOP_LEVEL_DIR = arg[11:]
custom_encoding = False
if out_file_name:
if mode.startswith("nsis"):
Expand Down

0 comments on commit 8f8787c

Please sign in to comment.