Skip to content

Commit

Permalink
Refactored find external programs API. Removed 'env' parameter from T…
Browse files Browse the repository at this point in the history
…ool.setup() method. Added Tool.findProgramX methods.
  • Loading branch information
menify committed Jan 24, 2015
1 parent be3a1ef commit 8b8ad5a
Show file tree
Hide file tree
Showing 13 changed files with 285 additions and 167 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ Key features:
- Support any build target types (files, strings, URLs, remote resources etc.)
- Conditional options
- Scons like build scripts (but don't compatible)
- Tools are not part of the build tool
4 changes: 3 additions & 1 deletion aql/main/aql_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def main():
p.sort_stats('cumulative')
p.print_stats( prj_cfg.debug_profile_top )

return status
except (Exception, KeyboardInterrupt) as ex:
if with_backtrace:
err = traceback.format_exc()
Expand All @@ -314,5 +313,8 @@ def main():
err = toUnicode(ex)

eventAqlError( err )
status = 1

return status

#//===========================================================================//
12 changes: 8 additions & 4 deletions aql/main/aql_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2012-2014 The developers of Aqualid project
# Copyright (c) 2012-2015 The developers of Aqualid project
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
Expand Down Expand Up @@ -158,7 +158,7 @@ def _readConfig( config_file, cli_config, options, tools_path ):
class ProjectConfig( object ):

__slots__ = ('directory', 'makefile', 'targets', 'options', 'arguments',
'verbose', 'no_output', 'jobs', 'keep_going', 'search_up', 'tools_path',
'verbose', 'no_output', 'jobs', 'keep_going', 'search_up', 'tools_path', 'no_tool_errors',
'build_always', 'clean', 'status', 'list_options', 'list_tool_options', 'list_targets',
'debug_profile', 'debug_profile_top', 'debug_memory', 'debug_explain', 'debug_backtrace',
'force_lock', 'show_version',
Expand All @@ -185,6 +185,7 @@ def __init__( self, args = None ):
CLIOption( "-R", "--clean", "clean", bool, False, "Cleans targets." ),
CLIOption( "-n", "--status", "status", bool, False, "Print status of targets." ),
CLIOption( "-u", "--up", "search_up", bool, False, "Search up directory tree for a make file." ),
CLIOption( "-e", "--no-tool-errors", "no_tool_errors", bool, False, "Stop on any error during initialization of tools." ),

# CLIOption( "-b", "--build-directory", "build_dir", FilePath, 'output', "Build output path.", 'FILE PATH'),
CLIOption( "-I", "--tools-path", "tools_path", Paths, [], "Path to tools and setup scripts.", 'FILE PATH, ...'),
Expand Down Expand Up @@ -252,6 +253,7 @@ def __init__( self, args = None ):
self.makefile = cli_config.makefile
self.search_up = cli_config.search_up
self.tools_path = tools_path
self.no_tool_errors = cli_config.no_tool_errors
self.targets = cli_config.targets
self.verbose = cli_config.verbose
self.show_version = cli_config.version
Expand Down Expand Up @@ -420,9 +422,11 @@ def __addTool( self, tool_name, options ):
except KeyError:
pass

tool, tool_names, tool_options = self.tools.getTool( tool_name, options )
project = self.project

tool = ToolWrapper( tool, self.project, tool_options )
tool, tool_names, tool_options = self.tools.getTool( tool_name, options, project.config.no_tool_errors )

tool = ToolWrapper( tool, project, tool_options )

attrs = self.__dict__

Expand Down
89 changes: 65 additions & 24 deletions aql/main/aql_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@

__all__ = ( 'Tool', 'tool', 'toolSetup', 'getToolsManager', 'ErrorToolNotFound' )

import os
import sys

from aql.util_types import toSequence, AqlException
from aql.utils import logWarning, logError, loadModule, loadPackage, expandFilePath, findFiles, eventWarning, ErrorProgramNotFound

#noinspection PyStatementEffect
"""
1. Tool('c++')
1.1 Select first c++ tool
1.2 Get tool's options
1.3 Setup tool's options
1.4 Create tool
1.5 Add tool's builders
"""
from aql.utils import logWarning, logError, loadModule, loadPackage, expandFilePath, findFiles, eventWarning,\
findProgram, findPrograms, findOptionalProgram, findOptionalPrograms

#//===========================================================================//

Expand All @@ -43,8 +34,18 @@ def eventToolsUnableLoadModule( settings, module, err ):
#//===========================================================================//

@eventWarning
def eventToolsToolFailed( settings, tool_info ):
logError( "Failed to initialize tool: name: %s, class: %s" % (tool_info.names,tool_info.tool_class.__name__))
def eventToolsToolFailed( settings, ex, tool_info ):
tool_class = tool_info.tool_class
module = tool_class.__module__
try:
file = sys.modules[ module ].__file__
except Exception:
file = module[module.rfind('.') + 1:] + '.py'

names = ','.join( tool_info.names )

logError( "Failed to initialize tool: name: %s, class: %s, file: %s" % (names, tool_class.__name__, file ))
logError( ex )

#//===========================================================================//

Expand Down Expand Up @@ -148,6 +149,7 @@ def addSetup( self, setup_method, names ):
def loadTools( self, paths ):

for path in toSequence( paths ):

path = expandFilePath( path )

if path in self.loaded_paths:
Expand Down Expand Up @@ -208,7 +210,7 @@ def __getToolInfoList( self, name ):

#//=======================================================//

def getTool( self, tool_name, options ):
def getTool( self, tool_name, options, no_errors = False ):

tool_info_list = self.__getToolInfoList( tool_name )

Expand All @@ -222,26 +224,26 @@ def getTool( self, tool_name, options ):

setup( tool_options )

env = tool_options.env.get()

tool_info.tool_class.setup( tool_options, env )
tool_info.tool_class.setup( tool_options )

if tool_options.hasChangedKeyOptions():
raise NotImplementedError()

tool_obj = tool_info.tool_class( tool_options )

except (NotImplementedError, ErrorProgramNotFound):
except NotImplementedError:
tool_options.clear()

except Exception:
except Exception as ex:
tool_options.clear()
eventToolsToolFailed( tool_info )
raise
eventToolsToolFailed( ex, tool_info )
if no_errors:
raise

else:
tool_names = self.tool_names.get( tool_info.tool_class, tuple() )
return tool_obj, tool_names, tool_options

raise ErrorToolNotFound( tool_name )

#//=======================================================//
Expand Down Expand Up @@ -282,11 +284,50 @@ def __init__( self, options ):
#//-------------------------------------------------------//

@classmethod
def setup( cls, options, env ):
def setup( cls, options ):
pass

#//-------------------------------------------------------//

@classmethod
def options( cls ):
return None

#//-------------------------------------------------------//

@classmethod
def findProgram( cls, options, prog, hint_prog = None ):
env = options.env.get()
prog = findProgram( prog, env, hint_prog )

if prog is None:
raise NotImplementedError()

return prog

#//-------------------------------------------------------//

@classmethod
def findPrograms( cls, options, progs, hint_prog = None ):
env = options.env.get()
progs = findPrograms( progs, env, hint_prog )

for prog in progs:
if prog is None:
raise NotImplementedError()

return progs

#//-------------------------------------------------------//

@classmethod
def findOptionalProgram( cls, options, prog, hint_prog = None ):
env = options.env.get()
return findOptionalProgram( prog, env, hint_prog )

#//-------------------------------------------------------//

@classmethod
def findOptionalPrograms( cls, options, progs, hint_prog = None ):
env = options.env.get()
return findOptionalPrograms( progs, env, hint_prog )
8 changes: 7 additions & 1 deletion aql/util_types/aql_simple_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ def _cmp( self, other, cmp_op ):
self_ver = self.__version
other_ver = self.__convert( other ).__version

min_len = min( len(self_ver), len(other_ver) )
len_self = len(self_ver)
len_other = len(other_ver)

min_len = min( len_self, len_other )
if min_len == 0:
return cmp_op( len_self, len_other )

self_ver = self_ver[:min_len]
other_ver = other_ver[:min_len]

Expand Down

0 comments on commit 8b8ad5a

Please sign in to comment.