Skip to content

Commit

Permalink
- Issue #260: Double Entry Point Definition
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Nov 21, 2021
1 parent 41396dd commit aa20359
Showing 1 changed file with 43 additions and 30 deletions.
73 changes: 43 additions & 30 deletions src/cscs/ScriptParser.cs
Expand Up @@ -33,12 +33,15 @@ public ScriptParsingResult GetContext()
}

/// <summary>
/// Processes the imported script. Processing involves lookup for 'static Main' and renaming it so it does not
/// interfere with the 'static Main' of the primary script. After renaming is done the new content is saved in the
/// CS-Script cache and the new file location is returned. The saved file can be used late as an "included script".
/// This technique can be from 'precompiler' scripts.
/// <para>If the script file does not require renaming (static Main is not present) the method returns the
/// original script file location.</para>
/// Processes the imported script. Processing involves lookup for 'static Main' and renaming
/// it so it does not interfere with the 'static Main' of the primary script. After renaming
/// is done the new content is saved in the CS-Script cache and the new file location is
/// returned. The saved file can be used late as an "included script". This technique can be
/// from 'precompiler' scripts.
/// <para>
/// If the script file does not require renaming (static Main is not present) the method
/// returns the original script file location.
/// </para>
/// </summary>
/// <param name="scriptFile">The script file.</param>
/// <returns>Path to the script file to be compiled and executed</returns>
Expand Down Expand Up @@ -94,12 +97,18 @@ public string[] ReferencedResources

/// <summary>
/// Resolves the NuGet packages into assemblies to be referenced by the script.
/// <para>If the package was never installed/downloaded yet CS-Script runtime will try to download it.</para>
/// <para>CS-Script will also analyze the installed package structure in try to reference compatible assemblies
/// from the package.</para>
/// <para>
/// If the package was never installed/downloaded yet CS-Script runtime will try to download it.
/// </para>
/// <para>
/// CS-Script will also analyze the installed package structure in try to reference
/// compatible assemblies from the package.
/// </para>
/// </summary>
/// <param name="suppressDownloading">if set to <c>true</c> suppresses downloading the NuGet package.
/// Suppressing can be useful for the quick 'referencing' assessment.</param>
/// <param name="suppressDownloading">
/// if set to <c>true</c> suppresses downloading the NuGet package. Suppressing can be
/// useful for the quick 'referencing' assessment.
/// </param>
/// <returns>Collection of the referenced assembly files.</returns>
public string[] ResolvePackages(bool suppressDownloading = false)
{
Expand All @@ -116,7 +125,8 @@ public string[] ResolvePackages(bool suppressDownloading = false)
public string[] Packages => packages.ToArray();

/// <summary>
/// Collection of referenced assemblies. All assemblies are referenced either from command-line, code or resolved from referenced namespaces.
/// Collection of referenced assemblies. All assemblies are referenced either from
/// command-line, code or resolved from referenced namespaces.
/// </summary>
public string[] ReferencedAssemblies => referencedAssemblies.ToArray();

Expand All @@ -133,7 +143,7 @@ public ScriptParser(string fileName)
/// Constructor.
/// </summary>
/// <param name="fileName">Script file name</param>
/// <param name="searchDirs">Extra ScriptLibrary directory </param>
/// <param name="searchDirs">Extra ScriptLibrary directory</param>
public ScriptParser(string fileName, string[] searchDirs)
{
//if ((CSExecutor.ExecuteOptions.options != null && CSExecutor.options.useSmartCaching) && CSExecutor.ScriptCacheDir == "") //in case if ScriptParser is used outside of the script engine
Expand All @@ -146,8 +156,10 @@ public ScriptParser(string fileName, string[] searchDirs)
/// Constructor.
/// </summary>
/// <param name="fileName">Script file name</param>
/// <param name="searchDirs">Extra ScriptLibrary directory(s) </param>
/// <param name="throwOnError">flag to indicate if the file parsing/processing error should raise an exception</param>
/// <param name="searchDirs">Extra ScriptLibrary directory(s)</param>
/// <param name="throwOnError">
/// flag to indicate if the file parsing/processing error should raise an exception
/// </param>
public ScriptParser(string fileName, string[] searchDirs, bool throwOnError)
{
this.throwOnError = throwOnError;
Expand All @@ -165,16 +177,14 @@ public ScriptParser(string fileName, string[] searchDirs, bool throwOnError)
/// <summary>
/// Gets a value indicating whether the script being parsed is a web application script.
/// </summary>
/// <value>
/// <c>true</c> if the script is web application; otherwise, <c>false</c>.
/// </value>
/// <value><c>true</c> if the script is web application; otherwise, <c>false</c>.</value>
public bool IsWebApp => this.fileParsers.FirstOrDefault()?.IsWebApp == true;

/// <summary>
/// Initialization of ScriptParser instance
/// </summary>
/// <param name="fileName">Script file name</param>
/// <param name="searchDirs">Extra ScriptLibrary directory(s) </param>
/// <param name="searchDirs">Extra ScriptLibrary directory(s)</param>

void Init(string fileName, string[] searchDirs)
{
Expand Down Expand Up @@ -247,7 +257,9 @@ void ProcessFile(ScriptInfo fileInfo)

this.fileParsers.Add(importedFile);
this.fileParsers.Sort(fileComparer);
importedFile.fileNameImported = importedFile.fileName;

if (importedFile.fileNameImported.IsEmpty())
importedFile.fileNameImported = importedFile.fileName;

foreach (string namespaceName in importedFile.ReferencedNamespaces)
PushNamespace(namespaceName);
Expand Down Expand Up @@ -409,11 +421,13 @@ void AddIfNotThere(List<string> list, string item)
}

/// <summary>
/// Aggregates the references from the script and its imported scripts. It is a logical equivalent of CSExecutor.AggregateReferencedAssemblies
/// but optimized for later .NET versions (e.g LINQ) and completely decoupled. Thus it has no dependencies on internal state
/// (e.g. settings, options.shareHostAssemblies).
/// <para>It is the method to call for generating list of ref asms as part of the project info.</para>
///
/// Aggregates the references from the script and its imported scripts. It is a logical
/// equivalent of CSExecutor.AggregateReferencedAssemblies but optimized for later .NET
/// versions (e.g LINQ) and completely decoupled. Thus it has no dependencies on internal
/// state (e.g. settings, options.shareHostAssemblies).
/// <para>
/// It is the method to call for generating list of ref asms as part of the project info.
/// </para>
/// </summary>
/// <param name="searchDirs">The search dirs.</param>
/// <param name="defaultRefAsms">The default ref asms.</param>
Expand All @@ -428,7 +442,8 @@ public List<string> AgregateReferences(IEnumerable<string> searchDirs, IEnumerab
var refCodeAsms = this.ReferencedAssemblies
.SelectMany(asm => AssemblyResolver.FindAssembly(asm.Replace("\"", ""), probingDirs)).ToArray();

// need to add default CLR assemblies as there will be no namespace->GAC assembly resolving as it is .NET Core
// need to add default CLR assemblies as there will be no namespace->GAC assembly
// resolving as it is .NET Core
var clrDefaultAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.StartsWith("System.")).Select(x => x.Location).ToArray();

var refAsms = refPkAsms.Union(refPkAsms)
Expand Down Expand Up @@ -473,10 +488,8 @@ static string[] FilterDuplicatedAssembliesByFileName(string[] assemblies)
{
try
{
// need to ensure that item has extension in order to avoid interpreting
// complex file names as simple name + extension:
// System.Core -> System
// System.dll -> System
// need to ensure that item has extension in order to avoid interpreting complex
// file names as simple name + extension: System.Core -> System System.dll -> System
string name = item.GetFileNameWithoutExtension();
if (!asmNames.Contains(name))
{
Expand Down

0 comments on commit aa20359

Please sign in to comment.