Separate MSBuild integration for .NET 3.5 and .NET 4.0 toolchains

This commit is contained in:
Sam Harwell 2013-04-17 19:02:01 -05:00
parent f9718aa62f
commit 785585199c
7 changed files with 331 additions and 13 deletions

View File

@ -16,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.v4.5", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.v4.5.csproj", "{9D8C43DF-71F9-4CC9-83AD-A39FAEBCECA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks", "Antlr4BuildTasks\Antlr4BuildTasks.csproj", "{F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.v4.0", "Antlr4BuildTasks\Antlr4BuildTasks.v4.0.csproj", "{F63DFE80-AE1F-47A6-A31A-E39DA4C837BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.v4.0", "Antlr4.Runtime\Antlr4.Runtime.v4.0.csproj", "{423978DF-85A4-409E-A16C-453683FE3969}"
EndProject
@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Portable", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.Test.Portable", "Antlr4.Runtime.Test\Antlr4.Runtime.Test.Portable.csproj", "{97C32E42-51B2-4A29-B005-769B63CFEFCA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4BuildTasks.v3.5", "Antlr4BuildTasks\Antlr4BuildTasks.v3.5.csproj", "{0D3D20E9-3341-4449-80E7-76A4534F0E55}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -96,6 +98,10 @@ Global
{97C32E42-51B2-4A29-B005-769B63CFEFCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97C32E42-51B2-4A29-B005-769B63CFEFCA}.Release|Any CPU.Build.0 = Release|Any CPU
{0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D3D20E9-3341-4449-80E7-76A4534F0E55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D3D20E9-3341-4449-80E7-76A4534F0E55}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -30,7 +30,7 @@
<BuildSystem>MSBuild</BuildSystem>
<TaskVersion>4.0.0.0</TaskVersion>
<TaskKeyToken>eb42632606e9261f</TaskKeyToken>
<Antlr4BuildTaskAssemblyName Condition="'$(Antlr4BuildTaskAssemblyName)'==''">Antlr4BuildTasks, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken)</Antlr4BuildTaskAssemblyName>
<Antlr4BuildTaskAssemblyName Condition="'$(Antlr4BuildTaskAssemblyName)'==''">Antlr4BuildTasks.v3.5, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken)</Antlr4BuildTaskAssemblyName>
</PropertyGroup>
<PropertyGroup>

View File

@ -0,0 +1,181 @@
<!--
[The "BSD licence"]
Copyright (c) 2013 Sam Harwell
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildSystem>MSBuild</BuildSystem>
<TaskVersion>4.0.0.0</TaskVersion>
<TaskKeyToken>eb42632606e9261f</TaskKeyToken>
<Antlr4BuildTaskAssemblyName Condition="'$(Antlr4BuildTaskAssemblyName)'==''">Antlr4BuildTasks.v4.0, Version=$(TaskVersion), Culture=neutral, PublicKeyToken=$(TaskKeyToken)</Antlr4BuildTaskAssemblyName>
</PropertyGroup>
<PropertyGroup>
<LoadTimeSensitiveTargets>
$(LoadTimeSensitiveTargets);
Antlr4Compile;
</LoadTimeSensitiveTargets>
<LoadTimeSensitiveProperties>
$(LoadTimeSensitiveProperties);
Antlr4CompileDependsOn;
</LoadTimeSensitiveProperties>
</PropertyGroup>
<PropertyGroup>
<Antlr4BuildTaskLocation Condition="'$(Antlr4BuildTaskPath)'==''">$(MSBuildBinPath)</Antlr4BuildTaskLocation>
<Antlr4BuildTaskLocation Condition="'$(Antlr4BuildTaskPath)'!=''">$(Antlr4BuildTaskPath)</Antlr4BuildTaskLocation>
<Antlr4ToolLocation Condition="'$(Antlr4ToolPath)'==''">$(MSBuildBinPath)\Antlr4\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolLocation>
<Antlr4ToolLocation Condition="'$(Antlr4ToolPath)'!=''">$(Antlr4ToolPath)</Antlr4ToolLocation>
<Antlr4JavaVendor Condition="'$(Antlr4JavaVendor)'==''">JavaSoft</Antlr4JavaVendor>
<Antlr4JavaInstallation Condition="'$(Antlr4JavaInstallation)'==''">Java Runtime Environment</Antlr4JavaInstallation>
</PropertyGroup>
<PropertyGroup>
<Antlr4GenCodeFileNames Condition="'$(Antlr4GenCodeFileNames)'==''">$(MSBuildProjectFile).Antlr4GeneratedCodeFileListAbsolute.txt</Antlr4GenCodeFileNames>
</PropertyGroup>
<UsingTask Condition="'$(Antlr4BuildTaskPath)'==''" TaskName="Antlr4.Build.Tasks.Antlr4ClassGenerationTask" AssemblyName="$(Antlr4BuildTaskAssemblyName)" />
<UsingTask Condition="'$(Antlr4BuildTaskPath)'!=''" TaskName="Antlr4.Build.Tasks.Antlr4ClassGenerationTask" AssemblyFile="$(Antlr4BuildTaskPath)\Antlr4BuildTasks.dll" />
<PropertyGroup>
<PrepareResourcesDependsOn>
Antlr4Compile;
Antlr4CompileAddFilesGenerated;
$(PrepareResourcesDependsOn)
</PrepareResourcesDependsOn>
</PropertyGroup>
<PropertyGroup>
<Antlr4CompileDependsOn>
Antlr4CompileReadGeneratedFileList
</Antlr4CompileDependsOn>
</PropertyGroup>
<ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'">
<AvailableItemName Include="Antlr4" />
<AvailableItemName Include="Antlr4Tokens" />
<AvailableItemName Include="Antlr4AbstractGrammar" />
</ItemGroup>
<ItemDefinitionGroup>
<Antlr4>
<Generator>MSBuild:Compile</Generator>
<CustomToolNamespace>$(RootNamespace)</CustomToolNamespace>
<TargetLanguage>CSharp</TargetLanguage>
<Listener>true</Listener>
<Visitor>true</Visitor>
<Abstract>false</Abstract>
<ForceAtn>false</ForceAtn>
</Antlr4>
</ItemDefinitionGroup>
<Target Name="Antlr4CompileReadGeneratedFileList">
<ReadLinesFromFile File="$(IntermediateOutputPath)$(Antlr4GenCodeFileNames)">
<Output TaskParameter="Lines" ItemName="Antlr4OutputCodeFilesList"/>
</ReadLinesFromFile>
</Target>
<PropertyGroup>
<!-- Add grammar compilation to the CoreCompileDependsOn so that the IDE inproc compilers (particularly VB)
can "see" the generated source files. -->
<CoreCompileDependsOn Condition="'$(BuildingInsideVisualStudio)' == 'true' ">
Antlr4DesignTimeGrammarCompilation;
$(CoreCompileDependsOn)
</CoreCompileDependsOn>
</PropertyGroup>
<Target Name="Antlr4DesignTimeGrammarCompilation">
<!-- Only if we are not actually performing a compile i.e. we are in design mode -->
<CallTarget Condition="'$(BuildingProject)' != 'true'"
Targets="Antlr4Compile" />
</Target>
<Target Name="Antlr4Compile"
DependsOnTargets="$(Antlr4CompileDependsOn)"
Condition="'@(Antlr4)' != ''"
Inputs="@(Antlr4);@(Antlr4Tokens);@(Antlr4AbstractGrammar)"
Outputs="@(Antlr4OutputCodeFilesList);
$(IntermediateOutputPath)$(Antlr4GenCodeFileNames);">
<ItemGroup>
<Antlr4GeneratedCodeFiles Remove="@(Antlr4GeneratedCodeFiles)" />
</ItemGroup>
<PropertyGroup>
<_IntellisenseOnlyCompile>false</_IntellisenseOnlyCompile>
<_IntellisenseOnlyCompile Condition="'$(BuildingProject)' != 'true'">true</_IntellisenseOnlyCompile>
</PropertyGroup>
<Antlr4ClassGenerationTask
ToolPath="$(Antlr4ToolLocation)"
JavaVendor="$(Antlr4JavaVendor)"
JavaInstallation="$(Antlr4JavaInstallation)"
BuildTaskPath="$(Antlr4BuildTaskLocation)"
OutputPath="$(IntermediateOutputPath)"
TargetLanguage="%(Antlr4.TargetLanguage)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
TargetNamespace="%(Antlr4.CustomToolNamespace)"
SourceCodeFiles="@(Antlr4 -> '%(FullPath)')"
ContinueOnError="$(_IntellisenseOnlyCompile)"
TokensFiles="@(Antlr4Tokens)"
AbstractGrammarFiles="@(Antlr4AbstractGrammar)"
LanguageSourceExtensions="$(DefaultLanguageSourceExtension)"
GenerateListener="%(Antlr4.Listener)"
GenerateVisitor="%(Antlr4.Visitor)"
ForceAtn="%(Antlr4.ForceAtn)"
AbstractGrammar="%(Antlr4.Abstract)">
<Output ItemName="Antlr4GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
</Antlr4ClassGenerationTask>
<WriteLinesToFile
Condition="'$(_IntellisenseOnlyCompile)' != 'true'"
File="$(IntermediateOutputPath)$(Antlr4GenCodeFileNames)"
Lines="@(Antlr4GeneratedCodeFiles)"
Overwrite="true"/>
</Target>
<Target Name="Antlr4CompileAddFilesGenerated"
AfterTargets="Antlr4Compile"
Condition="'@(Antlr4)' != ''">
<ItemGroup>
<Antlr4GeneratedCodeFiles Condition="'@(Antlr4GeneratedCodeFiles)' == ''" Include="@(Antlr4OutputCodeFilesList)" />
</ItemGroup>
<ItemGroup>
<FileWrites Include="@(Antlr4GeneratedCodeFiles);
$(IntermediateOutputPath)$(Antlr4GenCodeFileNames);" />
</ItemGroup>
<ItemGroup>
<Compile Include="@(Antlr4GeneratedCodeFiles)" />
<!-- The WinFX "GenerateTemporaryTargetAssembly" target requires generated code files be added here. -->
<_GeneratedCodeFiles Include="@(Antlr4GeneratedCodeFiles)" />
</ItemGroup>
</Target>
</Project>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0D3D20E9-3341-4449-80E7-76A4534F0E55}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Antlr4.Build.Tasks</RootNamespace>
<AssemblyName>Antlr4BuildTasks.v3.5</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseIntermediateOutputPath>obj\v3.5\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\v3.5\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>ExtendedDesignGuidelineRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\v3.5\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\..\..\..\..\keys\antlr\Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v3.5" />
<Reference Include="Microsoft.Build.Utilities.v3.5" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Antlr4ClassGenerationTask.cs" />
<Compile Include="Antlr4ClassGenerationTaskInternal.cs" />
<Compile Include="BuildMessage.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Antlr4.v3.5.targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
<None Include="..\..\..\..\..\..\keys\antlr\Key.snk">
<Link>Key.snk</Link>
</None>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\build\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -8,24 +8,26 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Antlr4.Build.Tasks</RootNamespace>
<AssemblyName>Antlr4BuildTasks</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AssemblyName>Antlr4BuildTasks.v4.0</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseIntermediateOutputPath>obj\v4.0\</BaseIntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<OutputPath>bin\v4.0\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>ExtendedDesignGuidelineRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<OutputPath>bin\v4.0\Release\</OutputPath>
<DefineConstants>TRACE;NET_4_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -55,7 +57,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Antlr4.targets">
<None Include="Antlr4.v4.0.targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>

View File

@ -37,7 +37,11 @@ namespace Antlr4.Build.Tasks
using System.Text.RegularExpressions;
using RegistryHive = Microsoft.Win32.RegistryHive;
using RegistryKey = Microsoft.Win32.RegistryKey;
#if NET_4_0
using RegistryView = Microsoft.Win32.RegistryView;
#else
using Registry = Microsoft.Win32.Registry;
#endif
internal class AntlrClassGenerationTaskInternal : MarshalByRefObject
{
@ -145,6 +149,7 @@ namespace Antlr4.Build.Tasks
}
}
#if NET_4_0
private string JavaHome
{
get
@ -190,13 +195,51 @@ namespace Antlr4.Build.Tasks
}
}
}
#else
private string JavaHome
{
get
{
string javaHome;
if (TryGetJavaHome(Registry.LocalMachine, JavaVendor, JavaInstallation, out javaHome))
return javaHome;
throw new NotSupportedException("Could not locate a Java installation.");
}
}
private static bool TryGetJavaHome(RegistryKey baseKey, string vendor, string installation, out string javaHome)
{
javaHome = null;
string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;
using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName))
{
if (javaKey == null)
return false;
object currentVersion = javaKey.GetValue("CurrentVersion");
if (currentVersion == null)
return false;
using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString()))
{
if (homeKey == null || homeKey.GetValue("JavaHome") == null)
return false;
javaHome = homeKey.GetValue("JavaHome").ToString();
return !string.IsNullOrEmpty(javaHome);
}
}
}
#endif
public bool Execute()
{
try
{
string javaHome = JavaHome;
string java = Path.Combine(javaHome, "bin", "java.exe");
string java = Path.Combine(Path.Combine(javaHome, "bin"), "java.exe");
List<string> arguments = new List<string>();
arguments.Add("-cp");
@ -245,7 +288,7 @@ namespace Antlr4.Build.Tasks
arguments.AddRange(SourceCodeFiles);
ProcessStartInfo startInfo = new ProcessStartInfo(java, string.Join(" ", arguments))
ProcessStartInfo startInfo = new ProcessStartInfo(java, string.Join(" ", arguments.ToArray()))
{
UseShellExecute = false,
CreateNoWindow = true,

View File

@ -35,11 +35,16 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Antlr4BuildTasks")]
#if NET_4_0
[assembly: AssemblyTitle("Antlr4BuildTasks.v4.0")]
[assembly: AssemblyProduct("Antlr4BuildTasks.v4.0")]
#else
[assembly: AssemblyTitle("Antlr4BuildTasks.v3.5")]
[assembly: AssemblyProduct("Antlr4BuildTasks.v3.5")]
#endif
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")]
[assembly: AssemblyProduct("Antlr4BuildTasks")]
[assembly: AssemblyCopyright("Copyright © Sam Harwell 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]