Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path to Scripts Does Not Work For Tokenized Paths or For Paths Relative to Config File Path #18

Closed
dmealo opened this issue Jun 26, 2018 · 9 comments

Comments

@dmealo
Copy link
Contributor

dmealo commented Jun 26, 2018

I'm trying to use the NuGet package version and specify the path to the scripts which I want in source control (but not the binaries), but Leprechaun seems to always append whatever path I specify to the path where the executable is (/packages/Leprechaun + /...) which is not to be in source control.

I've tried tokenized paths like $(ConfigDirectory), ./../../../Foundation/... and others, but it's always appended.

Here is the error output I'm getting since it can't find the scripts below the exe in the NuGet packages folder:

[16:21:36] Using gulpfile ~\Source\Repos\Website\Gulpfile.js
[16:21:36] Starting '07-Code-Generate-Models'...
  _                             _                       
 | |    ___ _ __  _ __ ___  ___| |__   __ _ _   _ _ __  
 | |   / _ \ '_ \| '__/ _ \/ __| '_ \ / _` | | | | '_ \ 
 | |__|  __/ |_) | | |  __/ (__| | | | (_| | |_| | | | |
 |_____\___| .__/|_|  \___|\___|_| |_|\__,_|\__,_|_| |_|
           |_|                       Version 1.0.1-pre01
                 @@                 .###@@::;%%&&00'
                @><@               .###@@::;%%&&00'
          ________)               .###@@::;%%&&00'
         |        |              .###@@::;%%&&00'
    _   _|===LI===|_            .###@@::;%%&&00'
   / \_(____________)          .###@@::;%%&&00'
   \  / (88 o  o 88)          .###@@::;%%&&00'
    \/\  88:  7 :88`         .###@@::;%%&&00'
     \/\ '88'=='88'         .###@@::;%%&&00'
      \ \__'8888'__________.###@@::;%%&&00'
       \___<\""/>_____/_/_.###@@::;%%&&00'
          /  ><  \       .###@@::;%%&&00'
        / __/--\__\     (oO@OoO@@o@oO@@o)
        '-.______.-'    /`"""""""""""""`\
          _|_||_|_     |                 |
       ___LI)||(LI___  |                 |
      (   ~~ || ~~   )  \               /
       `-----''-----`    '.___________.'
 
Loaded metadata for 17 configurations (0 total templates) in 156ms.
Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Code generation script 'C:\Users\david\Source\Repos\Website\packages\Leprechaun.Console.1.0.1-pre01\lib\net46\.\src\Foundation\CodeGen\code\Scripts\Diagnostics.csx' was not found on disk.
   at Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator.<ProcessScripts>b__7_0(String script)
   at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorResults.GetElement(Int32 index)
   at System.Linq.Parallel.QueryResults`1.get_Item(Int32 index)
   at System.Linq.Parallel.PartitionedDataSource`1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey)
   at System.Linq.Parallel.StopAndGoSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.<>c.<.cctor>b__10_0(Object o)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream`2 partitions, SynchronousChannel`1[] channels, TaskScheduler taskScheduler)
   at System.Linq.Parallel.DefaultMergeHelper`2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute()
   at System.Linq.Parallel.MergeExecutor`1.Execute()
   at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
   at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)
   at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
   at System.Linq.Parallel.QueryOperator`1.ExecuteAndGetResultsAsArray()
   at System.Linq.ParallelEnumerable.ToArray[TSource](ParallelQuery`1 source)
   at Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator.ProcessScripts(String scripts)
   at lambda_method(Closure , Object[] )
   at Configy.Containers.MicroContainer.Activate(Type type, KeyValuePair`2[] unmappedConstructorParameters)
   at Configy.XmlContainerBuilder.<>c__DisplayClass5_0.<RegisterConfigTypeInterface>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Configy.Containers.MicroContainer.Resolve(Type type)
   at Configy.Containers.MicroContainer.Resolve[T]()
   at Leprechaun.Console.Program.<>c__DisplayClass0_0.<Main>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Leprechaun.Console.Program.Main(String[] args)
[16:21:37] '07-Code-Generate-Models' errored after 529 ms
[16:21:37] Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c ".\packages\Leprechaun.Console.1.0.1-pre01\lib\net46\Leprechaun.console.exe /c .\src\Foundation\CodeGen\code\Leprechaun.config"
Unhandled Exception: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Code generation script 'C:\Users\david\Source\Repos\Website\packages\Leprechaun.Console.1.0.1-pre01\lib\net46\.\src\Foundation\CodeGen\code\Scripts\Diagnostics.csx' was not found on disk.
   at Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator.<ProcessScripts>b__7_0(String script)
   at System.Linq.Parallel.SelectQueryOperator`2.SelectQueryOperatorResults.GetElement(Int32 index)
   at System.Linq.Parallel.QueryResults`1.get_Item(Int32 index)
   at System.Linq.Parallel.PartitionedDataSource`1.ListContiguousIndexRangeEnumerator.MoveNext(T& currentElement, Int32& currentKey)
   at System.Linq.Parallel.StopAndGoSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Linq.Parallel.QueryTask.<>c.<.cctor>b__10_0(Object o)
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.SpoolingTask.SpoolStopAndGo[TInputOutput,TIgnoreKey](QueryTaskGroupState groupState, PartitionedStream`2 partitions, SynchronousChannel`1[] channels, TaskScheduler taskScheduler)
   at System.Linq.Parallel.DefaultMergeHelper`2.System.Linq.Parallel.IMergeHelper<TInputOutput>.Execute()
   at System.Linq.Parallel.MergeExecutor`1.Execute()
   at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2 partitions, Boolean ignoreOutput, ParallelMergeOptions options, TaskScheduler taskScheduler, Boolean isOrdered, CancellationState cancellationState, Int32 queryId)
   at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2 partitionedStream)
   at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1 recipient)
   at System.Linq.Parallel.QueryOperator`1.ExecuteAndGetResultsAsArray()
   at System.Linq.ParallelEnumerable.ToArray[TSource](ParallelQuery`1 source)
   at Leprechaun.CodeGen.Roslyn.CSharpScriptCodeGenerator.ProcessScripts(String scripts)
   at lambda_method(Closure , Object[] )
   at Configy.Containers.MicroContainer.Activate(Type type, KeyValuePair`2[] unmappedConstructorParameters)
   at Configy.XmlContainerBuilder.<>c__DisplayClass5_0.<RegisterConfigTypeInterface>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at Configy.Containers.MicroContainer.Resolve(Type type)
   at Configy.Containers.MicroContainer.Resolve[T]()
   at Leprechaun.Console.Program.<>c__DisplayClass0_0.<Main>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Leprechaun.Console.Program.Main(String[] args)
    at ChildProcess.exithandler (child_process.js:213:12)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
Process terminated with code 1.```
@blipson89
Copy link
Owner

Hi,
configDirectory is case sensitive. Please try using $(configDirectory) which should resolve to where the config file is.

What arguments are you passing the exe?

-Ben

@dmealo
Copy link
Contributor Author

dmealo commented Jun 26, 2018

Thanks for your reply! I am using $(configDirectory). Sorry, I typed that wrong here, but had it correct in the config:

		`<codeGenerator scripts="$(configDirectory)\Scripts\Synthesis.csx, $(configDirectory)\Scripts\Constants.csx, $(configDirectory)\Scripts\Diagnostics.csx" outputFile="$(configDirectory)\$(layer)\$(module)\code\Models\Templates.cs" />`

Here is my Gulp script which uses -c (adapted from a SitecoreMasters post). I went to check what the arguments were, but was getting an exception for a missing dependency at the time and forgot to check later:

// Run Leprechaun to Code Generate Models
gulp.task('07-Code-Generate-Models', function(x) {
  exec('.\\packages\\Leprechaun.Console.Runner.1.0.1-pre01\\Tools\\build\\Leprechaun\\Leprechaun.console.exe /c .\\src\\Foundation\\CodeGen\\code\\Leprechaun.config', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    x(err);
  });
});

@dmealo
Copy link
Contributor Author

dmealo commented Jun 26, 2018

I believe I have found the source of the issue (why it is neither detokenizing configDirectory nor starting from the configDirectory by default as I assumed all paths would do given this comment in Leprechaun.config). I think it is this block:

scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, scriptPath);

// not an absolute drive path, in which case we want to prepend the current exe path to it
					if (scriptPath[1] != ':')
					{
						scriptPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, scriptPath);
					}

Perhaps it can be refactored to work similarly to this (and surrounding code)?:

return Path.Combine(Path.GetDirectoryName(_configFilePath), glob);

Thanks,
David

@blipson89
Copy link
Owner

we came to similar conclusions 😃 ddf704d

Can you try this exe and see if that solves your problem? It'll ensure that all relative paths are converted to absolute, using the path to the exe as the base.
Leprechaun-1.0.1-pre02.zip

@dmealo
Copy link
Contributor Author

dmealo commented Jun 27, 2018

Hi,

Thanks for the reply, but that seems to be causing a new problem: it seems to be looking for the Leprechaun.config in a combination of the exe path and the path I'm specifying for the Leprechaun.config. This is the problem that I was having with the code gen scripts (e.g. Synthesis.csx) path as well.

Here is the shortened log error:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\david\Source\Repos\Website\packages\Leprechaun.Console.Runner.1.0.1-pre02\src\Foundation\CodeGen\code\Leprechaun.config'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Threading.CompressedStack.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) at System.Xml.XmlTextReaderImpl.OpenUrl() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.Load(String filename) at Leprechaun.Console.Program.BuildConfiguration(ConsoleArgs args) at Leprechaun.Console.Program.Main(String[] args)

I have a feeling there may be a misunderstanding from reading your last comment as well. I was hoping that Leprechaun would use the configDirectory as the base for forming the path to the scripts (and also the Leprechaun.config at this point as it was before). It was having an issue finding the config file before, just the scripts files.

Thanks again!

@blipson89
Copy link
Owner

I'll take a closer look tomorrow afternoon and get back to you. I agree - I think I misunderstood the issue you were having.

@dmealo
Copy link
Contributor Author

dmealo commented Jun 28, 2018

Per our outside conversation, I changed the way the path to the config was specified as you suggested (..\..\src\Foundation\CodeGen\code\Leprechaun.config instead of .\src\Foundation\CodeGen\code\Leprechaun.config) and that resolved all issues with paths - thank you!

Just a reminder that the version of the Runner package with the fix (1.0.1-pre02) is not on NuGet yet.

@blipson89
Copy link
Owner

@DavidMtbg It's on its way up to NuGet now 😃

@blipson89
Copy link
Owner

This was merged in a long time ago. Closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants