Skip to content

Commit

Permalink
Add util/git_info
Browse files Browse the repository at this point in the history
Removes need to force-compile main and all report files to get updated
git revision info.
  • Loading branch information
scamille committed Feb 8, 2018
1 parent 8893616 commit dbade82
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 45 deletions.
10 changes: 2 additions & 8 deletions engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,9 @@ $(OBJ_DIR)$(PATHSEP)%.$(OBJ_EXT): %.cpp $(SRC_H)
-@echo [$(MODULE)] Compiling $(notdir $<)
$(CXX) $(CPP_FLAGS) $(OPTS) -S $< -o $@

# Force regeneration of sc_main.o on every recompilation to potntially get the
# Force regeneration of git_info.o on every recompilation to potntially get the
# changed GIT shorthash into the binary
sc_main.o: .FORCE

report/sc_report_html_sim.o: .FORCE

report/sc_report_json.o: .FORCE

report/sc_report_xml.o: .FORCE
util/git_info.o: .FORCE

# cleanup targets
mostlyclean:
Expand Down
38 changes: 21 additions & 17 deletions engine/report/sc_report_html_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sc_report.hpp"
#include "data/report_data.inc"
#include "interfaces/sc_js.hpp"
#include "util/git_info.hpp"

// Experimental Raw Ability Output for Blizzard to do comparisons
namespace raw_ability_summary
Expand Down Expand Up @@ -1054,28 +1055,31 @@ void print_html_masthead( report::sc_html_stream& os, const sim_t& sim )

os.format(
"<span id=\"logo\"></span>\n"
"<h1><a href=\"%s\">SimulationCraft %s</a></h1>\n"
#if !defined( SC_GIT_REV )
"<h2>for World of Warcraft %s %s (wow build level %d)</h2>\n\n",
#else
"<h2>for World of Warcraft %s %s (wow build level %d, git build <a "
"href=\"%s\">%s</a>)</h2>\n\n",
#endif
"http://www.simulationcraft.org/", SC_VERSION, sim.dbc.wow_version(),
( sim.dbc.ptr ?
"<h1><a href=\"%s\">SimulationCraft %s</a></h1>\n",
"http://www.simulationcraft.org/", SC_VERSION);

const char* type = ( sim.dbc.ptr ?
#if SC_BETA
"BETA"
#else
"PTR"
#endif
: "Live" ),
#if !defined( SC_GIT_REV )
sim.dbc.build_level() );
#else
sim.dbc.build_level(),
"https://github.com/simulationcraft/simc/commit/" SC_GIT_REV,
SC_GIT_REV );
#endif
: "Live" );

if ( !git_info::available())
{
os.format(
"<h2>for World of Warcraft %s %s (wow build level %d)</h2>\n\n",
sim.dbc.wow_version(), type, sim.dbc.build_level());
}
else
{
std::string commit_link = "https://github.com/simulationcraft/simc/commit/";
commit_link += git_info::revision();
os.format("<h2>for World of Warcraft %s %s (wow build level %d, git build <a "
"href=\"%s\">%s</a>)</h2>\n\n",
sim.dbc.wow_version(), type, sim.dbc.build_level(), commit_link.c_str(), git_info::revision());
}

time_t rawtime;
time( &rawtime );
Expand Down
17 changes: 11 additions & 6 deletions engine/report/sc_report_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sc_report.hpp"
#include "interfaces/sc_js.hpp"
#include "simulationcraft.hpp"
#include "util/git_info.hpp"

#include "util/rapidjson/filewritestream.h"
#include "util/rapidjson/document.h"
Expand Down Expand Up @@ -1770,9 +1771,11 @@ js::sc_js_t get_root( const sim_t& sim )
{
js::sc_js_t root;
root.set( "version", SC_VERSION );
#if defined( SC_GIT_REV )
root.set( "git_rev", SC_GIT_REV );
#endif
if ( git_info::available())
{
root.set( "git_branch", git_info::branch() );
root.set( "git_rev", git_info::revision() );
}
root.set( "ptr_enabled", SC_USE_PTR );
root.set( "beta_enabled", SC_BETA );
root.set( "build_date", __DATE__ );
Expand All @@ -1794,9 +1797,11 @@ void print_json2_pretty( FILE* o, const sim_t& sim )
root[ "beta_enabled" ] = SC_BETA;
root[ "build_date" ] = __DATE__;
root[ "build_time" ] = __TIME__;
#if defined( SC_GIT_REV )
root[ "git_revision" ] = SC_GIT_REV;
#endif
if ( git_info::available())
{
root[ "git_revision" ] = git_info::revision();
root[ "git_branch" ] = git_info::branch();
}

to_json( root[ "sim" ], sim );

Expand Down
9 changes: 6 additions & 3 deletions engine/report/sc_report_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "sc_report.hpp"
#include <stack>
#include "simulationcraft.hpp"
#include "util/git_info.hpp"

namespace
{ // UNNAMED NAMESPACE ==========================================
Expand Down Expand Up @@ -1524,9 +1525,11 @@ void print_xml( sim_t* sim )
writer.print_attribute( "ptr", sim->dbc.ptr ? "true" : "false" );
writer.print_attribute( "wow_build",
util::to_string( sim->dbc.build_level() ) );
#if defined( SC_GIT_REV )
writer.print_attribute( "sc_git_build", SC_GIT_REV );
#endif
if ( git_info::available())
{
writer.print_attribute( "sc_git_branch", git_info::branch() );
writer.print_attribute( "sc_git_build", git_info::revision() );
}

#if SC_BETA

Expand Down
12 changes: 8 additions & 4 deletions engine/sc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ==========================================================================

#include "simulationcraft.hpp"
#include "util/git_info.hpp"
#include "sim/sc_profileset.hpp"
#include <locale>

Expand Down Expand Up @@ -248,13 +249,16 @@ int sim_t::main( const std::vector<std::string>& args )
setup_success = false;
}

#if ! defined( SC_GIT_REV )
if ( !git_info::available() )
{
util::printf("SimulationCraft %s for World of Warcraft %s %s (wow build %s)\n",
SC_VERSION, dbc.wow_version(), dbc.wow_ptr_status(), util::to_string(dbc.build_level()).c_str());
#else
}
else
{
util::printf("SimulationCraft %s for World of Warcraft %s %s (wow build %s, git build %s %s)\n",
SC_VERSION, dbc.wow_version(), dbc.wow_ptr_status(), util::to_string(dbc.build_level()).c_str(), SC_GIT_BRANCH, SC_GIT_REV);
#endif
SC_VERSION, dbc.wow_version(), dbc.wow_ptr_status(), util::to_string(dbc.build_level()).c_str(), git_info::branch(), git_info::revision());
}

if ( display_hotfixes )
{
Expand Down
40 changes: 40 additions & 0 deletions engine/util/git_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================

#include "git_info.hpp"

#if defined( SC_GIT_REV ) && defined( SC_GIT_BRANCH )

bool git_info::available()
{
return true;
}
const char* git_info::revision()
{
return SC_GIT_REV;
}

const char* git_info::branch()
{
return SC_GIT_BRANCH;
}

#else

bool git_info::available()
{
return false;
}
const char* git_info::revision()
{
return "";
}

const char* git_info::branch()
{
return "";
}

#endif
15 changes: 15 additions & 0 deletions engine/util/git_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================

#pragma once

namespace git_info {
/// True if git revision information is available
bool available();
/// git revision in short form
const char* revision();
/// current git branch
const char* branch();
}
20 changes: 13 additions & 7 deletions qt/sc_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "sc_WelcomeTab.hpp"
#include "sc_AddonImportTab.hpp"
#include "util/sc_mainwindowcommandline.hpp"
#include "util/git_info.hpp"
#ifdef SC_PAPERDOLL
#include "sc_PaperDoll.hpp"
#endif
Expand Down Expand Up @@ -797,13 +798,18 @@ void SC_MainWindow::startSim()

QString tab_name = std::get<0>( value );
auto simc_gui_profile = std::get<1>( value );
#if ! defined( SC_GIT_REV )
auto simc_version = QString("### SimulationCraft %1 for World of Warcraft %2 %3 (wow build %4) ###\n\n").
arg(SC_VERSION).arg(sim->dbc.wow_version()).arg(sim->dbc.wow_ptr_status()).arg(sim->dbc.build_level());
#else
auto simc_version = QString("### SimulationCraft %1 for World of Warcraft %2 %3 (wow build %4, git build %5) ###\n\n").
arg(SC_VERSION).arg(sim->dbc.wow_version()).arg(sim->dbc.wow_ptr_status()).arg(sim->dbc.build_level()).arg(SC_GIT_REV);
#endif
QString simc_version;
if ( !git_info::available())
{
simc_version = QString("### SimulationCraft %1 for World of Warcraft %2 %3 (wow build %4) ###\n\n").
arg(SC_VERSION).arg(sim->dbc.wow_version()).arg(sim->dbc.wow_ptr_status()).arg(sim->dbc.build_level());
}
else
{
simc_version = QString("### SimulationCraft %1 for World of Warcraft %2 %3 (wow build %4, git build %5 %6) ###\n\n").
arg(SC_VERSION).arg(sim->dbc.wow_version()).arg(sim->dbc.wow_ptr_status()).arg(sim->dbc.build_level()).
arg(git_info::branch()).arg(git_info::revision());
}
simc_gui_profile = simc_version + simc_gui_profile;
QByteArray utf8_profile = simc_gui_profile.toUtf8();
QFile file( AppDataDir + QDir::separator() + "simc_gui.simc" );
Expand Down
1 change: 1 addition & 0 deletions source_files/QT_engine.pri
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
SOURCES += engine/util/rng.cpp
SOURCES += engine/util/io.cpp
SOURCES += engine/util/concurrency.cpp
SOURCES += engine/util/git_info.cpp
SOURCES += engine/sim/x7_pantheon.cpp
SOURCES += engine/sim/sc_sim.cpp
SOURCES += engine/sim/sc_scaling.cpp
Expand Down
3 changes: 3 additions & 0 deletions source_files/VS_engine.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ To change the list of source files, update the QT_ files and run synchronize.py
<ClCompile Include="..\engine\util\concurrency.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\engine\util\git_info.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\engine\sim\x7_pantheon.cpp">

</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions source_files/engine_make
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SRC += \
util$(PATHSEP)rng.cpp \
util$(PATHSEP)io.cpp \
util$(PATHSEP)concurrency.cpp \
util$(PATHSEP)git_info.cpp \
sim$(PATHSEP)x7_pantheon.cpp \
sim$(PATHSEP)sc_sim.cpp \
sim$(PATHSEP)sc_scaling.cpp \
Expand Down

0 comments on commit dbade82

Please sign in to comment.