Adds a script processor for super flexible text generation

This commit is contained in:
Zontreck 2023-08-10 16:44:38 -07:00
parent e8339e4955
commit 0edc8104c9
84 changed files with 438 additions and 6 deletions

10
.gitignore vendored
View file

@ -396,3 +396,13 @@ FodyWeavers.xsd
# JetBrains Rider # JetBrains Rider
*.sln.iml *.sln.iml
# Exclude any new files in the bootstrap folder, only the manually added prebuild bootstrap
bootstrap/debug
bootstrap/*.pdb
bootstrap/*.exe
bootstrap/**
bootstrap
*.sln

Binary file not shown.

4
compile.bat Normal file
View file

@ -0,0 +1,4 @@
@echo off
runprebuild.bat
dotnet build -c Release

5
compile.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# Use the prebuild bootstrap to compile prebuild
./runprebuild.sh
dotnet build -c Release

View file

@ -26,7 +26,7 @@
<File>prebuild.xml</File> <File>prebuild.xml</File>
</Files> </Files>
<Project name="Prebuild" <Project name="Prebuild"
path="src" path="source/Prebuild"
language="C#" language="C#"
assemblyName="prebuild" assemblyName="prebuild"
icon="App.ico" icon="App.ico"
@ -48,20 +48,25 @@
<Options> <Options>
<CompilerDefines>DEBUG;TRACE</CompilerDefines> <CompilerDefines>DEBUG;TRACE</CompilerDefines>
<OptimizeCode>false</OptimizeCode> <OptimizeCode>false</OptimizeCode>
<OutputPath>bin/Debug</OutputPath> <OutputPath>../../bootstrap/debug</OutputPath>
<DebugInformation>true</DebugInformation> <DebugInformation>true</DebugInformation>
<KeyFile>Prebuild.snk</KeyFile> <KeyFile>Prebuild.snk</KeyFile>
<SuppressWarnings>1595</SuppressWarnings> <SuppressWarnings>1595</SuppressWarnings>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</Options> </Options>
</Configuration> </Configuration>
<Configuration name="Release"> <Configuration name="Release">
<Options> <Options>
<CompilerDefines>TRACE</CompilerDefines> <CompilerDefines>TRACE</CompilerDefines>
<OutputPath>bin/Release</OutputPath> <OutputPath>../../bootstrap/</OutputPath>
<OptimizeCode>true</OptimizeCode> <OptimizeCode>true</OptimizeCode>
<DebugInformation>false</DebugInformation> <DebugInformation>false</DebugInformation>
<KeyFile>Prebuild.snk</KeyFile> <KeyFile>Prebuild.snk</KeyFile>
<SuppressWarnings>1595</SuppressWarnings> <SuppressWarnings>1595</SuppressWarnings>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</Options> </Options>
</Configuration> </Configuration>
<Reference name="System.EnterpriseServices" /> <Reference name="System.EnterpriseServices" />
@ -74,5 +79,34 @@
</Match> </Match>
</Files> </Files>
</Project> </Project>
<Project name="SnapWrap"
path="source/snapwrap"
language="C#"
type="Exe"
version="1.0.1"
rootNamespace="dev.zontreck.snap"
startupObject="dev.zontreck.snap.Wrap">
<Author>Tara Piccari (tarapiccari@gmail.com)</Author>
<Description>C# Prebuild Scripting for code generation</Description>
<Configuration name="Debug">
<Options>
<OutputPath>../../bootstrap/debug/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../bootstrap/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</Options>
</Configuration>
<PackageReference name="Microsoft.CodeAnalysis.CSharp" version="4.6.0"/>
<PackageReference name="Microsoft.CodeAnalysis.CSharp.Scripting" version="4.6.0"/>
</Project>
</Solution> </Solution>
</Prebuild> </Prebuild>

View file

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/bash
dotnet bootstrap/prebuild.dll /target vs2022 /targetframework net6_0 /excludedir = "obj | bin" /file prebuild.xml dotnet bootstrap/prebuild.dll /target vs2022 /excludedir = "obj | bin" /file prebuild.xml

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Before After
Before After

View file

@ -691,8 +691,12 @@ public abstract class VSGenericTarget : ITarget
{ {
foreach(TextGenNode node in project.TextGenNodes) foreach(TextGenNode node in project.TextGenNodes)
{ {
string pathText = Path.Combine("Prebuild", "bootstrap", "SnapWrap.dll");
string filePath = Path.Combine(project.Path, node.Name);
string outputFile = Path.Combine(project.Path, node.OutputName);
ps.WriteLine(" <Target Name=\"Prebuild\" BeforeTargets=\"PreBuildEvent\">"); ps.WriteLine(" <Target Name=\"Prebuild\" BeforeTargets=\"PreBuildEvent\">");
ps.WriteLine($" <Exec Command=\"'dotnet' '$(DevEnvDir)TextTransformCore.dll' '$(ProjectDir){project.Path}\\{node.Name}'\" />"); ps.WriteLine($" <Exec Command=\"'dotnet' '$(ProjectDir){pathText}' '$(ProjectDir){filePath}' '$(ProjectDir){outputFile}'\" />");
ps.WriteLine($" </Target>"); ps.WriteLine($" </Target>");
} }
} }

View file

@ -0,0 +1,262 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PreserveCompilationContext>false</PreserveCompilationContext>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ImplicitUsings>disable</ImplicitUsings>
<AssemblyName>prebuild</AssemblyName>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<GenerateDependencyFile>false</GenerateDependencyFile>
<EnableDefaultItems>false</EnableDefaultItems>
<CopyLocalLockFileAssemblies>True</CopyLocalLockFileAssemblies>
<SelfContained>False</SelfContained>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\..\bootstrap\debug\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>1595</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\..\bootstrap\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>1595</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.EnterpriseServices" >
<Name>System.EnterpriseServices</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="App.ico">
</EmbeddedResource>
<EmbeddedResource Include="data\prebuild-1.10.xsd">
</EmbeddedResource>
<EmbeddedResource Include="data\autotools.xml">
</EmbeddedResource>
<Compile Include="Prebuild.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\FatalException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Kernel.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\UnknownLanguageException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\WarningException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Attributes\DataNodeAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Attributes\OptionNodeAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Attributes\TargetAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Interfaces\IDataNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Interfaces\ITarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\AuthorNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\CleanFilesNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\CleanupNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ConfigurationNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ConfigurationNodeCollection.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\DatabaseProjectNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\DatabaseReferenceNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\DataNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\DescriptionNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ExcludeNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\FileNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\FilesNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\MatchNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\OptionsNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\PackageReferenceNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ProcessNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ProjectNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ProjectReferenceNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ReferenceNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\ReferencePathNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\SolutionNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Nodes\TextGenNode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Parse\IfContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Parse\Preprocessor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\AutotoolsTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\DebugTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\MakefileTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\MonoDevelopTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\NAntTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\SharpDevelop2Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\SharpDevelopTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\ToolInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2002Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2003Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2005Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2008Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2010Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2012Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2013Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2015Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2017Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2019Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VS2022Target.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VSGenericTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\VSVersion.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Targets\XcodeTarget.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Utilities\CommandLineCollection.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Utilities\CurrentDirectory.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Utilities\Helper.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Core\Utilities\Log.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,45 @@
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnapWrap
{
public class SnapWrap
{
public static void Main(string[] args)
{
string input = args[0];
string output = args[1];
try
{
var inputCode = File.ReadAllText(input);
var options = ScriptOptions.Default
.WithReferences(AppDomain.CurrentDomain.GetAssemblies()) // Add necessary assemblies
.WithImports("System");
using (var sw = new StreamWriter(output))
{
Console.SetOut(sw); // Redirect console output
var scriptState = CSharpScript.RunAsync(inputCode, options).Result;
// Reset console output
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()));
Console.WriteLine("Output file generated successfully.");
}
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: {ex.Message}");
}
}
}
}

View file

@ -0,0 +1,68 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<PreserveCompilationContext>false</PreserveCompilationContext>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ImplicitUsings>disable</ImplicitUsings>
<AssemblyName>SnapWrap</AssemblyName>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<GenerateDependencyFile>false</GenerateDependencyFile>
<CopyLocalLockFileAssemblies>True</CopyLocalLockFileAssemblies>
<SelfContained>False</SelfContained>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\..\bootstrap\debug\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>1595</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
<TieredCompilationQuickJit>false</TieredCompilationQuickJit>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>False</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\..\bootstrap\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>1595</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.6.0" />
</ItemGroup>
</Project>