No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectPart.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEditor.Compilation;
  4. using UnityEngine;
  5. namespace Packages.Rider.Editor.ProjectGeneration
  6. {
  7. internal class ProjectPart
  8. {
  9. public string Name { get; }
  10. public string OutputPath { get; }
  11. public Assembly Assembly { get; }
  12. public string AssetsProjectPart { get; }
  13. public string[] SourceFiles { get; }
  14. public string RootNamespace { get; }
  15. public Assembly[] AssemblyReferences { get; }
  16. public string[] CompiledAssemblyReferences { get; }
  17. public string[] Defines { get; }
  18. public ScriptCompilerOptions CompilerOptions { get; }
  19. public ProjectPart(string name, Assembly assembly, string assetsProjectPart)
  20. {
  21. Name = name;
  22. Assembly = assembly;
  23. AssetsProjectPart = assetsProjectPart;
  24. OutputPath = assembly != null ? assembly.outputPath : "Temp/Bin/Debug";
  25. SourceFiles = assembly != null ? assembly.sourceFiles : new string[0];
  26. #if UNITY_2020_2_OR_NEWER
  27. RootNamespace = assembly != null ? assembly.rootNamespace : string.Empty;
  28. #else
  29. RootNamespace = UnityEditor.EditorSettings.projectGenerationRootNamespace;
  30. #endif
  31. AssemblyReferences = assembly != null ? assembly.assemblyReferences : new Assembly[0];
  32. CompiledAssemblyReferences = assembly!=null? assembly.compiledAssemblyReferences:new string[0];
  33. Defines = assembly != null ? assembly.defines : new string[0];
  34. CompilerOptions = assembly != null ? assembly.compilerOptions : new ScriptCompilerOptions();
  35. }
  36. public IEnumerable<ResponseFileData> ParseResponseFileData(IAssemblyNameProvider assemblyNameProvider, string projectDirectory)
  37. {
  38. if (Assembly == null)
  39. return new ResponseFileData[0];
  40. var systemReferenceDirectories =
  41. CompilationPipeline.GetSystemAssemblyDirectories(Assembly.compilerOptions.ApiCompatibilityLevel);
  42. var responseFilesData = Assembly.compilerOptions.ResponseFiles.ToDictionary(
  43. x => x, x => assemblyNameProvider.ParseResponseFile(
  44. x,
  45. projectDirectory,
  46. systemReferenceDirectories
  47. ));
  48. var responseFilesWithErrors = responseFilesData.Where(x => x.Value.Errors.Any())
  49. .ToDictionary(x => x.Key, x => x.Value);
  50. if (responseFilesWithErrors.Any())
  51. {
  52. foreach (var error in responseFilesWithErrors)
  53. foreach (var valueError in error.Value.Errors)
  54. {
  55. Debug.LogError($"{error.Key} Parse Error : {valueError}");
  56. }
  57. }
  58. return responseFilesData.Select(x => x.Value);
  59. }
  60. }
  61. }