diff --git a/site_scons/version.py b/site_scons/version.py index d8e4a07..e5c3a0b 100644 --- a/site_scons/version.py +++ b/site_scons/version.py @@ -1,62 +1,69 @@ # -*- coding: utf-8 -*- # @file # @section LICENSE # # Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne), # Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . import subprocess import base64 from functools import reduce def git(*args): - return subprocess.check_output(["git"] + list(args)) + try: + return subprocess.check_output(["git"] + list(args)) + except subprocess.CalledProcessError: + return "" def write_info_file(file_name, build_type="release"): header = '#include "tamaas_info.hh"\n\n' file_content = '' branch = git("rev-parse", "--abbrev-ref", "HEAD")[:-1] commit = git("rev-parse", branch)[:-1] file_content += \ 'std::string tamaas::TamaasInfo::build_type = "{}";\n'.format( build_type) file_content += \ 'std::string tamaas::TamaasInfo::branch = "{}";\n'.format(branch) file_content += \ 'std::string tamaas::TamaasInfo::commit = "{}";\n'.format(commit) diff = git("diff") diff += "|".encode('ascii') + git("diff", "--cached") file_content += \ 'std::string tamaas::TamaasInfo::diff = "{}";\n'.format( base64.b64encode(diff)) remotes = git('remote', '-v') - remotes_strings = filter(lambda x: x != '', remotes.splitlines()) - remotes_string = reduce(lambda x, y: x + '"{}\\n"\n'.format(y), - remotes_strings, "") + if remotes != "": + remotes_strings = filter(lambda x: x != '', remotes.splitlines()) + remotes_string = reduce(lambda x, y: x + '"{}\\n"\n'.format(y), + remotes_strings, "") + else: + remotes_string = '""' + file_content += \ 'std::string tamaas::TamaasInfo::remotes = {};\n'.format(remotes_string) with open(file_name, 'w') as file: file.write(header + file_content)