Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
338 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[CmdletBinding(PositionalBinding=$false)] | ||
param ( | ||
[string]$artifactsDir, | ||
[string]$apiKey, | ||
[string]$configuration | ||
) | ||
|
||
Set-StrictMode -version 2.0 | ||
$ErrorActionPreference = "Stop" | ||
|
||
$shippingDir = "$artifactsDir\packages\$configuration\Shipping" | ||
$packages = @( | ||
"$shippingDir\FSharp.Compiler.Scripting.*.nupkg", | ||
"$shippingDir\FSharp.Core.*.nupkg" | ||
) | ||
|
||
. (Join-Path $PSScriptRoot "publish-myget.ps1") -apiKey "$apiKey" -feedUrl "https://dotnet.myget.org/F/fsharp/api/v2/package" $packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[CmdletBinding(PositionalBinding=$false)] | ||
param ( | ||
[string]$apiKey, | ||
[string]$feedUrl, | ||
|
||
[parameter(ValueFromRemainingArguments=$true)][string[]]$packages | ||
) | ||
|
||
Set-StrictMode -version 2.0 | ||
$ErrorActionPreference = "Stop" | ||
|
||
$failedPackages = 0 | ||
foreach ($package in $packages) { | ||
$response = Invoke-WebRequest -Uri $feedUrl -Headers @{"X-NuGet-ApiKey"=$apiKey} -ContentType "multipart/form-data" -InFile "$package" -Method Post -UseBasicParsing | ||
if ($response.StatusCode -ne 201) { | ||
Write-Error "Failed to upload package. Upload failed with status code: $response.StatusCode." | ||
$failedPackages++ | ||
} | ||
} | ||
|
||
exit $failedPackages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<UseFSharpProductVersion>true</UseFSharpProductVersion> | ||
</PropertyGroup> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
src/fsharp/FSharp.Compiler.Scripting/FSharp.Compiler.Scripting.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<PackageDescription>Provides embedding F# language scripting.</PackageDescription> | ||
<NuspecFile>FSharp.Compiler.Scripting.nuspec</NuspecFile> | ||
<ExcludeFromSourceBuild>true</ExcludeFromSourceBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="TextHelpers.fs" /> | ||
<Compile Include="FSharpScript.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<NuspecProperty Include="FSharpCoreVersion=$(FSCorePackageVersion)-$(VersionSuffix)"/> | ||
<NuspecProperty Include="TargetFramework=$(TargetFramework)"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Compiler.Interactive.Settings\FSharp.Compiler.Interactive.Settings.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
20 changes: 20 additions & 0 deletions
20
src/fsharp/FSharp.Compiler.Scripting/FSharp.Compiler.Scripting.nuspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> | ||
<metadata> | ||
$CommonMetadataElements$ | ||
<language>en-US</language> | ||
<dependencies> | ||
<group targetFramework=".NETStandard2.0"> | ||
<dependency id="FSharp.Core" version="$FSharpCoreVersion$" exclude="Build,Analyzers" /> | ||
</group> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Scripting.dll" target="lib\netstandard2.0" /> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Scripting.xml" target="lib\netstandard2.0" /> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Interactive.Settings.dll" target="lib\netstandard2.0" /> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Interactive.Settings.xml" target="lib\netstandard2.0" /> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Private.dll" target="lib\netstandard2.0" /> | ||
<file src="FSharp.Compiler.Scripting\$Configuration$\$TargetFramework$\FSharp.Compiler.Private.xml" target="lib\netstandard2.0" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.Scripting | ||
|
||
open System | ||
open FSharp.Compiler.Interactive.Shell | ||
|
||
type FSharpScript(?captureInput: bool, ?captureOutput: bool) as this = | ||
let outputProduced = Event<string>() | ||
let errorProduced = Event<string>() | ||
|
||
// handle stdin/stdout | ||
let stdin = new CapturedTextReader() | ||
let stdout = new EventedTextWriter() | ||
let stderr = new EventedTextWriter() | ||
do stdout.LineWritten.Add outputProduced.Trigger | ||
do stderr.LineWritten.Add errorProduced.Trigger | ||
let captureInput = defaultArg captureInput false | ||
let captureOutput = defaultArg captureOutput false | ||
let savedInput = Console.In | ||
let savedOutput = Console.Out | ||
let savedError = Console.Error | ||
do (fun () -> | ||
if captureInput then | ||
Console.SetIn(stdin) | ||
if captureOutput then | ||
Console.SetOut(stdout) | ||
Console.SetError(stderr) | ||
())() | ||
|
||
let config = FsiEvaluationSession.GetDefaultConfiguration() | ||
let argv = [| this.GetType().Assembly.Location; "--noninteractive"; "--targetprofile:netcore"; "--quiet" |] | ||
let fsi = FsiEvaluationSession.Create (config, argv, stdin, stdout, stderr, collectible=true) | ||
|
||
member __.ProvideInput = stdin.ProvideInput | ||
|
||
member __.OutputProduced = outputProduced.Publish | ||
|
||
member __.ErrorProduced = errorProduced.Publish | ||
|
||
member __.Eval(code: string) = | ||
let ch, errors = fsi.EvalExpressionNonThrowing code | ||
match ch with | ||
| Choice1Of2(Some(value)) -> Ok(value), errors | ||
| Choice1Of2 None -> Error(Exception("No value produced")), errors | ||
| Choice2Of2 ex -> Error(ex), errors | ||
|
||
interface IDisposable with | ||
member __.Dispose() = | ||
if captureInput then | ||
Console.SetIn(savedInput) | ||
if captureOutput then | ||
Console.SetOut(savedOutput) | ||
Console.SetError(savedError) | ||
stdin.Dispose() | ||
stdout.Dispose() | ||
stderr.Dispose() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.Scripting | ||
|
||
open System.Collections.Generic | ||
open System.IO | ||
open System.Text | ||
|
||
type internal CapturedTextReader() = | ||
inherit TextReader() | ||
let queue = Queue<char>() | ||
member __.ProvideInput(text: string) = | ||
for c in text.ToCharArray() do | ||
queue.Enqueue(c) | ||
override __.Peek() = | ||
if queue.Count > 0 then queue.Peek() |> int | ||
else -1 | ||
override __.Read() = | ||
if queue.Count > 0 then queue.Dequeue() |> int | ||
else -1 | ||
|
||
type internal EventedTextWriter() = | ||
inherit TextWriter() | ||
let sb = StringBuilder() | ||
let lineWritten = Event<string>() | ||
member __.LineWritten = lineWritten.Publish | ||
override __.Encoding = Encoding.UTF8 | ||
override __.Write(c: char) = | ||
if c = '\n' then | ||
let line = | ||
let v = sb.ToString() | ||
if v.EndsWith("\r") then v.Substring(0, v.Length - 1) | ||
else v | ||
sb.Clear() |> ignore | ||
lineWritten.Trigger(line) | ||
else sb.Append(c) |> ignore |
9 changes: 9 additions & 0 deletions
9
tests/FSharp.Compiler.Scripting.UnitTests/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<UseFSharpProductVersion>true</UseFSharpProductVersion> | ||
</PropertyGroup> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
</Project> |
Oops, something went wrong.