diff options
author | Justin Clark-Casey (justincc) | 2014-07-11 00:03:02 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-07-11 00:03:02 +0100 |
commit | d7b92604963c7ecbddf76db37eabb84ed36fcfde (patch) | |
tree | 0f75eca56190522c477f2e53574e47ce9019f26b /OpenSim/Region/ScriptEngine/Shared | |
parent | refactor: use existing Compiler.CreateScriptsDirectory() (renamed to CheckOrC... (diff) | |
download | opensim-SC_OLD-d7b92604963c7ecbddf76db37eabb84ed36fcfde.zip opensim-SC_OLD-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.gz opensim-SC_OLD-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.bz2 opensim-SC_OLD-d7b92604963c7ecbddf76db37eabb84ed36fcfde.tar.xz |
If [XEngine] ScriptStopStrategy is changed between abort and co-op, for the existing session use the previous strategy for that script rather than not starting the script at all.
We have to do this since we can't unload existing DLLs if they're all in the same AppDomain.
But we can still update the underlying DLL which will be used in the next simulator session.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
3 files changed, 44 insertions, 56 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index f874de2..98658b6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs | |||
@@ -284,12 +284,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
284 | return GetCompilerOutput(assetID.ToString()); | 284 | return GetCompilerOutput(assetID.ToString()); |
285 | } | 285 | } |
286 | 286 | ||
287 | /// <summary> | 287 | public void PerformScriptCompile( |
288 | /// Converts script from LSL to CS and calls CompileFromCSText | 288 | string source, string asset, UUID ownerUUID, |
289 | /// </summary> | 289 | out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) |
290 | /// <param name="Script">LSL script</param> | 290 | { |
291 | /// <returns>Filename to .dll assembly</returns> | 291 | PerformScriptCompile(source, asset, ownerUUID, false, out assembly, out linemap); |
292 | public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, | 292 | } |
293 | |||
294 | public void PerformScriptCompile( | ||
295 | string source, string asset, UUID ownerUUID, bool alwaysRecompile, | ||
293 | out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) | 296 | out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) |
294 | { | 297 | { |
295 | // m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script); | 298 | // m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script); |
@@ -303,9 +306,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
303 | 306 | ||
304 | CheckOrCreateScriptsDirectory(); | 307 | CheckOrCreateScriptsDirectory(); |
305 | 308 | ||
306 | // Don't recompile if we already have it | 309 | // Don't recompile if we're not forced to and we already have it |
307 | // Performing 3 file exists tests for every script can still be slow | 310 | // Performing 3 file exists tests for every script can still be slow |
308 | if (File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map")) | 311 | if (!alwaysRecompile && File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map")) |
309 | { | 312 | { |
310 | // If we have already read this linemap file, then it will be in our dictionary. | 313 | // If we have already read this linemap file, then it will be in our dictionary. |
311 | // Don't build another copy of the dictionary (saves memory) and certainly | 314 | // Don't build another copy of the dictionary (saves memory) and certainly |
@@ -316,29 +319,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
316 | return; | 319 | return; |
317 | } | 320 | } |
318 | 321 | ||
319 | if (Script == String.Empty) | 322 | if (source == String.Empty) |
320 | { | ||
321 | throw new Exception("Cannot find script assembly and no script text present"); | 323 | throw new Exception("Cannot find script assembly and no script text present"); |
322 | } | ||
323 | 324 | ||
324 | enumCompileType language = DefaultCompileLanguage; | 325 | enumCompileType language = DefaultCompileLanguage; |
325 | 326 | ||
326 | if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture)) | 327 | if (source.StartsWith("//c#", true, CultureInfo.InvariantCulture)) |
327 | language = enumCompileType.cs; | 328 | language = enumCompileType.cs; |
328 | if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture)) | 329 | if (source.StartsWith("//vb", true, CultureInfo.InvariantCulture)) |
329 | { | 330 | { |
330 | language = enumCompileType.vb; | 331 | language = enumCompileType.vb; |
331 | // We need to remove //vb, it won't compile with that | 332 | // We need to remove //vb, it won't compile with that |
332 | 333 | ||
333 | Script = Script.Substring(4, Script.Length - 4); | 334 | source = source.Substring(4, source.Length - 4); |
334 | } | 335 | } |
335 | if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) | 336 | if (source.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) |
336 | language = enumCompileType.lsl; | 337 | language = enumCompileType.lsl; |
337 | 338 | ||
338 | if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) | 339 | if (source.StartsWith("//js", true, CultureInfo.InvariantCulture)) |
339 | language = enumCompileType.js; | 340 | language = enumCompileType.js; |
340 | 341 | ||
341 | if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) | 342 | if (source.StartsWith("//yp", true, CultureInfo.InvariantCulture)) |
342 | language = enumCompileType.yp; | 343 | language = enumCompileType.yp; |
343 | 344 | ||
344 | // m_log.DebugFormat("[Compiler]: Compile language is {0}", language); | 345 | // m_log.DebugFormat("[Compiler]: Compile language is {0}", language); |
@@ -359,13 +360,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools | |||
359 | throw new Exception(errtext); | 360 | throw new Exception(errtext); |
360 | } | 361 | } |
361 | 362 | ||
362 | string compileScript = Script; | 363 | string compileScript = source; |
363 | 364 | ||
364 | if (language == enumCompileType.lsl) | 365 | if (language == enumCompileType.lsl) |
365 | { | 366 | { |
366 | // Its LSL, convert it to C# | 367 | // Its LSL, convert it to C# |
367 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); | 368 | LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms, m_insertCoopTerminationCalls); |
368 | compileScript = LSL_Converter.Convert(Script); | 369 | compileScript = LSL_Converter.Convert(source); |
369 | 370 | ||
370 | // copy converter warnings into our warnings. | 371 | // copy converter warnings into our warnings. |
371 | foreach (string warning in LSL_Converter.GetWarnings()) | 372 | foreach (string warning in LSL_Converter.GetWarnings()) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs index 938cb2e..388de7f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CompilerTest.cs | |||
@@ -67,8 +67,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools.Tests | |||
67 | } | 67 | } |
68 | 68 | ||
69 | [SetUp] | 69 | [SetUp] |
70 | public void SetUp() | 70 | public override void SetUp() |
71 | { | 71 | { |
72 | base.SetUp(); | ||
73 | |||
72 | // Create a CSCodeProvider and CompilerParameters. | 74 | // Create a CSCodeProvider and CompilerParameters. |
73 | m_CSCodeProvider = new CSharpCodeProvider(); | 75 | m_CSCodeProvider = new CSharpCodeProvider(); |
74 | m_compilerParameters = new CompilerParameters(); | 76 | m_compilerParameters = new CompilerParameters(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index c5d0752..979c84a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -237,12 +237,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
237 | m_postOnRez = postOnRez; | 237 | m_postOnRez = postOnRez; |
238 | m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; | 238 | m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; |
239 | m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; | 239 | m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; |
240 | |||
241 | if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op") | ||
242 | { | ||
243 | m_coopTermination = true; | ||
244 | m_coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset); | ||
245 | } | ||
246 | } | 240 | } |
247 | 241 | ||
248 | /// <summary> | 242 | /// <summary> |
@@ -252,54 +246,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
252 | /// <param name='assembly'></param> | 246 | /// <param name='assembly'></param> |
253 | /// <param name='stateSource'></param> | 247 | /// <param name='stateSource'></param> |
254 | /// <returns>false if load failed, true if suceeded</returns> | 248 | /// <returns>false if load failed, true if suceeded</returns> |
255 | public bool Load(AppDomain dom, string assembly, StateSource stateSource) | 249 | public bool Load(AppDomain dom, Assembly scriptAssembly, StateSource stateSource) |
256 | { | 250 | { |
257 | m_Assembly = assembly; | 251 | //m_Assembly = scriptAssembly.CodeBase; |
252 | m_Assembly = scriptAssembly.Location; | ||
258 | m_stateSource = stateSource; | 253 | m_stateSource = stateSource; |
259 | |||
260 | ApiManager am = new ApiManager(); | ||
261 | |||
262 | foreach (string api in am.GetApis()) | ||
263 | { | ||
264 | m_Apis[api] = am.CreateApi(api); | ||
265 | m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle); | ||
266 | } | ||
267 | 254 | ||
268 | try | 255 | try |
269 | { | 256 | { |
270 | object[] constructorParams; | 257 | object[] constructorParams; |
271 | |||
272 | Assembly scriptAssembly = dom.Load(Path.GetFileNameWithoutExtension(assembly)); | ||
273 | Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript"); | 258 | Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript"); |
274 | 259 | ||
275 | if (scriptType != null) | 260 | if (scriptType != null) |
276 | { | 261 | { |
262 | m_coopTermination = true; | ||
263 | m_coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset); | ||
277 | constructorParams = new object[] { m_coopSleepHandle }; | 264 | constructorParams = new object[] { m_coopSleepHandle }; |
278 | } | 265 | } |
279 | else if (!m_coopTermination) | 266 | else |
280 | { | 267 | { |
268 | m_coopTermination = false; | ||
281 | scriptType = scriptAssembly.GetType("SecondLife.Script"); | 269 | scriptType = scriptAssembly.GetType("SecondLife.Script"); |
282 | constructorParams = null; | 270 | constructorParams = null; |
283 | } | 271 | } |
284 | else | ||
285 | { | ||
286 | m_log.ErrorFormat( | ||
287 | "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. You must remove all existing {6}* script DLL files before using enabling co-op termination" | ||
288 | + ", either by setting DeleteScriptsOnStartup = true in [XEngine] for one run" | ||
289 | + " or by deleting these files manually.", | ||
290 | ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, assembly); | ||
291 | |||
292 | return false; | ||
293 | } | ||
294 | 272 | ||
295 | // m_log.DebugFormat( | 273 | // m_log.DebugFormat( |
296 | // "[SCRIPT INSTANCE]: Looking to load {0} from assembly {1} in {2}", | 274 | // "[SCRIPT INSTANCE]: Looking to load {0} from assembly {1} in {2}", |
297 | // scriptType.FullName, Path.GetFileNameWithoutExtension(assembly), Engine.World.Name); | 275 | // scriptType.FullName, m_Assembly, Engine.World.Name); |
298 | 276 | ||
299 | if (dom != System.AppDomain.CurrentDomain) | 277 | if (dom != System.AppDomain.CurrentDomain) |
300 | m_Script | 278 | m_Script |
301 | = (IScript)dom.CreateInstanceAndUnwrap( | 279 | = (IScript)dom.CreateInstanceAndUnwrap( |
302 | Path.GetFileNameWithoutExtension(assembly), | 280 | Path.GetFileNameWithoutExtension(m_Assembly), |
303 | scriptType.FullName, | 281 | scriptType.FullName, |
304 | false, | 282 | false, |
305 | BindingFlags.Default, | 283 | BindingFlags.Default, |
@@ -327,11 +305,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
327 | { | 305 | { |
328 | m_log.ErrorFormat( | 306 | m_log.ErrorFormat( |
329 | "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error loading assembly {6}. Exception {7}{8}", | 307 | "[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error loading assembly {6}. Exception {7}{8}", |
330 | ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, assembly, e.Message, e.StackTrace); | 308 | ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, m_Assembly, e.Message, e.StackTrace); |
331 | 309 | ||
332 | return false; | 310 | return false; |
333 | } | 311 | } |
334 | 312 | ||
313 | ApiManager am = new ApiManager(); | ||
314 | |||
315 | foreach (string api in am.GetApis()) | ||
316 | { | ||
317 | m_Apis[api] = am.CreateApi(api); | ||
318 | m_Apis[api].Initialize(Engine, Part, ScriptTask, m_coopSleepHandle); | ||
319 | } | ||
320 | |||
335 | try | 321 | try |
336 | { | 322 | { |
337 | foreach (KeyValuePair<string,IScriptApi> kv in m_Apis) | 323 | foreach (KeyValuePair<string,IScriptApi> kv in m_Apis) |
@@ -341,8 +327,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
341 | 327 | ||
342 | // // m_log.Debug("[Script] Script instance created"); | 328 | // // m_log.Debug("[Script] Script instance created"); |
343 | 329 | ||
344 | Part.SetScriptEvents(ItemID, | 330 | Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); |
345 | (int)m_Script.GetStateEventFlags(State)); | ||
346 | } | 331 | } |
347 | catch (Exception e) | 332 | catch (Exception e) |
348 | { | 333 | { |
@@ -355,8 +340,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
355 | 340 | ||
356 | m_SaveState = true; | 341 | m_SaveState = true; |
357 | 342 | ||
358 | string savedState = Path.Combine(Path.GetDirectoryName(assembly), | 343 | string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), ItemID.ToString() + ".state"); |
359 | ItemID.ToString() + ".state"); | 344 | |
360 | if (File.Exists(savedState)) | 345 | if (File.Exists(savedState)) |
361 | { | 346 | { |
362 | string xml = String.Empty; | 347 | string xml = String.Empty; |