Last active
October 20, 2016 13:27
-
-
Save josuigoa/575f5bdf0e119d871b70c33e1c25e63e to your computer and use it in GitHub Desktop.
This macro saves the libraries versions used in the current build in a file. If the lib is a git repo, you get the commit hashes and the commit message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package macros; | |
using StringTools; | |
typedef LibVer = { | |
var name:String; | |
var version:String; | |
} | |
class LibraryParser { | |
static public function parse() { | |
var libs = haxe.macro.Context.getDefines(); | |
// regular expression to match library format x.x.xxxx | |
// matched: 3.2.205, 0.0.0, 0.1.3-alpha | |
// not matched: 1, true, 1.0 | |
var ereg = ~/[0-9]+\.[0-9]+\.[0-9\w-\.]+/; | |
var v = '', lib_versions = new Array<LibVer>(); | |
for (l in libs.keys()) { | |
v = libs.get(l); | |
if (l == 'haxe_ver') | |
lib_versions.push({name:'Haxe', version:v}); | |
else if (ereg.match(Std.string(v))) | |
lib_versions.push({name:l, version:get_lib_version(l, v)}); | |
} | |
haxe.ds.ArraySort.sort(lib_versions, function(a, b) if (a.name<=b.name) return -1 else return 1); | |
var fc = 'Used library versions: \n'; | |
for (lv in lib_versions) { | |
fc += 'Library: ${lv.name}\nVersion: ' + lv.version + '\n------------\n'; | |
} | |
var dir = Sys.getCwd() + 'lib_versions'; | |
if (!sys.FileSystem.exists(dir)) sys.FileSystem.createDirectory(dir); | |
var today = DateTools.format(Date.now(), "%Y-%m-%d"); | |
if (sys.FileSystem.exists(dir+'/'+today)) { | |
if (sys.io.File.getContent(dir+'/'+today) == fc) { | |
trace('same file content, not saving'); | |
} else { | |
today = Date.now().toString().replace(':', '.'); | |
trace('some library has changed, saving ${dir}/${today}'); | |
sys.io.File.saveContent(dir+'/'+today, fc); | |
} | |
} else { | |
sys.io.File.saveContent(dir+'/'+today, fc); | |
} | |
} | |
static function get_lib_version(_lib_name:String, _lib_version:String) : String { | |
var process = new sys.io.Process('haxelib', ['path', _lib_name]); | |
var msg, pos; | |
if (process.exitCode() != 0) { | |
msg = process.stderr.readAll().toString(); | |
pos = haxe.macro.Context.currentPos(); | |
haxe.macro.Context.error("Cannot execute `haxelib path " + _lib_name + "`. " + msg, pos); | |
} | |
var out = process.stdout.readAll().toString().split('\n'); | |
var path = ''; | |
for (o in out) { | |
// get rid of the results starting with '-' character (e.g. -L or -D) | |
if (!o.startsWith('-')) { | |
path = o.rtrim(); | |
break; | |
} | |
} | |
process.close(); | |
if (path != '' && (path.indexOf('\\git\\') != -1 || path.indexOf('/git/') != -1)) { | |
// process = new sys.io.Process('git', ['--git-dir', path+'.git', 'rev-parse', 'HEAD']); | |
process = new sys.io.Process('git', ['--git-dir', path+'.git', 'log', '-1', '--pretty=GIT->commit hash: %H / abbreviation: %h\nLast commit: "%s"']); | |
// process = new sys.io.Process('git', ['--git-dir', path+'.git', 'log', '-1']); | |
if (process.exitCode() != 0) { | |
var message = process.stderr.readAll().toString(); | |
var pos = haxe.macro.Context.currentPos(); | |
haxe.macro.Context.error("Cannot execute `git --git-dir " + path + ".git log -1 --pretty=GIT->commit hash: %H / abbreviation: %h\nLast commit: \"%s\"`. " + message, pos); | |
} | |
var info = process.stdout.readAll().toString(); | |
process.close(); | |
return info; | |
} | |
return _lib_version; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Used library versions: | |
Library: Haxe | |
Version: 3.201 | |
------------ | |
Library: hxcpp | |
Version: 3.2.205 | |
------------ | |
Library: linc_ogg | |
Version: GIT->commit hash: ad92bef61f1a8eef30c55e5b4b1c341de1f69697 / abbreviation: ad92bef | |
Last commit: "linc; don't apply touch/xml macros during completion" | |
------------ | |
Library: linc_openal | |
Version: GIT->commit hash: 525642c7cf2a06752f8e5f7c8dad92c63d87267a / abbreviation: 525642c | |
Last commit: "add more todo notes" | |
------------ | |
Library: linc_opengl | |
Version: GIT->commit hash: 1d97f488c6ac7b78353835d05f36dbb4c6a85ca5 / abbreviation: 1d97f48 | |
Last commit: "add workaround for hxcpp discarding the @:include meta" | |
------------ | |
Library: linc_sdl | |
Version: GIT->commit hash: 25a89e75834366fe148307c08bcca646eabca059 / abbreviation: 25a89e7 | |
Last commit: "fix #16, blitSurface" | |
------------ | |
Library: linc_stb | |
Version: GIT->commit hash: 05bd1c90d1f7bdd9547e3f44c1ca28bb8b0d2152 / abbreviation: 05bd1c9 | |
Last commit: "Fixes byte array size when using default req_comp value" | |
------------ | |
Library: linc_timestamp | |
Version: GIT->commit hash: 3592c5659ddfbe5de1a2c91980a75c1025b28f14 / abbreviation: 3592c56 | |
Last commit: "remove redundant value/call" | |
------------ | |
Library: luxe | |
Version: GIT->commit hash: 497bb08f9ba452a99927d9aa17c0cf41bdbef33d / abbreviation: 497bb08 | |
Last commit: "tests; add example of using a custom OS level cursor on desktop + web platforms" | |
------------ | |
Library: snow | |
Version: GIT->commit hash: e26fedd45dbd79c52ad2aade8ec8acc2c414c40c / abbreviation: e26fedd | |
Last commit: "web; audio; avoid trying to load or use the context if unavailable" | |
------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment