From abf33378888971b2b18cacef8e77977c4d81a860 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Tue, 8 Oct 2002 15:55:04 -0400 Subject: some mods to the plugin API --- Source/cmCPluginAPI.cxx | 98 +++++++++++++++++++++++------------------ Source/cmCPluginAPI.h | 5 ++- Source/cmLoadCommandCommand.cxx | 31 ++++++++++--- 3 files changed, 83 insertions(+), 51 deletions(-) diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 6fb744e..a550630 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -35,6 +35,15 @@ void cmSetClientData(void *info, void *cd) ((cmLoadedCommandInfo *)info)->ClientData = cd; } +void cmSetError(void *info, const char *err) +{ + if (((cmLoadedCommandInfo *)info)->Error) + { + free(((cmLoadedCommandInfo *)info)->Error); + } + ((cmLoadedCommandInfo *)info)->Error = strdup(err); +} + unsigned int cmGetCacheMajorVersion(void *arg) { cmMakefile *mf = static_cast(arg); @@ -461,50 +470,51 @@ void cmRemoveFile(const char *name) cmCAPI cmStaticCAPI = { cmGetClientData, - cmGetTotalArgumentSize, - cmFreeArguments, - cmSetClientData, - cmAddCacheDefinition, - cmAddCustomCommand, - cmAddDefineFlag, - cmAddDefinition, - cmAddExecutable, - cmAddLibrary, - cmAddLinkDirectoryForTarget, - cmAddLinkLibraryForTarget, - cmAddUtilityCommand, - cmCommandExists, - cmExecuteCommand, - cmExpandSourceListArguments, - cmExpandVariablesInString, - cmGetCacheMajorVersion, - cmGetCacheMinorVersion, - cmGetCurrentDirectory, - cmGetCurrentOutputDirectory, - cmGetDefinition, - cmGetHomeDirectory, - cmGetHomeOutputDirectory, - cmGetMajorVersion, - cmGetMinorVersion, - cmGetProjectName, - cmGetStartDirectory, - cmGetStartOutputDirectory, - cmIsOn, + cmGetTotalArgumentSize, + cmFreeArguments, + cmSetClientData, + cmSetError, + cmAddCacheDefinition, + cmAddCustomCommand, + cmAddDefineFlag, + cmAddDefinition, + cmAddExecutable, + cmAddLibrary, + cmAddLinkDirectoryForTarget, + cmAddLinkLibraryForTarget, + cmAddUtilityCommand, + cmCommandExists, + cmExecuteCommand, + cmExpandSourceListArguments, + cmExpandVariablesInString, + cmGetCacheMajorVersion, + cmGetCacheMinorVersion, + cmGetCurrentDirectory, + cmGetCurrentOutputDirectory, + cmGetDefinition, + cmGetHomeDirectory, + cmGetHomeOutputDirectory, + cmGetMajorVersion, + cmGetMinorVersion, + cmGetProjectName, + cmGetStartDirectory, + cmGetStartOutputDirectory, + cmIsOn, + + cmAddSource, + cmCreateSourceFile, + cmGetSource, + cmSourceFileAddDepend, + cmSourceFileGetProperty, + cmSourceFileGetPropertyAsBool, + cmSourceFileGetSourceName, + cmSourceFileSetName, + cmSourceFileSetName2, + cmSourceFileSetProperty, - cmAddSource, - cmCreateSourceFile, - cmGetSource, - cmSourceFileAddDepend, - cmSourceFileGetProperty, - cmSourceFileGetPropertyAsBool, - cmSourceFileGetSourceName, - cmSourceFileSetName, - cmSourceFileSetName2, - cmSourceFileSetProperty, - - cmCapitalized, - cmCopyFileIfDifferent, - cmGetFilenameWithoutExtension, - cmRemoveFile, + cmCapitalized, + cmCopyFileIfDifferent, + cmGetFilenameWithoutExtension, + cmRemoveFile, }; diff --git a/Source/cmCPluginAPI.h b/Source/cmCPluginAPI.h index ba76eff..2ac3270 100644 --- a/Source/cmCPluginAPI.h +++ b/Source/cmCPluginAPI.h @@ -52,7 +52,9 @@ typedef struct information is passed from the InitialPass to FInalPass for commands that need a FinalPass and need information from the InitialPass */ void (*SetClientData) (void *info, void *cd); - + /* when an error occurs, call this function to set the error string */ + void (*SetError) (void *info, const char *err); + /*========================================================================= The following functions all directly map to methods in the cmMakefile class. See cmMakefile.h for descriptions of what each method does. All of @@ -188,6 +190,7 @@ Finally we define the key data structures and function prototypes CM_DOC_FUNCTION GetTerseDocumentation; CM_DOC_FUNCTION GetFullDocumentation; const char *Name; + char *Error; void *ClientData; } cmLoadedCommandInfo; diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index c01fa46..d3bf67a 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -110,6 +110,12 @@ bool cmLoadedCommand::InitialPass(std::vector const& args) { return true; } + + // clear the error string + if (this->info.Error) + { + free(this->info.Error); + } // create argc and argv and then invoke the command int argc = static_cast (args.size()); @@ -125,10 +131,17 @@ bool cmLoadedCommand::InitialPass(std::vector const& args) } int result = info.InitialPass((void *)&info,(void *)this->m_Makefile,argc,argv); cmFreeArguments(argc,argv); + if (result) { return true; } + + /* Initial Pass must have failed so set the error string */ + if (this->info.Error) + { + this->SetError(this->info.Error); + } return false; } @@ -146,6 +159,10 @@ cmLoadedCommand::~cmLoadedCommand() { this->info.Destructor((void *)&this->info); } + if (this->info.Error) + { + free(this->info.Error); + } } // cmLoadCommandCommand @@ -187,16 +204,18 @@ bool cmLoadCommandCommand::InitialPass(std::vector const& argsIn) cmLibHandle lib = cmDynamicLoader::OpenLibrary(fullPath.c_str()); if(lib) { - // Look for the symbol cmLoad, cmGetFactoryCompilerUsed, - // and cmGetFactoryVersion in the library + // find the init function + std::string initFuncName = args[0] + "Init"; CM_INIT_FUNCTION initFunction = (CM_INIT_FUNCTION) - cmDynamicLoader::GetSymbolAddress(lib, "cmInitializeCommand"); + cmDynamicLoader::GetSymbolAddress(lib, initFuncName.c_str()); if ( !initFunction ) { - initFunction = - (CM_INIT_FUNCTION)( - cmDynamicLoader::GetSymbolAddress(lib, "_cmInitializeCommand")); + initFuncName = "_"; + initFuncName += args[0]; + initFuncName += "Init"; + initFunction = (CM_INIT_FUNCTION)( + cmDynamicLoader::GetSymbolAddress(lib, initFuncName.c_str())); } // if the symbol is found call it to set the name on the // function blocker -- cgit v0.12