Browse Source

Added a CheckIfFscNotInstalled target to the F# build tasks so that it is possible to build SharpDevelop's main solution without the F# compiler being installed. If the CheckIfFscNotInstalled property is set to True in the F# project and the F# compiler cannot be found a warning is displayed and the F# addin is not built. If the CheckIfFscNotInstalled property is not set or set to False the F# build tasks will not check for the presence of the F# compiler and will try to compile the project. This will be the case for any projects created from the F# project templates.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2982 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
0fbdacdd23
  1. 2
      src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/FSharp.Build.Tasks.csproj
  2. 98
      src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/SharpDevelop.Build.Fsc.targets
  3. 48
      src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/Fsc.cs
  4. 62
      src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/FscToolLocationHelper.cs
  5. 36
      src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/IsFscInstalled.cs
  6. 10
      src/AddIns/BackendBindings/FSharp/FSharpBinding.sln
  7. 1
      src/AddIns/BackendBindings/FSharp/FSharpBinding/Project/FSharpBinding.fsproj
  8. BIN
      src/AddIns/BackendBindings/FSharp/RequiredLibraries/FSharp.Build.Tasks.dll
  9. 98
      src/AddIns/BackendBindings/FSharp/RequiredLibraries/SharpDevelop.Build.Fsc.targets

2
src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/FSharp.Build.Tasks.csproj

@ -58,6 +58,8 @@ @@ -58,6 +58,8 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\CompilerCommandLineBuilder.cs" />
<Compile Include="Src\Fsc.cs" />
<Compile Include="Src\FscToolLocationHelper.cs" />
<Compile Include="Src\IsFscInstalled.cs" />
<None Include="SharpDevelop.Build.Fsc.targets">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

98
src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/SharpDevelop.Build.Fsc.targets

@ -1,11 +1,15 @@ @@ -1,11 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="FSharp.Build.Tasks.Fsc" AssemblyFile="FSharp.Build.Tasks.dll" />
<UsingTask TaskName="CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="FSharp.Build.Tasks.IsFscInstalled" AssemblyFile="FSharp.Build.Tasks.dll" />
<UsingTask TaskName="CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Copy" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(FSharpBuildTasksPath)\SharpDevelop.Build.Fsc.targets</MSBuildAllProjects>
<DefaultLanguageSourceExtension>.fs</DefaultLanguageSourceExtension>
<Language>F#</Language>
<CheckIfFscNotInstalled Condition=" '$(CheckIfFscNotInstalled)' == '' ">False</CheckIfFscNotInstalled>
<FscInstalled>True</FscInstalled>
</PropertyGroup>
<PropertyGroup>
@ -33,7 +37,7 @@ @@ -33,7 +37,7 @@
<Output TaskParameter="ManifestResourceNames" ItemName="ManifestNonResxWithCulture" />
</CreateCSharpManifestResourceName>
</Target>
<Target Name="CoreCompile" Inputs="$(MSBuildAllProjects);
@(Compile);
@(ReferencePath);
@ -50,6 +54,7 @@ @@ -50,6 +54,7 @@
$(NonExistentFile)"
DependsOnTargets="$(CoreCompileDependsOn)">
<Fsc
Condition=" '$(FscInstalled)' == 'True' "
DebugType="$(DebugType)"
EmitDebugInformation="$(DebugSymbols)"
FileAlignment="$(FileAlignment)"
@ -66,4 +71,91 @@ @@ -66,4 +71,91 @@
</Target>
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />
<!--
Check if F# is installed.
-->
<Target Name="BeforeBuild">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="BeforeClean">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="BeforeRebuild">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="IfFscInstalled">
<Message Text="Checking if F# is installed." Condition=" '$(CheckIfFscNotInstalled)' == 'True' "/>
<!-- Check if F# is installed -->
<IsFscInstalled Condition=" '$(CheckIfFscNotInstalled)' == 'True' ">
<Output TaskParameter="IsInstalled" PropertyName="FscInstalled"/>
</IsFscInstalled>
<Warning Code="FSC1001" Text="Unable to find the F# compiler (fsi.exe). The F# addin will not be compiled." Condition=" '$(FscInstalled)' == 'False' and '$(CheckIfFscNotInstalled)' == 'True' " />
</Target>
<!-- Override CopyFilesToOutputDirectory so if the F# compiler is not installed there are
no errors when trying to copy non-existent files. -->
<Target
Name="CopyFilesToOutputDirectory"
DependsOnTargets="
ComputeIntermediateSatelliteAssemblies;
_CopyFilesMarkedCopyLocal;
_CopySourceItemsToOutputDirectory;
_CopyAppConfigFile;
_CopyManifestFiles;
_CheckForCompileOutputs;
_SGenCheckForOutputs">
<!-- Copy the build product (.dll or .exe). -->
<Copy Condition=" '$(FscInstalled)' == 'True' "
SourceFiles="@(IntermediateAssembly)"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)">
<Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<Message Importance="High" Text="$(MSBuildProjectName) -&gt; @(MainAssembly->'%(FullPath)')" />
<!-- Copy the debug information file (.pdb), if any -->
<Copy
SourceFiles="@(_DebugSymbolsIntermediatePath)"
DestinationFiles="@(_DebugSymbolsOutputPath)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Condition="'$(FscInstalled)' == 'True' and '$(_DebugSymbolsProduced)'=='true' and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!-- Copy the resulting XML documentation file, if any. -->
<Copy
SourceFiles="@(DocFileItem)"
DestinationFiles="@(FinalDocFile)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Condition="'$(FscInstalled)' == 'True' and '$(_DocumentationFileProduced)'=='true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!-- Copy satellite assemblies. -->
<Copy Condition=" '$(FscInstalled)' == 'True' "
SourceFiles="@(IntermediateSatelliteAssembliesWithTargetPath)"
DestinationFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(OutDir)%(Culture)\$(TargetName).resources.dll')"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
</Target>
</Project>

48
src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/Fsc.cs

@ -8,7 +8,6 @@ @@ -8,7 +8,6 @@
using System;
using System.IO;
using System.CodeDom.Compiler;
using System.Configuration;
using System.Globalization;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@ -103,49 +102,10 @@ namespace FSharp.Build.Tasks @@ -103,49 +102,10 @@ namespace FSharp.Build.Tasks
get { return "fsc.exe"; }
}
protected override string GenerateFullPathToTool() {
string path = null;
if (Array.Exists<string>(ConfigurationManager.AppSettings.AllKeys, delegate(string k) { return k == "alt_fs_bin_path"; })) {
path = Path.Combine(ConfigurationManager.AppSettings["alt_fs_bin_path"], ToolName);
if (!File.Exists(path)) {
throw new Exception("you are trying to use the app setting alt_fs_bin_path, but fsc.exe is not localed in the given directory");
}
}
else {
string[] paths = Environment.GetEnvironmentVariable("path").Split(';');
path = Array.Find(paths, delegate(string x) {
bool res = false;
try {
res = File.Exists(Path.Combine(x, "fsc.exe"));
}
catch {
res = false;
}
return res;
});
if (path != null) {
path = Path.Combine(path, ToolName);
}
else {
string[] dirs = Directory.GetDirectories(Environment.GetEnvironmentVariable("ProgramFiles"), "FSharp*");
List<FileInfo> files = new List<FileInfo>();
foreach (string dir in dirs) {
FileInfo file = new FileInfo(Path.Combine(Path.Combine(dir, "bin"), ToolName));
if (file.Exists) {
files.Add(file);
}
}
if (files.Count > 0) {
files.Sort(delegate(FileInfo x, FileInfo y) { return DateTime.Compare(x.CreationTime, y.CreationTime); });
path = files[0].FullName;
}
//else {
// throw new Exception("can not find the fsi.exe, ensure a version of the F# compiler is installed");
//}
}
}
return path;
}
protected override string GenerateFullPathToTool()
{
return FscToolLocationHelper.GetPathToTool();
}
protected override string GenerateCommandLineCommands()
{

62
src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/FscToolLocationHelper.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Robert Pickering" email="robert@strangelights.com"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
namespace FSharp.Build.Tasks
{
public sealed class FscToolLocationHelper
{
public static readonly string ToolName = "fsc.exe";
FscToolLocationHelper()
{
}
public static string GetPathToTool()
{
string path = null;
if (Array.Exists<string>(ConfigurationManager.AppSettings.AllKeys, delegate(string k) { return k == "alt_fs_bin_path"; })) {
path = Path.Combine(ConfigurationManager.AppSettings["alt_fs_bin_path"], ToolName);
if (!File.Exists(path)) {
throw new Exception("you are trying to use the app setting alt_fs_bin_path, but fsc.exe is not localed in the given directory");
}
} else {
string[] paths = Environment.GetEnvironmentVariable("path").Split(';');
path = Array.Find(paths, delegate(string x) {
bool res = false;
try {
res = File.Exists(Path.Combine(x, "fsc.exe"));
} catch {
res = false;
}
return res;
});
if (path != null) {
path = Path.Combine(path, ToolName);
} else {
string[] dirs = Directory.GetDirectories(Environment.GetEnvironmentVariable("ProgramFiles"), "FSharp*");
List<FileInfo> files = new List<FileInfo>();
foreach (string dir in dirs) {
FileInfo file = new FileInfo(Path.Combine(Path.Combine(dir, "bin"), ToolName));
if (file.Exists) {
files.Add(file);
}
}
if (files.Count > 0) {
files.Sort(delegate(FileInfo x, FileInfo y) { return DateTime.Compare(x.CreationTime, y.CreationTime); });
path = files[0].FullName;
}
}
}
return path;
}
}
}

36
src/AddIns/BackendBindings/FSharp/FSharp.Build.Tasks/Project/Src/IsFscInstalled.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Build.Tasks;
namespace FSharp.Build.Tasks
{
/// <summary>
/// Tasks that determines if the F# compiler is installed.
/// </summary>
public sealed class IsFscInstalled : Task
{
bool installed;
[Output]
public bool IsInstalled {
get { return installed; }
set { installed = value; }
}
public override bool Execute()
{
if (FscToolLocationHelper.GetPathToTool() != null) {
installed = true;
}
return true;
}
}
}

10
src/AddIns/BackendBindings/FSharp/FSharpBinding.sln

@ -1,15 +1,11 @@ @@ -1,15 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 3.0.0.2958
# SharpDevelop 3.0.0.2980
Project("{982E8BC1-ACD7-4dbf-96AB-B2CE67D6A008}") = "FSharpBinding", "FSharpBinding\Project\FSharpBinding.fsproj", "{99BAE3A2-C40D-40D2-A7B4-EBB4798F36E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FSharp.Build.Tasks", "FSharp.Build.Tasks\Project\FSharp.Build.Tasks.csproj", "{674D485B-8340-498D-B91F-BE51543386C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor", "..\..\..\Libraries\ICSharpCode.TextEditor\Project\ICSharpCode.TextEditor.csproj", "{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net", "..\..\..\Libraries\log4net\src\log4net.csproj", "{F6A02431-167E-4347-BC43-65532C31CDB7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop", "..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj", "{2748AD25-9C63-4E12-877B-4DCE96FBED54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\..\..\Main\Core\Project\ICSharpCode.Core.csproj", "{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}"
@ -46,10 +42,6 @@ Global @@ -46,10 +42,6 @@ Global
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.Build.0 = Release|Any CPU
{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6A02431-167E-4347-BC43-65532C31CDB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6A02431-167E-4347-BC43-65532C31CDB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6A02431-167E-4347-BC43-65532C31CDB7}.Release|Any CPU.Build.0 = Release|Any CPU
{F6A02431-167E-4347-BC43-65532C31CDB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.Build.0 = Release|Any CPU

1
src/AddIns/BackendBindings/FSharp/FSharpBinding/Project/FSharpBinding.fsproj

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
<AssemblyName>FSharpBinding</AssemblyName>
<Standalone>True</Standalone>
<NoMLLib>True</NoMLLib>
<CheckIfFscNotInstalled>True</CheckIfFscNotInstalled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\..\..\..\..\..\AddIns\AddIns\BackendBindings\FSharpBinding\</OutputPath>

BIN
src/AddIns/BackendBindings/FSharp/RequiredLibraries/FSharp.Build.Tasks.dll

Binary file not shown.

98
src/AddIns/BackendBindings/FSharp/RequiredLibraries/SharpDevelop.Build.Fsc.targets

@ -1,11 +1,15 @@ @@ -1,11 +1,15 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="FSharp.Build.Tasks.Fsc" AssemblyFile="FSharp.Build.Tasks.dll" />
<UsingTask TaskName="CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="FSharp.Build.Tasks.IsFscInstalled" AssemblyFile="FSharp.Build.Tasks.dll" />
<UsingTask TaskName="CreateCSharpManifestResourceName" AssemblyName="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<UsingTask TaskName="Copy" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(FSharpBuildTasksPath)\SharpDevelop.Build.Fsc.targets</MSBuildAllProjects>
<DefaultLanguageSourceExtension>.fs</DefaultLanguageSourceExtension>
<Language>F#</Language>
<CheckIfFscNotInstalled Condition=" '$(CheckIfFscNotInstalled)' == '' ">False</CheckIfFscNotInstalled>
<FscInstalled>True</FscInstalled>
</PropertyGroup>
<PropertyGroup>
@ -33,7 +37,7 @@ @@ -33,7 +37,7 @@
<Output TaskParameter="ManifestResourceNames" ItemName="ManifestNonResxWithCulture" />
</CreateCSharpManifestResourceName>
</Target>
<Target Name="CoreCompile" Inputs="$(MSBuildAllProjects);
@(Compile);
@(ReferencePath);
@ -50,6 +54,7 @@ @@ -50,6 +54,7 @@
$(NonExistentFile)"
DependsOnTargets="$(CoreCompileDependsOn)">
<Fsc
Condition=" '$(FscInstalled)' == 'True' "
DebugType="$(DebugType)"
EmitDebugInformation="$(DebugSymbols)"
FileAlignment="$(FileAlignment)"
@ -66,4 +71,91 @@ @@ -66,4 +71,91 @@
</Target>
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />
<!--
Check if F# is installed.
-->
<Target Name="BeforeBuild">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="BeforeClean">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="BeforeRebuild">
<CallTarget Targets="IfFscInstalled" />
</Target>
<Target Name="IfFscInstalled">
<Message Text="Checking if F# is installed." Condition=" '$(CheckIfFscNotInstalled)' == 'True' "/>
<!-- Check if F# is installed -->
<IsFscInstalled Condition=" '$(CheckIfFscNotInstalled)' == 'True' ">
<Output TaskParameter="IsInstalled" PropertyName="FscInstalled"/>
</IsFscInstalled>
<Warning Code="FSC1001" Text="Unable to find the F# compiler (fsi.exe). The F# addin will not be compiled." Condition=" '$(FscInstalled)' == 'False' and '$(CheckIfFscNotInstalled)' == 'True' " />
</Target>
<!-- Override CopyFilesToOutputDirectory so if the F# compiler is not installed there are
no errors when trying to copy non-existent files. -->
<Target
Name="CopyFilesToOutputDirectory"
DependsOnTargets="
ComputeIntermediateSatelliteAssemblies;
_CopyFilesMarkedCopyLocal;
_CopySourceItemsToOutputDirectory;
_CopyAppConfigFile;
_CopyManifestFiles;
_CheckForCompileOutputs;
_SGenCheckForOutputs">
<!-- Copy the build product (.dll or .exe). -->
<Copy Condition=" '$(FscInstalled)' == 'True' "
SourceFiles="@(IntermediateAssembly)"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)">
<Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<Message Importance="High" Text="$(MSBuildProjectName) -&gt; @(MainAssembly->'%(FullPath)')" />
<!-- Copy the debug information file (.pdb), if any -->
<Copy
SourceFiles="@(_DebugSymbolsIntermediatePath)"
DestinationFiles="@(_DebugSymbolsOutputPath)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Condition="'$(FscInstalled)' == 'True' and '$(_DebugSymbolsProduced)'=='true' and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!-- Copy the resulting XML documentation file, if any. -->
<Copy
SourceFiles="@(DocFileItem)"
DestinationFiles="@(FinalDocFile)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Condition="'$(FscInstalled)' == 'True' and '$(_DocumentationFileProduced)'=='true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<!-- Copy satellite assemblies. -->
<Copy Condition=" '$(FscInstalled)' == 'True' "
SourceFiles="@(IntermediateSatelliteAssembliesWithTargetPath)"
DestinationFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(OutDir)%(Culture)\$(TargetName).resources.dll')"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
</Target>
</Project>
Loading…
Cancel
Save