mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-06-16 12:27:45 +00:00
Merge pull request #861 from takhlaq/ThreePointThree
scripts: build modules to tmp directory before copying over to reload
This commit is contained in:
commit
d52fac9e35
4 changed files with 36 additions and 1 deletions
|
@ -5,7 +5,8 @@ file(GLOB SCRIPT_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
|
||||||
|
|
||||||
message("exec: ${EXECUTABLE_OUTPUT_PATH}")
|
message("exec: ${EXECUTABLE_OUTPUT_PATH}")
|
||||||
|
|
||||||
set(SCRIPT_LIB_DIR "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/" )
|
set(SCRIPT_POSTBUILD_DIR "${EXECUTABLE_OUTPUT_PATH}/compiledscripts/")
|
||||||
|
set(SCRIPT_LIB_DIR "${EXECUTABLE_OUTPUT_PATH}/tmp/compiledscripts/" )
|
||||||
set(EXECUTABLE_OUTPUT_PATH "${SCRIPT_LIB_DIR}")
|
set(EXECUTABLE_OUTPUT_PATH "${SCRIPT_LIB_DIR}")
|
||||||
set(LIBRARY_OUTPUT_PATH "${SCRIPT_LIB_DIR}")
|
set(LIBRARY_OUTPUT_PATH "${SCRIPT_LIB_DIR}")
|
||||||
set(RUNTIME_OUTPUT_DIRECTORY "${SCRIPT_LIB_DIR}")
|
set(RUNTIME_OUTPUT_DIRECTORY "${SCRIPT_LIB_DIR}")
|
||||||
|
@ -55,15 +56,27 @@ foreach(_scriptDir ${children})
|
||||||
|
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ScriptLoader.cpp.in" "${_scriptDir}/ScriptLoader.cpp")
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ScriptLoader.cpp.in" "${_scriptDir}/ScriptLoader.cpp")
|
||||||
|
|
||||||
|
set(ScriptTargetName "script_${_name}")
|
||||||
|
|
||||||
|
# Copy the modules over once they're built. Prevent watchdog from trying to reload partially written files.
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.exp"
|
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.exp"
|
||||||
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.lib"
|
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.lib"
|
||||||
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.ilk"
|
COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.ilk"
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy "${SCRIPT_LIB_DIR}/script_${_name}.dll" ${SCRIPT_POSTBUILD_DIR}${ScriptTargetName}.dll_LOCK
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SCRIPT_LIB_DIR}/script_${_name}.dll" ${SCRIPT_POSTBUILD_DIR}${ScriptTargetName}.dll
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E remove ${SCRIPT_POSTBUILD_DIR}${ScriptTargetName}.dll_LOCK
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
add_custom_command(TARGET "script_${_name}" POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${ScriptTargetName}> ${SCRIPT_POSTBUILD_DIR}_LOCK
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${ScriptTargetName}> ${SCRIPT_POSTBUILD_DIR}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E remove ${SCRIPT_POSTBUILD_DIR}$<TARGET_FILE_NAME:${ScriptTargetName}>_LOCK
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
unset(ScriptTargetName)
|
||||||
unset(ScriptIncludes)
|
unset(ScriptIncludes)
|
||||||
unset(ScriptNames)
|
unset(ScriptNames)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
bool NativeScriptMgr::loadScript( const std::string& path )
|
bool NativeScriptMgr::loadScript( const std::string& path )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
auto module = m_loader.loadModule( path );
|
auto module = m_loader.loadModule( path );
|
||||||
if( !module )
|
if( !module )
|
||||||
return false;
|
return false;
|
||||||
|
@ -47,11 +49,15 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
const std::string NativeScriptMgr::getModuleExtension()
|
const std::string NativeScriptMgr::getModuleExtension()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.getModuleExtension();
|
return m_loader.getModuleExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeScriptMgr::unloadScript( const std::string& name )
|
bool NativeScriptMgr::unloadScript( const std::string& name )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
auto info = m_loader.getScriptInfo( name );
|
auto info = m_loader.getScriptInfo( name );
|
||||||
if( !info )
|
if( !info )
|
||||||
return false;
|
return false;
|
||||||
|
@ -61,6 +67,8 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
bool NativeScriptMgr::unloadScript( ScriptInfo* info )
|
bool NativeScriptMgr::unloadScript( ScriptInfo* info )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
for( auto& script : info->scripts )
|
for( auto& script : info->scripts )
|
||||||
{
|
{
|
||||||
m_scripts[ script->getType() ].erase( script->getId() );
|
m_scripts[ script->getType() ].erase( script->getId() );
|
||||||
|
@ -83,11 +91,14 @@ namespace Sapphire::Scripting
|
||||||
if( !unloadScript( info ) )
|
if( !unloadScript( info ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
m_scriptLoadQueue.push( libPath );
|
m_scriptLoadQueue.push( libPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeScriptMgr::processLoadQueue()
|
void NativeScriptMgr::processLoadQueue()
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
std::vector< std::string > deferredLoads;
|
std::vector< std::string > deferredLoads;
|
||||||
|
|
||||||
while( !m_scriptLoadQueue.empty() )
|
while( !m_scriptLoadQueue.empty() )
|
||||||
|
@ -110,11 +121,15 @@ namespace Sapphire::Scripting
|
||||||
|
|
||||||
void NativeScriptMgr::findScripts( std::set< Sapphire::Scripting::ScriptInfo* >& scripts, const std::string& search )
|
void NativeScriptMgr::findScripts( std::set< Sapphire::Scripting::ScriptInfo* >& scripts, const std::string& search )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.findScripts( scripts, search );
|
return m_loader.findScripts( scripts, search );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeScriptMgr::isModuleLoaded( const std::string& name )
|
bool NativeScriptMgr::isModuleLoaded( const std::string& name )
|
||||||
{
|
{
|
||||||
|
std::scoped_lock lock( m_mutex );
|
||||||
|
|
||||||
return m_loader.isModuleLoaded( name );
|
return m_loader.isModuleLoaded( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "ScriptLoader.h"
|
#include "ScriptLoader.h"
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ namespace Sapphire::Scripting
|
||||||
*/
|
*/
|
||||||
std::queue< std::string > m_scriptLoadQueue;
|
std::queue< std::string > m_scriptLoadQueue;
|
||||||
|
|
||||||
|
std::recursive_mutex m_mutex;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Used to unload a script
|
* @brief Used to unload a script
|
||||||
*
|
*
|
||||||
|
|
|
@ -74,6 +74,10 @@ Sapphire::Scripting::ScriptInfo* Sapphire::Scripting::ScriptLoader::loadModule(
|
||||||
fs::create_directories( cacheDir );
|
fs::create_directories( cacheDir );
|
||||||
fs::path dest( cacheDir /= f.filename().string() );
|
fs::path dest( cacheDir /= f.filename().string() );
|
||||||
|
|
||||||
|
// make sure the module has finished building before trying to copy it
|
||||||
|
if( fs::exists( f.string() + "_LOCK" ) )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fs::copy_file( f, dest, fs::copy_options::overwrite_existing );
|
fs::copy_file( f, dest, fs::copy_options::overwrite_existing );
|
||||||
|
|
Loading…
Add table
Reference in a new issue