Skip to content

Instantly share code, notes, and snippets.

@mash
Created April 23, 2013 01:15
Show Gist options
  • Select an option

  • Save mash/5440062 to your computer and use it in GitHub Desktop.

Select an option

Save mash/5440062 to your computer and use it in GitHub Desktop.
string cmd, s, version;
int count = 0;
string git_dir = argv[ 1 ];
string stdout = "debug.log";
string revision_file = "git-revision.log";
string GitRevision () {
if ( version ) {
return version;
}
string git_cmd = "git --git-dir=";
git_cmd += git_dir;
git_cmd += " rev-parse --short HEAD > ";
git_cmd += revision_file;
int result = system( git_cmd );
if ( result ) {
dlgMessageBox( "git rev-parse failed" );
exit( -1 );
}
fileread( version, revision_file );
return version;
}
if ( ! git_dir ) {
dlgMessageBox( "provide .git directory as an argument", "OK" );
exit( -1 );
}
output( stdout, "wt" ) {
if (schematic) {
schematic(S) {
S.parts( P) {
if ( P.device && P.device.name && ! strstr(P.device.name, "GIT-REVISION") ) {
sprintf( s, "VALUE %s %s\n", P.name, GitRevision() );
cmd += s;
count ++;
}
}
}
}
}
if ( ! count ) {
dlgMessageBox( "device named \"GIT-REVISION\" not found", "OK" );
exit( -1 );
}
exit( cmd );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment