public SynchronizerBuilder WithAssemblyData (string[] files = null, string[] defines = null, Assembly[] assemblyReferences = null, string[] compiledAssemblyReferences = null, ScriptCompilerOptions options = null, string rootNamespace = "", string roslynAnalyzerRulesetPath = null) { // ReSharper disable once ConvertToNullCoalescingCompoundAssignment options = options ?? new ScriptCompilerOptions(); Assembly assembly = CreateAssembly( "Test", "some/path/file.dll", files ?? new[] { "test.cs" }, defines ?? new string[0], assemblyReferences ?? new Assembly[0], compiledAssemblyReferences ?? new string[0], AssemblyFlags.None, options, rootNamespace ); #if UNITY_2020_2_OR_NEWER assembly.compilerOptions.RoslynAnalyzerRulesetPath = roslynAnalyzerRulesetPath; #endif return(WithAssembly(assembly)); }
public void TestCreateNewTemplateMap() { const string OutputMapName = "Template.w3x"; var scriptCompilerOptions = new ScriptCompilerOptions(CSharpLua.CoreSystem.CoreSystemProvider.GetCoreSystemFiles()); scriptCompilerOptions.MapInfo = MapInfo.Default; scriptCompilerOptions.MapEnvironment = MapEnvironment.Default; scriptCompilerOptions.SourceDirectory = @".\TestData\Script\Template"; scriptCompilerOptions.OutputDirectory = @".\TestOutput\Template"; #if DEBUG scriptCompilerOptions.Debug = true; #endif // Build and launch var mapBuilder = new MapBuilder(OutputMapName); if (mapBuilder.Build(scriptCompilerOptions)) { var mapPath = Path.Combine(scriptCompilerOptions.OutputDirectory, OutputMapName); var absoluteMapPath = new FileInfo(mapPath).FullName; Assert.IsNotNull(Warcraft3ExecutableFilePath, "Path to Warcraft III.exe is not set."); Process.Start(Warcraft3ExecutableFilePath, $"-loadfile \"{absoluteMapPath}\""); } else { Assert.Fail(); } }
public void TestGenerateLuaScriptWithUnitData() { const string OutputMapName = "TestOutput.w3x"; const string InputPath = @".\TestData\MapFiles\TestGenerateUnitData"; var mapInfo = MapInfo.Parse(File.OpenRead(Path.Combine(InputPath, MapInfo.FileName))); mapInfo.ScriptLanguage = ScriptLanguage.Lua; var scriptCompilerOptions = new ScriptCompilerOptions(); scriptCompilerOptions.MapInfo = mapInfo; scriptCompilerOptions.ForceCompile = true; scriptCompilerOptions.SourceDirectory = null; scriptCompilerOptions.OutputDirectory = @".\TestOutput\TestGenerateUnitData"; var mapBuilder = new MapBuilder(OutputMapName); if (mapBuilder.Build(scriptCompilerOptions, InputPath)) { var mapPath = Path.Combine(scriptCompilerOptions.OutputDirectory, OutputMapName); var absoluteMapPath = new FileInfo(mapPath).FullName; Assert.IsNotNull(Warcraft3ExecutableFilePath, "Path to Warcraft III.exe is not set."); Process.Start(Warcraft3ExecutableFilePath, $"-loadfile \"{absoluteMapPath}\""); } else { Assert.Fail(); } }
public ScriptAssemblySettings() { BuildTarget = BuildTarget.NoTarget; BuildTargetGroup = BuildTargetGroup.Unknown; PredefinedAssembliesCompilerOptions = new ScriptCompilerOptions(); ExtraGeneralDefines = new string[0]; }
public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, string guid, CustomScriptAssemblyData customScriptAssemblyData) { if (customScriptAssemblyData == null) return null; var pathPrefix = path.Substring(0, path.Length - AssetPath.GetFileName(path).Length); var customScriptAssembly = new CustomScriptAssembly(); customScriptAssembly.Name = customScriptAssemblyData.name; customScriptAssembly.GUID = guid; customScriptAssembly.References = customScriptAssemblyData.references; customScriptAssembly.FilePath = path; customScriptAssembly.PathPrefix = pathPrefix; customScriptAssembly.AutoReferenced = customScriptAssemblyData.autoReferenced; customScriptAssembly.OverrideReferences = customScriptAssemblyData.overrideReferences; customScriptAssembly.NoEngineReferences = customScriptAssemblyData.noEngineReferences; customScriptAssembly.PrecompiledReferences = customScriptAssemblyData.precompiledReferences ?? new string[0]; customScriptAssembly.DefineConstraints = customScriptAssemblyData.defineConstraints ?? new string[0]; customScriptAssembly.VersionDefines = (customScriptAssemblyData.versionDefines ?? new VersionDefine[0]); if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0) customScriptAssembly.IncludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.includePlatforms); if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0) customScriptAssembly.ExcludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.excludePlatforms); var compilerOptions = new ScriptCompilerOptions(); compilerOptions.AllowUnsafeCode = customScriptAssemblyData.allowUnsafeCode; customScriptAssembly.CompilerOptions = compilerOptions; return customScriptAssembly; }
public TargetAssembly(string name, SupportedLanguage language, AssemblyFlags flags, TargetAssemblyType type, string pathPrefix, string[] additionalPrefixes, Func <string, int> pathFilter, Func <ScriptAssemblySettings, string[], bool> compatFunc, ScriptCompilerOptions compilerOptions) : this() { Language = language; Filename = name; Flags = flags; PathPrefix = pathPrefix; AdditionalPrefixes = additionalPrefixes; PathFilter = pathFilter; IsCompatibleFunc = compatFunc; Type = type; CompilerOptions = compilerOptions; ExplicitPrecompiledReferences = new List <string>(); VersionDefines = new List <VersionDefine>(); if (PathPrefix != null) { MaxPathLength = PathPrefix.Length; } if (AdditionalPrefixes != null) { MaxPathLength = UnityEngine.Mathf.Max(MaxPathLength, AdditionalPrefixes.Max(am => am.Length)); } }
public static string GetLangVersion() { var languageVersion = #if UNITY_2020_2_OR_NEWER new ScriptCompilerOptions().LanguageVersion; #else "latest"; #endif return(languageVersion); }
public void LanguageVersionFromAssembly_WillBeSet(string languageVersion) { var options = new ScriptCompilerOptions(); typeof(ScriptCompilerOptions).GetProperty("LanguageVersion")?.SetValue(options, languageVersion, null); var synchronizer = m_Builder .WithAssemblyData(options: options) .Build(); synchronizer.Sync(); var csprojFileContents = m_Builder.ReadProjectFile(m_Builder.Assembly); StringAssert.Contains($"<LangVersion>{languageVersion}</LangVersion>", csprojFileContents); }
public static ScriptCompilerOptions GetCompilerOptions(string sourceDirectory, string outputDirectory) { var scriptCompilerOptions = new ScriptCompilerOptions(CSharpLua.CoreSystem.CoreSystemProvider.GetCoreSystemFiles()); scriptCompilerOptions.SourceDirectory = sourceDirectory; scriptCompilerOptions.OutputDirectory = outputDirectory; scriptCompilerOptions.DefaultFileFlags = MpqFileFlags.Exists | MpqFileFlags.CompressedMulti; scriptCompilerOptions.FileFlags[ListFile.Key] = MpqFileFlags.Exists | MpqFileFlags.CompressedMulti | MpqFileFlags.Encrypted | MpqFileFlags.BlockOffsetAdjustedKey; #if DEBUG scriptCompilerOptions.Debug = true; #endif return(scriptCompilerOptions); }
public TargetAssembly(string name, SupportedLanguage language, AssemblyFlags flags, TargetAssemblyType type, Func <string, int> pathFilter, Func <BuildTarget, EditorScriptCompilationOptions, bool> compatFunc, ScriptCompilerOptions compilerOptions) : this() { Language = language; Filename = name; Flags = flags; PathFilter = pathFilter; IsCompatibleFunc = compatFunc; Type = type; CompilerOptions = compilerOptions; }
public static CustomScriptAssembly FromCustomScriptAssemblyData(string path, string guid, CustomScriptAssemblyData customScriptAssemblyData) { if (customScriptAssemblyData == null) { return(null); } var pathPrefix = path.Substring(0, path.Length - AssetPath.GetFileName(path).Length); var customScriptAssembly = new CustomScriptAssembly(); customScriptAssembly.Name = customScriptAssemblyData.name; customScriptAssembly.GUID = guid; customScriptAssembly.References = customScriptAssemblyData.references; customScriptAssembly.FilePath = path; customScriptAssembly.PathPrefix = pathPrefix; customScriptAssembly.AutoReferenced = customScriptAssemblyData.autoReferenced; customScriptAssembly.OverrideReferences = customScriptAssemblyData.overrideReferences; customScriptAssembly.PrecompiledReferences = customScriptAssemblyData.precompiledReferences ?? new string[0]; customScriptAssembly.DefineConstraints = customScriptAssemblyData.defineConstraints ?? new string[0]; customScriptAssembly.VersionDefines = (customScriptAssemblyData.versionDefines ?? new VersionDefine[0]); customScriptAssemblyData.optionalUnityReferences = customScriptAssemblyData.optionalUnityReferences ?? new string[0]; foreach (var optionalUnityReferenceString in customScriptAssemblyData.optionalUnityReferences) { var optionalUnityReference = (OptionalUnityReferences)Enum.Parse(typeof(OptionalUnityReferences), optionalUnityReferenceString); customScriptAssembly.OptionalUnityReferences |= optionalUnityReference; } if (customScriptAssemblyData.includePlatforms != null && customScriptAssemblyData.includePlatforms.Length > 0) { customScriptAssembly.IncludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.includePlatforms); } if (customScriptAssemblyData.excludePlatforms != null && customScriptAssemblyData.excludePlatforms.Length > 0) { customScriptAssembly.ExcludePlatforms = GetPlatformsFromNames(customScriptAssemblyData.excludePlatforms); } var compilerOptions = new ScriptCompilerOptions(); compilerOptions.AllowUnsafeCode = customScriptAssemblyData.allowUnsafeCode; customScriptAssembly.CompilerOptions = compilerOptions; return(customScriptAssembly); }
public ProjectPart(string name, Assembly assembly, string assetsProjectPart) { Name = name; Assembly = assembly; AssetsProjectPart = assetsProjectPart; OutputPath = assembly != null ? assembly.outputPath : "Temp/Bin/Debug"; SourceFiles = assembly != null ? assembly.sourceFiles : new string[0]; #if UNITY_2020_2_OR_NEWER RootNamespace = assembly != null ? assembly.rootNamespace : string.Empty; #else RootNamespace = UnityEditor.EditorSettings.projectGenerationRootNamespace; #endif AssemblyReferences = assembly != null ? assembly.assemblyReferences : new Assembly[0]; CompiledAssemblyReferences = assembly != null? assembly.compiledAssemblyReferences:new string[0]; Defines = assembly != null ? assembly.defines : new string[0]; CompilerOptions = assembly != null ? assembly.compilerOptions : new ScriptCompilerOptions(); }
private static void Main() { var stringProvider = new ExampleStringProvider(); var mapInfo = MapInfo.Parse(FileProvider.GetFile(Path.Combine(stringProvider.BaseMapFilePath, MapInfo.FileName))); mapInfo.MapName = stringProvider.MapName; mapInfo.MapDescription = stringProvider.MapDescription; mapInfo.MapAuthor = stringProvider.MapAuthor; mapInfo.RecommendedPlayers = stringProvider.RecommendedPlayers; mapInfo.MapFlags &= ~MapFlags.MeleeMap; mapInfo.ScriptLanguage = ScriptLanguage.Lua; PlayerAndForceProperties.ApplyToMapInfo(mapInfo); var scriptCompilerOptions = new ScriptCompilerOptions(CoreSystemProvider.GetCoreSystemFiles().Append(@".\LuaLibs\PerlinNoise.lua")); scriptCompilerOptions.MapInfo = mapInfo; scriptCompilerOptions.LobbyMusic = stringProvider.LobbyMusic; scriptCompilerOptions.SourceDirectory = stringProvider.SourceProjectPath; scriptCompilerOptions.OutputDirectory = stringProvider.OutputDirectoryPath; // Note: do not use MpqFileFlags.SingleUnit, as it appears to be bugged. scriptCompilerOptions.DefaultFileFlags = MpqFileFlags.Exists | MpqFileFlags.CompressedMulti; scriptCompilerOptions.FileFlags["war3map.wtg"] = 0; scriptCompilerOptions.FileFlags[mapInfo.ScriptLanguage == ScriptLanguage.Jass ? "war3map.lua" : "war3map.j"] = 0; scriptCompilerOptions.FileFlags[ListFile.Key] = MpqFileFlags.Exists | MpqFileFlags.Encrypted | MpqFileFlags.BlockOffsetAdjustedKey; #if DEBUG scriptCompilerOptions.Debug = true; #endif // Build and launch var mapName = stringProvider.MapFileName; var mapBuilder = new MapBuilder(mapName); if (mapBuilder.Build(scriptCompilerOptions, stringProvider.AssetsDirectoryPath, stringProvider.BaseMapFilePath)) { var mapPath = Path.Combine(scriptCompilerOptions.OutputDirectory, mapName); var absoluteMapPath = new FileInfo(mapPath).FullName; Process.Start(stringProvider.Warcraft3ExecutablePath, $"{stringProvider.CommandLineArguments} -loadfile \"{absoluteMapPath}\""); } }
public void TestGenerateJassScriptWithUnitData() { const string OutputMapName = "TestOutput.w3x"; const string InputPath = @".\TestData\MapFiles\TestGenerateUnitData"; var scriptCompilerOptions = new ScriptCompilerOptions(); scriptCompilerOptions.ForceCompile = true; scriptCompilerOptions.SourceDirectory = null; scriptCompilerOptions.OutputDirectory = @".\TestOutput\TestGenerateUnitData"; var mapBuilder = new MapBuilder(OutputMapName); if (mapBuilder.Build(scriptCompilerOptions, InputPath)) { } else { Assert.Fail(); } }
protected ScriptCompiler(ScriptCompilerOptions options) { _options = options; }
internal static TargetAssembly[] CreatePredefinedTargetAssemblies() { var runtimeFirstPassAssemblies = new List <TargetAssembly>(); var runtimeAssemblies = new List <TargetAssembly>(); var editorFirstPassAssemblies = new List <TargetAssembly>(); var editorAssemblies = new List <TargetAssembly>(); var assemblies = new List <TargetAssembly>(); var scriptCompilerOptions = new ScriptCompilerOptions(); // Initialize predefined assembly targets { const string languageName = "CSharp"; var runtimeFirstPass = new TargetAssembly("Assembly-" + languageName + "-firstpass" + ".dll", AssemblyFlags.FirstPass | AssemblyFlags.UserAssembly, TargetAssemblyType.Predefined, null, null, FilterAssemblyInFirstpassFolder, null, scriptCompilerOptions); var runtime = new TargetAssembly("Assembly-" + languageName + ".dll", AssemblyFlags.UserAssembly, TargetAssemblyType.Predefined, null, null, null, null, scriptCompilerOptions); var editorFirstPass = new TargetAssembly("Assembly-" + languageName + "-Editor-firstpass" + ".dll", AssemblyFlags.EditorOnly | AssemblyFlags.FirstPass | AssemblyFlags.UserAssembly, TargetAssemblyType.Predefined, null, null, FilterAssemblyInFirstpassEditorFolder, (settings, defines) => IsCompatibleWithEditor(settings), scriptCompilerOptions); var editor = new TargetAssembly("Assembly-" + languageName + "-Editor" + ".dll", AssemblyFlags.EditorOnly | AssemblyFlags.UserAssembly, TargetAssemblyType.Predefined, null, null, FilterAssemblyInEditorFolder, (settings, defines) => IsCompatibleWithEditor(settings), scriptCompilerOptions); runtimeFirstPassAssemblies.Add(runtimeFirstPass); runtimeAssemblies.Add(runtime); editorFirstPassAssemblies.Add(editorFirstPass); editorAssemblies.Add(editor); assemblies.Add(runtimeFirstPass); assemblies.Add(runtime); assemblies.Add(editorFirstPass); assemblies.Add(editor); } // Setup dependencies // Runtime assemblies depend all first pass runtime assemblies foreach (var assembly in runtimeAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); } // First pass editor assemblies depend on all first pass runtime assemblies foreach (var assembly in editorFirstPassAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); } // Editor assemblies depend on all previous runtime and editor assemblies foreach (var assembly in editorAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); assembly.References.AddRange(runtimeAssemblies); assembly.References.AddRange(editorFirstPassAssemblies); } return(assemblies.ToArray()); }
internal static TargetAssembly[] CreatePredefinedTargetAssemblies() { var runtimeFirstPassAssemblies = new List <TargetAssembly>(); var runtimeAssemblies = new List <TargetAssembly>(); var editorFirstPassAssemblies = new List <TargetAssembly>(); var editorAssemblies = new List <TargetAssembly>(); var supportedLanguages = ScriptCompilers.SupportedLanguages; var assemblies = new List <TargetAssembly>(); var scriptCompilerOptions = new ScriptCompilerOptions(); // Initialize predefined assembly targets foreach (var language in supportedLanguages) { var languageName = language.GetLanguageName(); var runtimeFirstPass = new TargetAssembly("Assembly-" + languageName + "-firstpass" + ".dll", language, AssemblyFlags.FirstPass, TargetAssemblyType.Predefined, null, FilterAssemblyInFirstpassFolder, null, scriptCompilerOptions); var runtime = new TargetAssembly("Assembly-" + languageName + ".dll", language, AssemblyFlags.None, TargetAssemblyType.Predefined, null, null, null, scriptCompilerOptions); var editorFirstPass = new TargetAssembly("Assembly-" + languageName + "-Editor-firstpass" + ".dll", language, AssemblyFlags.EditorOnly | AssemblyFlags.FirstPass, TargetAssemblyType.Predefined, null, FilterAssemblyInFirstpassEditorFolder, IsCompatibleWithEditor, scriptCompilerOptions) { OptionalUnityReferences = OptionalUnityReferences.TestAssemblies, }; var editor = new TargetAssembly("Assembly-" + languageName + "-Editor" + ".dll", language, AssemblyFlags.EditorOnly, TargetAssemblyType.Predefined, null, FilterAssemblyInEditorFolder, IsCompatibleWithEditor, scriptCompilerOptions) { OptionalUnityReferences = OptionalUnityReferences.TestAssemblies, }; runtimeFirstPassAssemblies.Add(runtimeFirstPass); runtimeAssemblies.Add(runtime); editorFirstPassAssemblies.Add(editorFirstPass); editorAssemblies.Add(editor); assemblies.Add(runtimeFirstPass); assemblies.Add(runtime); assemblies.Add(editorFirstPass); assemblies.Add(editor); } // Setup dependencies // Runtime assemblies depend all first pass runtime assemblies foreach (var assembly in runtimeAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); } // First pass editor assemblies depend on all first pass runtime assemblies foreach (var assembly in editorFirstPassAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); } // Editor assemblies depend on all previous runtime and editor assemblies foreach (var assembly in editorAssemblies) { assembly.References.AddRange(runtimeFirstPassAssemblies); assembly.References.AddRange(runtimeAssemblies); assembly.References.AddRange(editorFirstPassAssemblies); } return(assemblies.ToArray()); }
public ScriptAssemblySettings() { BuildTarget = BuildTarget.NoTarget; BuildTargetGroup = BuildTargetGroup.Unknown; PredefinedAssembliesCompilerOptions = new ScriptCompilerOptions(); }
private Assembly CreateAssembly(string name, string path, string[] files, string[] defines, Assembly[] assemblyReferences, string[] compiledAssemblyReferences, AssemblyFlags flags, ScriptCompilerOptions options, string rootNamespace) { return(new Assembly(name, path, files, defines, assemblyReferences, compiledAssemblyReferences, flags, options)); }
public ScriptAssembly() { CompilerOptions = new ScriptCompilerOptions(); }