From 9fee3a29d02f92e5de1e0a8a120fa28502c60a6b Mon Sep 17 00:00:00 2001 From: SunSerega Date: Fri, 17 Jul 2020 07:02:36 +0300 Subject: [PATCH] SearchDir --- CodeCompletion/CodeCompletion.cs | 2 +- CodeCompletion/DomConverter.cs | 8 +++---- Compiler/Compiler.cs | 21 ++++++++----------- .../Workbench/RunnerManagerHandlers.cs | 3 +-- pabcnetc_clear/ConsoleCompiler.cs | 21 ++++++++++++------- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/CodeCompletion/CodeCompletion.cs b/CodeCompletion/CodeCompletion.cs index 36ec2f658..1f036c5d7 100644 --- a/CodeCompletion/CodeCompletion.cs +++ b/CodeCompletion/CodeCompletion.cs @@ -369,7 +369,7 @@ namespace CodeCompletion { List Dirs = new List(); Dirs.AddRange(ddirs); - Dirs.Add(CodeCompletionController.comp.CompilerOptions.SearchDirectory); + Dirs.AddRange(CodeCompletionController.comp.CompilerOptions.SearchDirectory); if (CodeCompletionController.StandartDirectories.ContainsKey(LibSourceDirectoryIdent)) Dirs.Add((string)CodeCompletionController.StandartDirectories[LibSourceDirectoryIdent]); return CodeCompletionController.comp.FindSourceFileNameInDirs(unit_name, Dirs.ToArray()); diff --git a/CodeCompletion/DomConverter.cs b/CodeCompletion/DomConverter.cs index cab0a23db..349ee77de 100644 --- a/CodeCompletion/DomConverter.cs +++ b/CodeCompletion/DomConverter.cs @@ -10,8 +10,8 @@ using System.Reflection; using PascalABCCompiler; using PascalABCCompiler.TreeConverter; using PascalABCCompiler.TreeRealization; -using PascalABCCompiler.Parsers; - +using PascalABCCompiler.Parsers; + namespace CodeCompletion { public struct RetValue @@ -47,8 +47,8 @@ namespace CodeCompletion private void InitModules() { try - { - string[] files = Directory.GetFiles(CodeCompletionController.comp.CompilerOptions.SearchDirectory, "*.pas"); + { + string[] files = Directory.GetFiles(Path.Combine(CodeCompletionController.comp.CompilerOptions.SystemDirectory, "Lib"), "*.pas"); standard_units = new SymInfo[files.Length]; int i = 0; foreach (string s in files) diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 2f5233630..701e8bdd9 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -164,6 +164,7 @@ using System.Reflection; //using SyntaxTreeChanger; using PascalABCCompiler.SyntaxTreeConverters; using System.Text; +using System.Linq; namespace PascalABCCompiler { @@ -546,7 +547,7 @@ namespace PascalABCCompiler // public string SystemDirectory; - public string SearchDirectory; + public List SearchDirectory; private bool useDllForSystemUnits = false; @@ -645,12 +646,13 @@ namespace PascalABCCompiler private void SetDirectories() { - SystemDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); - SearchDirectory = Path.Combine(SystemDirectory,"Lib"); + SystemDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName); + StandartDirectories = new Hashtable(StringComparer.InvariantCultureIgnoreCase); StandartDirectories.Add("%PABCSYSTEM%", SystemDirectory); - ParserSearchPatchs = new string[1]; - ParserSearchPatchs[0] = SearchDirectory; + + ParserSearchPatchs = new string[] { Path.Combine(SystemDirectory, "Lib") }; + SearchDirectory = ParserSearchPatchs.ToList(); } @@ -2456,7 +2458,7 @@ namespace PascalABCCompiler res = Tuple.Create(res_s1, 1); else if (FindFileInDirs(Path.GetFileName(fname), CompilerOptions.OutputDirectory) is string res_s2) res = Tuple.Create(res_s2, 2); - else if (FindFileInDirs(fname, CompilerOptions.SearchDirectory) is string res_s3) + else if (FindFileInDirs(fname, CompilerOptions.SearchDirectory.ToArray()) is string res_s3) res = Tuple.Create(res_s3, 3); else res = null; @@ -2477,7 +2479,7 @@ namespace PascalABCCompiler if (FindSourceFileNameInDirs(fname, curr_path) is string res_s1) res = Tuple.Create(res_s1, 1); - else if (FindSourceFileNameInDirs(fname, CompilerOptions.SearchDirectory) is string res_s3) + else if (FindSourceFileNameInDirs(fname, CompilerOptions.SearchDirectory.ToArray()) is string res_s3) res = Tuple.Create(res_s3, 3); else res = null; @@ -2671,11 +2673,6 @@ namespace PascalABCCompiler return res; } - private bool FileInSearchDirectory(string FileName) - { - return Path.GetDirectoryName(FileName).ToLower() == CompilerOptions.SearchDirectory.ToLower(); - } - public void AddStandartUnitsToUsesSection(SyntaxTree.compilation_unit cu) { //if (FileInSearchDirectory(cu.file_name)) return; diff --git a/VisualPascalABCNET/Workbench/RunnerManagerHandlers.cs b/VisualPascalABCNET/Workbench/RunnerManagerHandlers.cs index 517f5b192..f647c4cb6 100644 --- a/VisualPascalABCNET/Workbench/RunnerManagerHandlers.cs +++ b/VisualPascalABCNET/Workbench/RunnerManagerHandlers.cs @@ -120,8 +120,7 @@ namespace VisualPascalABC if (ToSend == null && File.Exists(StackTraceItem.SourceFileName)) ToSend = StackTraceItem; if (Workbench.UserOptions.SkipStakTraceItemIfSourceFileInSystemDirectory && - (Path.GetDirectoryName(StackTraceItem.SourceFileName) == WorkbenchServiceFactory.BuildService.CompilerOptions.SearchDirectory || - Path.GetDirectoryName(StackTraceItem.SourceFileName) == WorkbenchServiceFactory.BuildService.CompilerOptions.SearchDirectory+"Source")) + StackTraceItem.SourceFileName.StartsWith(WorkbenchServiceFactory.BuildService.CompilerOptions.SystemDirectory)) continue; if (!(bool)Workbench.VisualEnvironmentCompiler.SourceFilesProvider(StackTraceItem.SourceFileName, PascalABCCompiler.SourceFileOperation.Exists)) { diff --git a/pabcnetc_clear/ConsoleCompiler.cs b/pabcnetc_clear/ConsoleCompiler.cs index 07b484453..3a635334e 100644 --- a/pabcnetc_clear/ConsoleCompiler.cs +++ b/pabcnetc_clear/ConsoleCompiler.cs @@ -74,13 +74,19 @@ namespace PascalABCCompiler Console.WriteLine("Bad value in 'Debug' directive '{0}'. Acceptable values are 0 or 1", value); return false; } - case "output": - co.OutputFileName = Path.GetFileName(value); - if (Path.IsPathRooted(value)) - { - co.OutputDirectory = Path.GetDirectoryName(value); - } - return true; + + case "output": + co.OutputFileName = Path.GetFileName(value); + if (Path.IsPathRooted(value)) + { + co.OutputDirectory = Path.GetDirectoryName(value); + } + return true; + + case "searchdir": + co.SearchDirectory.Insert(0, value); // .Insert, чтобы определённые пользователем папки имели бОльший приоритет, чем стандартная + return true; + default: Console.WriteLine("No such directive name: '{0}'", name); return false; @@ -105,6 +111,7 @@ namespace PascalABCCompiler Console.WriteLine("Available directives:\n /Help /H /?\n /Debug:0(1)\n /output:[\\name]\n"); Console.WriteLine("/output:[ \\name ] compile into an executable called \"name\" and save it in \"path\" directory"); Console.WriteLine("/Debug:0 generates code with all .NET optimizations!"); + Console.WriteLine("/SearchDir: add \"path\" to list of standart unit search directories. Last added paths would be searched first"); } public static int Main(string[] args)