Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Add Scriptcs plugins support #229

Merged
merged 35 commits into from
May 5, 2015
Merged

Add Scriptcs plugins support #229

merged 35 commits into from
May 5, 2015

Conversation

laedit
Copy link
Member

@laedit laedit commented Mar 29, 2015

Fix #217.

Thanks to @vikingcode and @glennblock this PR allow Pretzel to have plugins as easily as to create a *.csx file in the _plugins folder.

But like @vikingcode has already said for some parts:

  • the projects are now upgraded to .NET 4.5
  • the total size of all dlls / exes is now about 13 mo (we can gain some size if we make a release for Windows (Roslyin) and another for Linux (Mono.Cecil) but I don't know if it worth it)
  • the merging is no longer supported, ILMerge and ILRepack explodes over a StackOverflowException. I haven't tried Fody.Costura but as stated on Pretzel on Mono #215 it doesn't seems to work for Mono, so between that and the total size of files, I think we should just embrace all the little dlls and stop the merging.

@shiftkey, @JakeGinnivan your thoughts?

@glennblock
Copy link

Why not have it be an opt-in add on package like Pretzel.ScriptCs. Is that
not possible?
On Sun, Mar 29, 2015 at 6:04 AM Jérémie Bertrand notifications@github.com
wrote:

Fix #217 #217.

Thanks to @vikingcode https://github.com/vikingcode and @glennblock
https://github.com/glennblock this PR allow Pretzel to have plugins as
easily as to create a *.csx file in the _plugins folder.

But like @vikingcode https://github.com/vikingcode has already said for
some parts:

@shiftkey https://github.com/shiftkey, @JakeGinnivan

https://github.com/JakeGinnivan your thoughts?

You can view, comment on, or merge this pull request online at:

#229
Commit Summary

  • Update to .NET 4.5
  • Add ScriptCsCatalog usage

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#229.

@laedit
Copy link
Member Author

laedit commented Mar 29, 2015

Like always you give great advice, I will try that.

@glennblock
Copy link

@laedit not always, but at least some of the time :-)

It would seem based on what I know about this, that it should be possible to keep the scriptcs dependency out of Pretzel. Maybe allow passing in a catalog, which means just the MEF dependency is sufficient, or have a non-MEF specific plugin interface.

@@ -102,6 +103,7 @@ private void LoadPlugins(string[] commandArgs)
if (Directory.Exists(pluginsPath))
{
catalog.Catalogs.Add(new DirectoryCatalog(pluginsPath));
catalog.Catalogs.Add(new ScriptCsCatalog(pluginsPath, new ScriptCsCatalogOptions { References = new[] { typeof(DotLiquid.Tag), typeof(Pretzel.Logic.Extensibility.ITag) } }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding the dependency on scriptcs, you could find the catalog and dynamically load it. There's a host of diff strategies you could use to do this. One could be checking if the assembly exists, and if it does you dynamically load it and instantiate yourself via reflection. You could move ScriptcsCatalogOptions to a separate Pretzel.ScriptCs.Contracts package so that Pretzel and the Pretzel.ScriptCs package can reference it, this way Pretzel can still construct and pass in the options easily.

@glennblock
Copy link

I comment in the PR on one way you might handle this.

On Sun, Mar 29, 2015 at 12:36 PM Jérémie Bertrand notifications@github.com
wrote:

Like always you give great advice, I will try that.


Reply to this email directly or view it on GitHub
#229 (comment).

@glennblock
Copy link

comment[ed]

On Sun, Mar 29, 2015 at 12:56 PM Glenn Block glenn.block@gmail.com wrote:

I comment in the PR on one way you might handle this.

On Sun, Mar 29, 2015 at 12:36 PM Jérémie Bertrand <
notifications@github.com> wrote:

Like always you give great advice, I will try that.


Reply to this email directly or view it on GitHub
#229 (comment).

@laedit
Copy link
Member Author

laedit commented Mar 29, 2015

Since we already use MEF both for internals and plugins I was thinking to use it again, like loading the Pretzel.ScriptCs if exists and include it in the main catalog. Don't know if the DirectoryCatalog with a search pattern likePretzel.ScriptCs.dll will do the trick or if it's better to check and load it manually.
The Pretzel.ScriptCs.Contracts is a great idea, I will keep it in mind thanks.

@JakeGinnivan
Copy link
Member

That would actually be quite cool, grab the ScriptCs plugin then ScriptCs extensibility just works.

@glennblock
Copy link

Yep!

On Mon, Mar 30, 2015 at 2:43 AM Jake Ginnivan notifications@github.com
wrote:

That would actually be quite cool, grab the ScriptCs plugin then ScriptCs
extensibility just works.


Reply to this email directly or view it on GitHub
#229 (comment).

@laedit
Copy link
Member Author

laedit commented Mar 30, 2015

I made a quick and dirty test, but I face the same problem:

  • if I merge all dlls including Pretzel.ScriptCs.Contracts there is a cast exception caused by the class used to transmit parameters to the ScriptCsCatalog: the runtime cannot convert the type from the merged Pretzel assembly to the original Pretzel.ScriptCs.Contracts assembly
  • if I try to not merge Pretzel.ScriptCs.Contracts, ILMerge throw an exception:
    Unresolved assembly reference not allowed: Pretzel.ScriptCs.Contracts.. ILRepack goes to a stack overflow...

Did I miss something?
Or we abandon the merging?

@glennblock
Copy link

I wasn't suggesting Contracts is merged. Pretzel.ScriptCs.Contracts should
be in a package that Pretzel and Pretzel.ScriptCs both reference. I don't
see how that can work with ILMerge.

On Mon, Mar 30, 2015 at 1:36 PM Jérémie Bertrand notifications@github.com
wrote:

I made a quick and dirty test, but I face the same problem:

  • if I merge all dlls including Pretzel.ScriptCs.Contracts there is a
    cast exception caused by the class used to transmit parameters to the
    ScriptCsCatalog: the runtime cannot convert the type from the merged
    Pretzel assembly to the original Pretzel.ScriptCs.Contracts assembly
  • if I try to not merge Pretzel.ScriptCs.Contracts, ILMerge throw an
    exception: Unresolved assembly reference not allowed:
    Pretzel.ScriptCs.Contracts.. ILRepack goes to a stack overflow...

Did I miss something?
Or we abandon the merging?


Reply to this email directly or view it on GitHub
#229 (comment).

@laedit
Copy link
Member Author

laedit commented Mar 31, 2015

That's what I was trying to do in my second point: Pretzel.ScriptCs.Contracts isn't part of the Pretzel merge, but int that case ILMerge can't work.
Or at least I haven't figured out how to make it work.

@glennblock
Copy link

I know very little about ILMerge but can't be much help her.

If an ILMerged assembly must have all dependencies merged, then it sounds
like you won't be able to split out the catalog functionality.

On Mon, Mar 30, 2015 at 9:09 PM Jérémie Bertrand notifications@github.com
wrote:

That's what I was trying to do in my second point:
Pretzel.ScriptCs.Contracts isn't part of the Pretzel merge, but int that
case ILMerge can't work.
Or at least I haven't figured out how to make it work.


Reply to this email directly or view it on GitHub
#229 (comment).

@JakeGinnivan
Copy link
Member

@SimonCropp @distantcam any ideas?

Sent from my Windows Phone


From: Glenn Blockmailto:notifications@github.com
Sent: ý31/ý03/ý2015 07:59
To: Code52/pretzelmailto:pretzel@noreply.github.com
Cc: Jake Ginnivanmailto:jake@ginnivan.net
Subject: Re: [pretzel] Add Scriptcs plugins support (#229)

I know very little about ILMerge but can't be much help her.

If an ILMerged assembly must have all dependencies merged, then it sounds
like you won't be able to split out the catalog functionality.

On Mon, Mar 30, 2015 at 9:09 PM Jérémie Bertrand notifications@github.com
wrote:

That's what I was trying to do in my second point:
Pretzel.ScriptCs.Contracts isn't part of the Pretzel merge, but int that
case ILMerge can't work.
Or at least I haven't figured out how to make it work.


Reply to this email directly or view it on GitHub
#229 (comment).


Reply to this email directly or view it on GitHubhttps://github.com//pull/229#issuecomment-87968058.

@glennblock
Copy link

Thinking about this more I have an idea of how you can do this which won't require Pretzel to reference the shared contracts directly. A new assembly (say Pretzel.ScriptCs) will contain a ScriptCsCatalogFactory (the answer to all things!). The factory will manufacture a ScriptCsCatalog and return it casted as a ComposablePartCatalog. If Pretzel needs to pass in types and such it can do it via the factory. The factory only exposes primitive / framework types, so it can easily be invoked via reflection. Pretzel will dynamically look for the factory and load it and then invoke it to get the catalog.

The code will look something like this...

public static class ScriptCsCatalogFactory {
  public static ComposablePartCatalog Create(string[] scriptArgs, Type[] references)
  {
    var options = new ScriptCsCatalogOptions {...};
    return new ScriptCsCatalog(options);
}

@distantcam
Copy link
Contributor

ScriptCs had issues whenever I tried folding it into another assembly. There's a few ScriptCs classes that need to be reworked, and then there was a showstopper in Roslyn that meant I couldn't continue. Having said that I was trying this on the version of ScriptCs that used the old version of Roslyn. I haven't tried it since the update.

@glennblock
Copy link

Scriptcs still relies on the old version of Roslyn on Windows. You can
install the ScriptCs.Rosyln.Engines module to try the newer Roslyn.
On Tue, Mar 31, 2015 at 1:02 AM Cameron MacFarland notifications@github.com
wrote:

ScriptCs had issues whenever I tried folding it into another assembly.
There's a few ScriptCs classes that need to be reworked, and then there was
a showstopper in Roslyn that meant I couldn't continue. Having said that I
was trying this on the version of ScriptCs that used the old version of
Roslyn. I haven't tried it since the update.


Reply to this email directly or view it on GitHub
#229 (comment).

@laedit
Copy link
Member Author

laedit commented Mar 31, 2015

Praise to @glennblock and shame on me. Following your comment I was so focused on the idea of using a Pretzel.ScriptCs.Contracts assembly to pass parameters that I haven't realized that it was the problem and wasn't really needed. Sorry for the fuss.

Just for testing purpose I tried to merge the Pretzel.ScriptCs and all his references (ScriptCs + Engine.Roslyn) but ILMerge still goes to a stack overflow.

@laedit
Copy link
Member Author

laedit commented Apr 21, 2015

Thanks to the recommendations of @ferventcoder, Pretzel will install itself in "C:\tools\Pretzel" (BinRoot or soon ToolsRoot in Chocolatey world) and so does Pretzel.ScriptCs.
@JakeGinnivan, @shiftkey are you ok with that?

@JakeGinnivan
Copy link
Member

No objections from me

laedit pushed a commit that referenced this pull request May 5, 2015
Add Scriptcs plugins support
@laedit laedit merged commit 883c113 into master May 5, 2015
@laedit laedit deleted the scriptcs-plugin branch May 5, 2015 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins/scripts
4 participants