# 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
help="Specify .kll files to generate partial map, multiple files per flag.\n"
"Each -p defines another partial map.\n"
"Base .kll files (that define the scan code maps) must be defined for each partial map." )
- pArgs.add_argument( '-t', '--template', type=str, default="templates/kiibohdKeymap.h",
+ pArgs.add_argument( '-t', '--templates', type=str, nargs='+',
+ default=["templates/kiibohdKeymap.h", "templates/kiibohdDefs.h"],
help="Specify template used to generate the keymap.\n"
- "Default: templates/kiibohdKeymap.h" )
- pArgs.add_argument( '--defines-template', type=str, default="templates/kiibohdDefs.h",
- help="Specify template used to generate kll_defs.h.\n"
- "Default: templates/kiibohdDefs.h" )
- pArgs.add_argument( '-o', '--output', type=str, default="generatedKeymap.h",
+ "Default: templates/kiibohdKeymap.h templates/kiibohdDefs.h" )
+ pArgs.add_argument( '-o', '--outputs', type=str, nargs='+',
+ default=["generatedKeymap.h", "kll_defs.h"],
help="Specify output file. Writes to current working directory by default.\n"
- "Default: generatedKeymap.h" )
- pArgs.add_argument( '--defines-output', type=str, default="kll_defs.h",
- help="Specify output path for kll_defs.h. Writes to current working directory by default.\n"
- "Default: kll_defs.h" )
+ "Default: generatedKeymap.h kll_defs.h" )
pArgs.add_argument( '-h', '--help', action="help",
help="This message." )
for filename in partial:
checkFileExists( filename )
- return (baseFiles, defaultFiles, partialFileSets, args.backend, args.template, args.defines_template, args.output, args.defines_output)
+ return (baseFiles, defaultFiles, partialFileSets, args.backend, args.templates, args.outputs)
curLeafList[ leaf ] = 0
if leaf + 1 < len( curLeafList ):
curLeafList[ leaf + 1 ] += 1
- break
return expandedSequences
# Only convert if an integer, otherwise USB Code doesn't need converting
if isinstance( items[ variant ][ sequence ][ combo ], int ):
# Use backend capability name and a single argument
- items[ variant ][ sequence ][ combo ] = tuple( [ backend.usbCodeCapability(), tuple( [ items[ variant ][ sequence ][ combo ] ] ) ] )
+ items[ variant ][ sequence ][ combo ] = tuple( [ backend.usbCodeCapability(), tuple( [ hid_lookup_dictionary[ items[ variant ][ sequence ][ combo ] ] ] ) ] )
return items
data = file.read()
tokenSequence = tokenize( data )
#print ( pformat( tokenSequence ) ) # Display tokenization
- tree = parse( tokenSequence )
+ try:
+ tree = parse( tokenSequence )
+ except NoParseError as e:
+ 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 = "<no git>"
+ 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()
+ (baseFiles, defaultFiles, partialFileSets, backend_name, templates, outputs) = 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 ) )
- backend = backend_import.Backend( template, defines_template )
+ backend = backend_import.Backend( templates )
# Process base layout files
for filename in baseFiles:
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 )
+ backend.generate( outputs )
# Successful Execution
sys.exit( 0 )