homebrew-core/Formula/dotnet.rb

102 lines
3.3 KiB
Ruby

class Dotnet < Formula
desc ".NET Core"
homepage "https://dotnet.microsoft.com/"
url "https://github.com/dotnet/source-build.git",
tag: "v5.0.206-SDK",
revision: "7422fa72e3e3cb32cfad37ccb3ad5a2d9c05d857"
license "MIT"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)-SDK$/i)
end
bottle do
sha256 cellar: :any, big_sur: "13d9201f595c6beb27a70d7ce390cb550e3fc7353c4db13b042a7318aea3b958"
sha256 cellar: :any, catalina: "c8aeb6eb53feb7d3d0ac9ed7c5fe9d7e30971852a980f4b226f43f1471bfe3e6"
sha256 cellar: :any, mojave: "c8af8eb10f1ac1dc48e6f89325863b4a5beeb1c5463615f352035f88c3651262"
sha256 cellar: :any_skip_relocation, x86_64_linux: "c3d508da58b4fa947a59f43c5129d74516ad0dafb07f316e01b2ce95b5dde3cc"
end
depends_on "cmake" => :build
depends_on "pkg-config" => :build
depends_on xcode: :build
depends_on arch: :x86_64
depends_on "curl"
depends_on "icu4c"
depends_on "openssl@1.1"
uses_from_macos "krb5"
uses_from_macos "zlib"
on_linux do
depends_on "llvm" => [:build, :test]
depends_on "libunwind"
depends_on "lttng-ust"
end
fails_with :gcc
def install
ENV.append_path "LD_LIBRARY_PATH", Formula["icu4c"].opt_lib if OS.linux?
# Arguments needed to not artificially time-limit downloads from Azure.
# See the following GitHub issue comment for details:
# https://github.com/dotnet/source-build/issues/1596#issuecomment-670995776
system "./build.sh", "/p:DownloadSourceBuildReferencePackagesTimeoutSeconds=N/A",
"/p:DownloadSourceBuiltArtifactsTimeoutSeconds=N/A"
libexec.mkpath
tarball = Dir["artifacts/*/Release/dotnet-sdk-#{version}-*.tar.gz"].first
system "tar", "-xzf", tarball, "--directory", libexec
doc.install Dir[libexec/"*.txt"]
(bin/"dotnet").write_env_script libexec/"dotnet", DOTNET_ROOT: libexec
end
def caveats
<<~EOS
For other software to find dotnet you may need to set:
export DOTNET_ROOT="#{opt_libexec}"
EOS
end
test do
target_framework = "net#{version.major_minor}"
(testpath/"test.cs").write <<~EOS
using System;
namespace Homebrew
{
public class Dotnet
{
public static void Main(string[] args)
{
var joined = String.Join(",", args);
Console.WriteLine(joined);
}
}
}
EOS
(testpath/"test.csproj").write <<~EOS
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>#{target_framework}</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<RootNamespace>Homebrew</RootNamespace>
<PackageId>Homebrew.Dotnet</PackageId>
<Title>Homebrew.Dotnet</Title>
<Product>$(AssemblyName)</Product>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test.cs" />
</ItemGroup>
</Project>
EOS
system bin/"dotnet", "build", "--framework", target_framework, "--output", testpath, testpath/"test.csproj"
assert_equal "#{testpath}/test.dll,a,b,c\n",
shell_output("#{bin}/dotnet run --framework #{target_framework} #{testpath}/test.dll a b c")
end
end