From 0cb66411aad82f7bf9fa20e4942be9bacefcfa86 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 9 Feb 2015 20:15:00 -0800 Subject: [PATCH] Adding more generation debug output - Adding latest kll git commit rev - Adding list of changed files since latest git rev - Adding list of all command line arguments during generation - Adding generation timestamp - Updating copyrights --- backends/kiibohd.py | 30 ++++++++++++++++++++++++----- kll.py | 40 +++++++++++++++++++++++++++++++++++++-- templates/kiibohdDefs.h | 2 +- templates/kiibohdKeymap.h | 2 +- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/backends/kiibohd.py b/backends/kiibohd.py index c035fb2..19168a2 100644 --- a/backends/kiibohd.py +++ b/backends/kiibohd.py @@ -3,7 +3,7 @@ # # Backend code generator for the Kiibohd Controller firmware. # -# Copyright (C) 2014 by Jacob Alexander +# Copyright (C) 2014-2015 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -24,6 +24,8 @@ import os import sys import re +from datetime import date + # Modifying Python Path, which is dumb, but the only way to import up one directory... sys.path.append( os.path.expanduser('..') ) @@ -72,6 +74,7 @@ class Backend: return "usbKeyOut"; + # TODO def layerInformation( self, name, date, author ): self.fill_dict['Information'] += "// Name: {0}\n".format( "TODO" ) self.fill_dict['Information'] += "// Version: {0}\n".format( "TODO" ) @@ -80,14 +83,31 @@ class Backend: # Processes content for fill tags and does any needed dataset calculations - def process( self, capabilities, macros, variables ): + def process( self, capabilities, macros, variables, gitRev, gitChanges ): + # Build string list of compiler arguments + compilerArgs = "" + for arg in sys.argv: + if "--" in arg or ".py" in arg: + compilerArgs += "// {0}\n".format( arg ) + else: + compilerArgs += "// {0}\n".format( arg ) + + # Build a string of modified files, if any + gitChangesStr = "\n" + if len( gitChanges ) > 0: + for gitFile in gitChanges: + gitChangesStr += "// {0}\n".format( gitFile ) + else: + gitChangesStr = " None\n" + ## Information ## # TODO self.fill_dict['Information'] = "// This file was generated by the kll compiler, DO NOT EDIT.\n" - self.fill_dict['Information'] += "// Generation Date: {0}\n".format( "TODO" ) - self.fill_dict['Information'] += "// Compiler arguments: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// Generation Date: {0}\n".format( date.today() ) self.fill_dict['Information'] += "// KLL Backend: {0}\n".format( "kiibohd" ) - self.fill_dict['Information'] += "// KLL Git Rev: {0}\n".format( "TODO" ) + self.fill_dict['Information'] += "// KLL Git Rev: {0}\n".format( gitRev ) + self.fill_dict['Information'] += "// KLL Git Changes:{0}".format( gitChangesStr ) + self.fill_dict['Information'] += "// Compiler arguments:\n{0}".format( compilerArgs ) self.fill_dict['Information'] += "//\n" self.fill_dict['Information'] += "// - Base Layer -\n" self.fill_dict['Information'] += "// - Default Layer -\n" diff --git a/kll.py b/kll.py index 401d22e..37cfd5f 100755 --- a/kll.py +++ b/kll.py @@ -2,7 +2,7 @@ # KLL Compiler # Keyboard Layout Langauge # -# Copyright (C) 2014 by Jacob Alexander +# Copyright (C) 2014-2015 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -558,11 +558,41 @@ def processKLLFile( filename ): print("Error parsing %s. %s" % (filename, e.msg), file=sys.stderr) sys.exit(1) + +### Misc Utility Functions ### + +def gitRevision( kllPath ): + import subprocess + + # Change the path to where kll.py is + origPath = os.getcwd() + os.chdir( kllPath ) + + # Just in case git can't be found + try: + # Get hash of the latest git commit + revision = subprocess.check_output( ['git', 'rev-parse', 'HEAD'] ).decode()[:-1] + + # Get list of files that have changed since the commit + changed = subprocess.check_output( ['git', 'diff-index', '--name-only', 'HEAD', '--'] ).decode().splitlines() + except: + revision = "" + changed = [] + + # Change back to the old working directory + os.chdir( origPath ) + + return revision, changed + + ### Main Entry Point ### if __name__ == '__main__': (baseFiles, defaultFiles, partialFileSets, backend_name, template, defines_template, output, defines_output) = processCommandLineArgs() + # Look up git information on the compiler + gitRev, gitChanges = gitRevision( os.path.dirname( os.path.realpath( __file__ ) ) ) + # Load backend module global backend backend_import = importlib.import_module( "backends.{0}".format( backend_name ) ) @@ -602,7 +632,13 @@ if __name__ == '__main__': macros_map.generate() # Process needed templating variables using backend - backend.process( capabilities_dict, macros_map, variables_dict ) + backend.process( + capabilities_dict, + macros_map, + variables_dict, + gitRev, + gitChanges + ) # Generate output file using template and backend backend.generate( output, defines_output ) diff --git a/templates/kiibohdDefs.h b/templates/kiibohdDefs.h index 3944da5..dd21fd0 100644 --- a/templates/kiibohdDefs.h +++ b/templates/kiibohdDefs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 by Jacob Alexander +/* Copyright (C) 2014-2015 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/templates/kiibohdKeymap.h b/templates/kiibohdKeymap.h index 0e42c45..d3bfe49 100644 --- a/templates/kiibohdKeymap.h +++ b/templates/kiibohdKeymap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 by Jacob Alexander +/* Copyright (C) 2014-2015 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by