Sat, 03 Aug 2019 01:18:56 +0300
add version
.hgignore | file | annotate | diff | comparison | revisions | |
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/version.cpp | file | annotate | diff | comparison | revisions | |
src/version.h | file | annotate | diff | comparison | revisions | |
tools/outputfile.py | file | annotate | diff | comparison | revisions | |
tools/updaterevision.py | file | annotate | diff | comparison | revisions |
--- a/.hgignore Fri Aug 02 21:29:06 2019 +0300 +++ b/.hgignore Sat Aug 03 01:18:56 2019 +0300 @@ -1,2 +1,3 @@ syntax:glob CMakeLists.txt.user +__pycache__
--- a/CMakeLists.txt Fri Aug 02 21:29:06 2019 +0300 +++ b/CMakeLists.txt Sat Aug 03 01:18:56 2019 +0300 @@ -11,29 +11,31 @@ endif() set (CMAKE_AUTOMOC ON) find_package (OpenGL REQUIRED) -# add_custom_target (revision_check ALL -# COMMAND python3 "${CMAKE_SOURCE_DIR}/tools/updaterevision.py" --cwd "$(CMAKE_SOURCE_DIR)" hginfo.h -# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +add_custom_target (revision_check ALL + COMMAND python3 "${CMAKE_SOURCE_DIR}/tools/updaterevision.py" --cwd "$(CMAKE_SOURCE_DIR)" hginfo.h + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) include_directories (${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}) # set_source_files_properties (${CMAKE_BINARY_DIR}/configuration.cpp PROPERTIES GENERATED TRUE) # set_property(SOURCE configuration.cpp PROPERTY SKIP_AUTOMOC ON) set (LDFORGE_SOURCES src/main.cpp - src/mainwindow.cpp + src/mainwindow.cpp + src/version.cpp ) set (LDFORGE_HEADERS src/main.h - src/mainwindow.h + src/mainwindow.h + src/version.h ) set (LDFORGE_FORMS - src/mainwindow.ui + src/mainwindow.ui ) # set (LDFORGE_OTHER_FILES # src/configurationoptions.txt # data/primitive-categories.cfg # ) set (LDFORGE_RESOURCES ldforge.qrc) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) include_directories ("${PROJECT_BINARY_DIR}") @@ -69,5 +71,6 @@ # --sourcedir ${CMAKE_SOURCE_DIR}/src # ${CMAKE_SOURCE_DIR}/src/configurationoptions.txt # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -add_dependencies (ldforge revision_check config_collection) +add_dependencies (ldforge revision_check) +#add_dependencies (ldforge config_collection) install (TARGETS ldforge RUNTIME DESTINATION bin)
--- a/src/mainwindow.cpp Fri Aug 02 21:29:06 2019 +0300 +++ b/src/mainwindow.cpp Sat Aug 03 01:18:56 2019 +0300 @@ -1,12 +1,17 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "version.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}, ui{*new Ui_MainWindow} { - ui.setupUi(this); - connect(ui.actionQuit, &QAction::triggered, this, &QMainWindow::close); + ui.setupUi(this); + connect(ui.actionQuit, &QAction::triggered, this, &QMainWindow::close); + QString title = ::appName; + title += " "; + title += fullVersionString(); + setWindowTitle(title); } MainWindow::~MainWindow()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/version.cpp Sat Aug 03 01:18:56 2019 +0300 @@ -0,0 +1,47 @@ +#include <QString> +#include <time.h> +#include "version.h" +#include "hginfo.h" + +static QString makeVersionString(const Version &version) +{ + QString result = QString::number(version.major) + "." + QString::number(version.minor); + if (version.patch != 0) { + result += "."; + result += QString::number(version.patch); + } + return result; +} + +const QString& fullVersionString() +{ +#ifdef HG_DATE_VERSION + if (::buildType != ReleaseBuild) { + static const QString result = makeVersionString(::version) + "-" HG_DATE_VERSION; + return result; + } +#else + static const QString result = makeVersionString(::version); + return result; +#endif +} + +static QString makeCommitTimeString() +{ + QString result; +#ifdef HG_DATE_TIME + { + char buffer[100]; + constexpr time_t timestamp = HG_DATE_TIME; + strftime (buffer, sizeof buffer, "%d %b %Y", localtime (×tamp)); + result += buffer; + } +#endif + return result; +} + +const QString &commitTimeString() +{ + static QString result = makeCommitTimeString(); + return result; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/version.h Sat Aug 03 01:18:56 2019 +0300 @@ -0,0 +1,45 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2018 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QString> + +const char appName[] = "LDForge"; +const char unixName[] = "ldforge"; + +struct Version { + int major; + int minor; + int patch = 0; +}; + +enum BuildType {InternalBuild, ReleaseBuild}; + +constexpr Version version = {1, 0}; +constexpr BuildType buildType = InternalBuild; + +#ifdef DEBUG +# undef RELEASE +#endif // DEBUG + +#ifdef RELEASE +# undef DEBUG +#endif // RELEASE + +const QString& fullVersionString(); +const QString& commitTimeString();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/outputfile.py Sat Aug 03 01:18:56 2019 +0300 @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# coding: utf-8 +# +# Copyright 2015 Teemu Piippo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +class OutputFile: + def __init__ (self, filename): + self.filename = filename + try: + with open (self.filename, "r") as file: + self.oldsum = file.readline() + self.oldsum = self.oldsum.replace ('// ', '').strip() + except IOError: + self.oldsum = '' + self.body = '' + + def write(self, text): + self.body += text + + def save(self, verbose = False): + from hashlib import sha256 + checksum = sha256(self.body.encode('utf-8')).hexdigest() + if checksum == self.oldsum: + if verbose: + print ('%s is up to date' % self.filename) + pass + else: + with open (self.filename, "w") as file: + file.write('// %s\n' % checksum) + file.write('// This file has been automatically generated. Do not edit by hand\n') + file.write('\n') + file.write(self.body) + if verbose: + print('%s written' % self.filename)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/updaterevision.py Sat Aug 03 01:18:56 2019 +0300 @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# coding: utf-8 +# +# Copyright 2015 Teemu Piippo +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +import argparse +import outputfile + +def main(): + import subprocess + from datetime import datetime + parser = argparse.ArgumentParser(description='Writes a header file with Hg commit information') + parser.add_argument('--cwd', default = '.') + parser.add_argument('output') + args = parser.parse_args() + f = outputfile.OutputFile(args.output) + data = subprocess.check_output(['hg', 'log', '--cwd', args.cwd, '-r.', '--template', + '{node|short} {branch} {date|hgdate}']).decode().replace('\n', '').split(' ') + + rev = data[0] + branch = data[1] + timestamp = int(data[2]) + date = datetime.utcfromtimestamp(timestamp) + datestring = date.strftime('%y%m%d-%H%M') if date.year >= 2000 else '000000-0000' + + if len(rev) > 7: + rev = rev[0:7] + + if subprocess.check_output(['hg', 'id', '--cwd', args.cwd, '-n']).decode().replace('\n', '').endswith('+'): + rev += '+' + + f.write('#define HG_NODE "%s"\n' % rev) + f.write('#define HG_BRANCH "%s"\n' % branch) + f.write('#define HG_DATE_VERSION "%s"\n' % datestring) + f.write('#define HG_DATE_STRING "%s"\n' % date.strftime('%d %b %Y')) + f.write('#define HG_DATE_TIME %d\n' % int(timestamp)) + if f.save(): + print('%s updated to %s' %(f.filename, rev)) + +if __name__ == '__main__': + main()