Skip to content

Commit

Permalink
Use git-based versioning scheme
Browse files Browse the repository at this point in the history
We use a link to build_info to avoid regenerating every file depending on bot_const.h after every update.

Versioning based off of SourceMod.

Closes rcbotCheeseh#5.
  • Loading branch information
nosoop committed Aug 26, 2019
1 parent 5814fa7 commit b750eca
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 17 deletions.
6 changes: 6 additions & 0 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ class MMSConfig(object):
'-mmacosx-version-min=10.9',
]
# elif builder.target.platform == 'windows': # todo: implement MSVC support
cxx.includes += [
os.path.join(builder.buildPath, 'includes')
]

def HL2Compiler(self, context, sdk, arch):
compiler = context.cxx.clone()
Expand Down Expand Up @@ -362,6 +365,7 @@ class MMSConfig(object):
'-compatibility_version', '1.0.0',
'-current_version', self.productVersion
]
binary.compiler.sourcedeps += MMS.generated_headers

return binary

Expand Down Expand Up @@ -463,6 +467,8 @@ MMS.detectProductVersion()
MMS.detectSDKs()
MMS.configure()

MMS.generated_headers = builder.Build('versioning/AMBuildScript', { 'MMS': MMS })

BuildScripts = [
'AMBuilder',
'loader/AMBuilder'
Expand Down
4 changes: 4 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ mods_requiring_runcmd_overrides = [
# Make sure to edit PackageScript, which copies your files to their appropriate locations
# Simple extensions do not need to modify past this point.

# set up the build info
include_paths += [ os.path.join(builder.currentSourcePath, 'versioning'), ]
sourceFiles += [ os.path.join(builder.currentSourcePath, 'versioning', 'build_info.cpp'), ]

if os.path.isfile(os.path.join(builder.currentSourcePath, 'sdk', 'smsdk_ext.cpp')):
# Use the copy included in the project
# sourceFiles += [os.path.join('sdk', 'smsdk_ext.cpp')]
Expand Down
13 changes: 1 addition & 12 deletions utils/RCBot2_meta/bot_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,7 @@ typedef enum

#undef ENTINDEX
#define ENTINDEX(pEdict) engine->IndexOfEdict(pEdict)
/*
#define BUILDNAME "TF2/HL2DM/DOD:S"
#define BUILDVER "BETA"
#define BUILDNUM "365"*/
#define BOT_NAME "RCBot"
#ifdef __linux__
#define BOT_VER "TF2/HL2DM/DOD:S 1.04 META Linux 488-apg (merge) (BUILD " __DATE__ "-" __TIME__ ")" //bir3yk
#else
#define BOT_VER "TF2/HL2DM/DOD:S 1.04 META Win32 488-apg (merge) (BUILD " ## __DATE__ ## "-" ## __TIME__ ## ")"
#endif
#define BOT_NAME_VER "RCbot version"
#define BOT_VER_CVAR "rcbot_ver"

#define BOT_FOLDER "rcbot2"

typedef enum
Expand Down
12 changes: 7 additions & 5 deletions utils/RCBot2_meta/bot_plugin_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#include "bot_kv.h"
#include "bot_sigscan.h"

#include <build_info.h>

SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool);
Expand Down Expand Up @@ -99,7 +101,7 @@ RCBotPluginMeta g_RCBotPluginMeta;

PLUGIN_EXPOSE(RCBotPluginMeta, g_RCBotPluginMeta);

static ConVar rcbot2_ver_cvar(BOT_VER_CVAR, BOT_VER, FCVAR_REPLICATED, BOT_NAME_VER);
static ConVar rcbot2_ver_cvar("rcbot_ver", build_info::long_version, FCVAR_REPLICATED, "RCbot version");

CON_COMMAND(rcbotd, "access the bot commands on a server")
{
Expand Down Expand Up @@ -980,12 +982,12 @@ const char *RCBotPluginMeta::GetLicense()

const char *RCBotPluginMeta::GetVersion()
{
return "1.01 (r487-apg-ch)";
return build_info::short_version;
}

const char *RCBotPluginMeta::GetDate()
{
return __DATE__;
return build_info::date;
}

const char *RCBotPluginMeta::GetLogTag()
Expand All @@ -995,7 +997,7 @@ const char *RCBotPluginMeta::GetLogTag()

const char *RCBotPluginMeta::GetAuthor()
{
return "Cheeseh, RoboCop";
return build_info::authors;
}

const char *RCBotPluginMeta::GetDescription()
Expand All @@ -1010,7 +1012,7 @@ const char *RCBotPluginMeta::GetName()

const char *RCBotPluginMeta::GetURL()
{
return "http://rcbot.bots-united.com/";
return build_info::url;
}

#if defined SM_EXT
Expand Down
42 changes: 42 additions & 0 deletions versioning/AMBuildScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python:
import os, sys
import re

builder.SetBuildFolder('/')

includes = builder.AddFolder('includes/version')

argv = [
sys.executable,
os.path.join(builder.sourcePath, 'versioning', 'generate.py'),
os.path.join(builder.sourcePath),
os.path.join(builder.buildPath, 'includes'),
]
outputs = [
os.path.join(builder.buildFolder, 'includes', 'build_version_auto.h'),
]

with open(os.path.join(builder.sourcePath, '.git', 'HEAD')) as fp:
head_contents = fp.read().strip()
if re.search('^[a-fA-F0-9]{40}$', head_contents):
git_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD')
else:
git_state = head_contents.split(':')[1].strip()
git_head_path = os.path.join(builder.sourcePath, '.git', git_state)
if not os.path.exists(git_head_path):
git_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD')

sources = [
# This is a hack, but we need some way to only run this script when Git changes.
git_head_path,

# The script source is a dependency, of course...
argv[1]
]
cmd_node, output_nodes = builder.AddCommand(
inputs=sources,
argv=argv,
outputs=outputs
)

rvalue = output_nodes
12 changes: 12 additions & 0 deletions versioning/build_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "build_info.h"

// generated with versioning/generate.py, AMBuild handles this
#include <build_version_auto.h>

const char* build_info::authors = "Cheeseh, RoboCop, nosoop";
const char* build_info::url = "http://rcbot.bots-united.com/";

const char* build_info::long_version = "nosoop/rcbot2@" GIT_COMMIT_HASH;
const char* build_info::short_version = "nosoop@" GIT_COMMIT_SHORT_HASH;

const char* build_info::date = __DATE__;
14 changes: 14 additions & 0 deletions versioning/build_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __RCBOT_VERSION_STUB_H__
#define __RCBOT_VERSION_STUB_H__

namespace build_info {
extern const char* authors;
extern const char* url;

extern const char* long_version;
extern const char* short_version;

extern const char* date;
}

#endif
37 changes: 37 additions & 0 deletions versioning/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python3

import subprocess

output_filename = 'build_version_auto.h'

def git_version():
return subprocess.check_output(['git', 'log', '--pretty=format:%H', '-n', '1']).decode('ascii')

if __name__ == '__main__':
import argparse, re, collections, functools, os, textwrap
from string import Template

parser = argparse.ArgumentParser(description = "Generates git snapshot headers.",
usage = "%(prog)s [options]")

parser.add_argument('source_dir', help="Source directory")
parser.add_argument('output_dir', help="Output directory")

args = parser.parse_args()

source_directory = os.path.abspath(os.path.normpath(args.source_dir))
output_directory = os.path.normpath(args.output_dir)
with open(os.path.join(output_directory, output_filename), 'wt') as f:
values = {
'git_hash': git_version(),
'git_short_hash': git_version()[:8]
}
f.write(textwrap.dedent("""
#if defined _auto_version_included
#endinput
#endif
#define _auto_version_included
#define GIT_COMMIT_HASH "{git_hash}"
#define GIT_COMMIT_SHORT_HASH "{git_short_hash}"
""".format(**values))[1:])

0 comments on commit b750eca

Please sign in to comment.