Implement workaround for cmake using mtime to determine what to rebuild.

This commit is contained in:
pentarctagon 2018-02-09 16:41:15 -06:00 committed by Charles Dang
parent 0193302847
commit acc0b6a1f1
3 changed files with 84 additions and 1 deletions

71
cmake_mtime_crc.py Normal file
View file

@ -0,0 +1,71 @@
import os
from time import time
from zlib import crc32
# #
# Functions
# #
# get the CRC of a file's contents
def getCRC32(file):
src_file = open(file, "r", encoding="utf-8")
file_contents = src_file.read()
src_file.close()
return crc32(file_contents.encode("utf8"))
# recursively get all files in all subdirectories
def getAllFiles(start):
file_list = []
for root, _, files in os.walk(start):
for file in files:
file_list.append(root+"/"+file)
return file_list
# #
# Variables
# #
today = time()
yesterday = time() - (24*60*60)
mtime_file = "build/cmake_mtime_crc.txt"
# #
# Run
# #
file_list = getAllFiles("src")
# get the current CRC all relevant files in src/, and set their mtime to yesterday
crc_dict_curr = {}
for file in file_list:
os.utime(file, (yesterday, yesterday))
if (file.endswith(".cpp") or file.endswith(".hpp") or file.endswith(".tpp") or file.endswith(".c") or file.endswith(".h")) and "CMakeFiles" not in file:
crc_dict_curr.update({file : getCRC32(file)})
# if there's an existing stored list of CRCs, read that in
if os.path.isfile(mtime_file):
readfile = open(mtime_file, "r", encoding="utf-8")
crc_dict_prev = {}
for line in readfile:
line_list = line.strip().split(":")
crc_dict_prev.update({line_list[0] : int(line_list[1])})
readfile.close()
# compare file CRCs between the set of CRCs from the previous run and the current run
# if the file has changed, or is brand new, set its mtime to today so that cmake will know to recompile it
for key, value in crc_dict_curr.items():
if key in crc_dict_prev:
if value != crc_dict_prev[key]:
os.utime(key, (today, today))
else:
os.utime(key, (today, today))
# write out the new set of file CRCs
writefile = open(mtime_file, "w")
for key, value in crc_dict_curr.items():
writefile.write(key+":"+str(value)+"\n")
writefile.close()
print("Updated cmake mtime data!")

View file

@ -2,5 +2,7 @@ FROM wesnoth/wesnoth:16.04
COPY ./ /home/wesnoth-travis/
RUN apt install -y -qq python3
WORKDIR /home/wesnoth-travis

View file

@ -49,7 +49,17 @@ if [ "$NLS" == "true" ]; then
else
# if not doing the translations, build wesnoth, wesnothd, campaignd, boost_unit_tests
if [ "$TOOL" == "cmake" ]; then
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GAME=true -DENABLE_SERVER=true -DENABLE_CAMPAIGN_SERVER=true -DENABLE_TESTS=true -DENABLE_NLS=false -DEXTRA_FLAGS_CONFIG="-pipe" -DEXTRA_FLAGS_RELEASE="$EXTRA_FLAGS_RELEASE" -DENABLE_STRICT_COMPILATION="$STRICT" -DENABLE_LTO=false && make VERBOSE=1 -j2
# softlink to build/ for cmake, since that's where the docker mount point is
cd src/
ln -s ../build CMakeFiles
cd ..
# run cmake separately so config.h will be seen by the md5 script
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GAME=true -DENABLE_SERVER=true -DENABLE_CAMPAIGN_SERVER=true -DENABLE_TESTS=true -DENABLE_NLS=false -DEXTRA_FLAGS_CONFIG="-pipe" -DEXTRA_FLAGS_RELEASE="$EXTRA_FLAGS_RELEASE" -DENABLE_STRICT_COMPILATION="$STRICT" -DENABLE_LTO=false
# run manual md5 file tracking/mtime modification script for cmake
python3 cmake_mtime_crc.py
make VERBOSE=1 -j2
else
scons wesnoth wesnothd campaignd boost_unit_tests build=release ctool=$CC cxxtool=$CXX --debug=time extra_flags_config="-pipe" extra_flags_release="$EXTRA_FLAGS_RELEASE" strict="$STRICT" cxx_std=$CXXSTD nls=false jobs=2 enable_lto=false
fi