Detect git revision and have version shown
This commit is contained in:
parent
35560566d1
commit
e1633750a9
9 changed files with 113 additions and 2 deletions
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
buildaux/version.cpp export-subst
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@ docs
|
||||||
rom
|
rom
|
||||||
/core
|
/core
|
||||||
src/fonts/font.cpp
|
src/fonts/font.cpp
|
||||||
|
src/core/version.cpp
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -7,6 +7,7 @@ FONT_SRC := unifontfull-5.1.20080820.hex
|
||||||
#Compilers.
|
#Compilers.
|
||||||
CC := g++
|
CC := g++
|
||||||
REALCC = $(CROSS_PREFIX)$(CC)
|
REALCC = $(CROSS_PREFIX)$(CC)
|
||||||
|
HOSTCC = $(CC)
|
||||||
|
|
||||||
#Flags.
|
#Flags.
|
||||||
HOSTCCFLAGS = -std=gnu++0x
|
HOSTCCFLAGS = -std=gnu++0x
|
||||||
|
@ -23,7 +24,7 @@ JOYSTICK = SDL
|
||||||
#Core objects and what to build.
|
#Core objects and what to build.
|
||||||
CORE_OBJECTS = $(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard src/core/*.cpp)) \
|
CORE_OBJECTS = $(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard src/core/*.cpp)) \
|
||||||
$(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard avi/*.cpp)) \
|
$(patsubst %.cpp,%.$(OBJECT_SUFFIX),$(wildcard avi/*.cpp)) \
|
||||||
src/fonts/font.$(OBJECT_SUFFIX)
|
src/fonts/font.$(OBJECT_SUFFIX) src/core/version.$(OBJECT_SUFFIX)
|
||||||
PROGRAMS = lsnes.$(EXECUTABLE_SUFFIX) movieinfo.$(EXECUTABLE_SUFFIX) lsnes-dumpavi.$(EXECUTABLE_SUFFIX) sdmp2sox.$(EXECUTABLE_SUFFIX)
|
PROGRAMS = lsnes.$(EXECUTABLE_SUFFIX) movieinfo.$(EXECUTABLE_SUFFIX) lsnes-dumpavi.$(EXECUTABLE_SUFFIX) sdmp2sox.$(EXECUTABLE_SUFFIX)
|
||||||
all: $(PROGRAMS)
|
all: $(PROGRAMS)
|
||||||
|
|
||||||
|
@ -160,5 +161,13 @@ src/fonts/font.$(OBJECT_SUFFIX): src/fonts/$(FONT_SRC)
|
||||||
echo ";" >>src/fonts/font.cpp
|
echo ";" >>src/fonts/font.cpp
|
||||||
$(REALCC) $(CORE_CFLAGS) -c -o $@ src/fonts/font.cpp
|
$(REALCC) $(CORE_CFLAGS) -c -o $@ src/fonts/font.cpp
|
||||||
|
|
||||||
|
#Version info.
|
||||||
|
buildaux/version.exe: buildaux/version.cpp VERSION
|
||||||
|
$(HOSTCC) $(HOSTCCFLAGS) -o $@ $<
|
||||||
|
src/core/version.cpp: buildaux/version.exe FORCE
|
||||||
|
buildaux/version.exe >$@
|
||||||
|
|
||||||
|
.PHONY: FORCE
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(PROGRAMS) src/*.$(OBJECT_SUFFIX) src/*/*.$(OBJECT_SUFFIX) avi/*.$(OBJECT_SUFFIX) src/fonts/font.o src/fonts/font.cpp
|
rm -f $(PROGRAMS) src/*.$(OBJECT_SUFFIX) src/*/*.$(OBJECT_SUFFIX) avi/*.$(OBJECT_SUFFIX) src/fonts/font.o src/fonts/font.cpp
|
||||||
|
|
1
VERSION
Normal file
1
VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1-β3
|
85
buildaux/version.cpp
Normal file
85
buildaux/version.cpp
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
std::string X = "$Format:%h by %cn on %ci$";
|
||||||
|
|
||||||
|
std::string derive_format(std::string kwformat)
|
||||||
|
{
|
||||||
|
if(kwformat[0] != '$' || kwformat[1] != 'F' || kwformat[kwformat.length() - 1] != '$') {
|
||||||
|
std::cerr << "Bad keyword format '" << kwformat << "'" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return "--pretty=f" + kwformat.substr(2, kwformat.length() - 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string shellquote(std::string arg)
|
||||||
|
{
|
||||||
|
std::ostringstream x;
|
||||||
|
x << "'";
|
||||||
|
for(size_t i = 0; i < arg.length(); i++) {
|
||||||
|
if(arg[i] == '\'')
|
||||||
|
x << "\\'";
|
||||||
|
else
|
||||||
|
x << arg[i];
|
||||||
|
}
|
||||||
|
x << "'";
|
||||||
|
return x.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string runlog(std::string logformat)
|
||||||
|
{
|
||||||
|
std::string command = "git log " + shellquote(logformat) + " -1";
|
||||||
|
std::string retval;
|
||||||
|
int r;
|
||||||
|
char buf[4096] = {0};
|
||||||
|
FILE* out = popen(command.c_str(), "r");
|
||||||
|
if(!out) {
|
||||||
|
std::cerr << "Can't invoke git to get the version" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
while((r = fread(buf, 1, 4095, out)) > 0) {
|
||||||
|
buf[r] = 0;
|
||||||
|
retval = retval + buf;
|
||||||
|
}
|
||||||
|
if(ferror(out)) {
|
||||||
|
std::cerr << "Error reading git version output" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
pclose(out);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_main_version()
|
||||||
|
{
|
||||||
|
std::ifstream x("VERSION");
|
||||||
|
if(!x) {
|
||||||
|
std::cerr << "Error reading main version" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
std::string out;
|
||||||
|
std::getline(x, out);
|
||||||
|
if(out == "") {
|
||||||
|
std::cerr << "Error reading main version" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::string gitversion;
|
||||||
|
std::string mainversion = get_main_version();
|
||||||
|
if(X[0] == '$') {
|
||||||
|
std::string logformat = derive_format(X);
|
||||||
|
gitversion = runlog(logformat);
|
||||||
|
} else
|
||||||
|
gitversion = X;
|
||||||
|
std::cout << "#include <string>" << std::endl;
|
||||||
|
std::cout << "std::string lsnes_git_revision = \"" << gitversion << "\";" << std::endl;
|
||||||
|
std::cout << "std::string lsnes_version = \"" << mainversion << "\";" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -15,5 +15,6 @@
|
||||||
|
|
||||||
extern std::string bsnes_core_version;
|
extern std::string bsnes_core_version;
|
||||||
extern std::string lsnes_version;
|
extern std::string lsnes_version;
|
||||||
|
extern std::string lsnes_git_revision;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -307,4 +307,3 @@ std::string format_address(void* addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bsnes_core_version;
|
std::string bsnes_core_version;
|
||||||
std::string lsnes_version = "1-β3";
|
|
||||||
|
|
|
@ -144,6 +144,11 @@ int main(int argc, char** argv)
|
||||||
std::vector<std::string> cmdline;
|
std::vector<std::string> cmdline;
|
||||||
for(int i = 1; i < argc; i++)
|
for(int i = 1; i < argc; i++)
|
||||||
cmdline.push_back(argv[i]);
|
cmdline.push_back(argv[i]);
|
||||||
|
if(cmdline.size() == 1 && cmdline[0] == "--version") {
|
||||||
|
std::cout << "lsnes rr" << lsnes_version << " (" << lsnes_git_revision << ")" << std::endl;
|
||||||
|
std::cout << snes_library_id() << " (" << SNES::Info::Profile << " core)" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
my_interfaced intrf;
|
my_interfaced intrf;
|
||||||
SNES::interface = &intrf;
|
SNES::interface = &intrf;
|
||||||
|
|
||||||
|
|
|
@ -775,6 +775,8 @@ wxwin_mainwindow::wxwin_mainwindow()
|
||||||
menu_entry(wxID_EDIT_AUTHORS, wxT("&Edit game name && authors"));
|
menu_entry(wxID_EDIT_AUTHORS, wxT("&Edit game name && authors"));
|
||||||
menu_separator();
|
menu_separator();
|
||||||
menu_entry(wxID_EXIT, wxT("&Quit"));
|
menu_entry(wxID_EXIT, wxT("&Quit"));
|
||||||
|
menu_separator();
|
||||||
|
menu_entry(wxID_ABOUT, wxT("About"));
|
||||||
//File menu: (ACFOS)DELMNPRTV
|
//File menu: (ACFOS)DELMNPRTV
|
||||||
menu_start(wxT("&File"));
|
menu_start(wxT("&File"));
|
||||||
menu_entry_check(wxID_READONLY_MODE, wxT("Reado&nly mode"));
|
menu_entry_check(wxID_READONLY_MODE, wxT("Reado&nly mode"));
|
||||||
|
@ -1001,6 +1003,13 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
|
||||||
case wxID_LOAD_MEMORYWATCH:
|
case wxID_LOAD_MEMORYWATCH:
|
||||||
menu_load_memorywatch(e);
|
menu_load_memorywatch(e);
|
||||||
break;
|
break;
|
||||||
|
case wxID_ABOUT: {
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "lsnes rr" << lsnes_version << " (" << lsnes_git_revision << ")" << std::endl;
|
||||||
|
str << bsnes_core_version << std::endl;
|
||||||
|
wxMessageBox(towxstring(str.str()), _T("About"), wxICON_INFORMATION | wxOK, this);
|
||||||
|
}
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue