From 80f04d457192f1eb3702ab367674b263de07074b Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Oct 24 2018 17:09:41 +0000
Subject: Include netcoredbg


netcoredbg is an open source debug serve for .NET Core. It is used by
editors like Eclipse aCute (https://github.com/eclipse/aCute).
See https://github.com/Samsung/netcoredbg for moe detials.

netcoredbg uses (private?) headers from coreclr and bundles copies of
libraries from coreclr. So we build it as part of .NET Core to it stays
consistent with coreclr libraries and headers.

netcoredbg also needs a small number of nuget packges to build, which
are included as prebuilts in source-build already.

---

diff --git a/copr-build b/copr-build
index 6d431dc..2dd8ce2 100755
--- a/copr-build
+++ b/copr-build
@@ -8,4 +8,4 @@ fedpkg srpm 2>&1 | tee fedpkg.output
 
 srpm_name=$(grep 'Wrote: ' fedpkg.output | cut -d' ' -f 2)
 
-copr-cli build @dotnet-sig/dotnet "${srpm_name}"
+copr-cli build omajid/dotnet-2.1 "${srpm_name}"
diff --git a/dotnet.spec b/dotnet.spec
index 9a109c1..d3b6627 100644
--- a/dotnet.spec
+++ b/dotnet.spec
@@ -23,7 +23,7 @@
 
 Name:           dotnet
 Version:        %{sdk_version}
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        .NET Core CLI tools and runtime
 License:        MIT and ASL 2.0 and BSD
 URL:            https://github.com/dotnet/
@@ -39,6 +39,9 @@ Source0:        dotnet-%{runtime_version}.tar.gz
 Source1:        check-debug-symbols.py
 Source2:        dotnet.sh
 
+Source100:      netcoredbg-b4b291fa.tar.gz
+Source101:      netcoredbg-nuget.config.in
+
 Patch1:         corefx-optflags-support.patch
 Patch2:         cli-telemetry-optout.patch
 
@@ -150,9 +153,24 @@ cross platform applications that work on Linux, Mac and Windows.
 It particularly focuses on creating console applications, web
 applications and micro-services.
 
+%package -n netcoredbg
+
+Version:        0.0.1
+Summary:        Debugger for .NET Core runtime
+
+%description -n netcoredbg
+The debugger provides GDB/MI or VSCode Debug Adapter protocol and allows to
+debug .NET apps under .NET Core runtime.
+
+
 %prep
 %setup -q -n %{name}-%{runtime_version}
 
+mkdir netcoredbg
+pushd netcoredbg
+tar xf %{SOURCE100}
+popd
+
 # Fix bad hardcoded path in build
 sed -i 's|/usr/share/dotnet|%{_libdir}/%{name}|' src/core-setup/src/corehost/common/pal.unix.cpp
 
@@ -164,8 +182,16 @@ pushd src/cli
 %patch2 -p1
 popd
 
+builddir=$(pwd)
+sed -e "s|[@]BUILD_DIR[@]|${builddir}|" %{SOURCE101} > netcoredbg/nuget.config
+mkdir netcoredbg-build
+pushd netcoredbg-build
+popd
+
+
 %build
 
+# build dotnet core
 export CFLAGS="%{dotnet_cflags}"
 export CXXFLAGS="%{dotnet_cflags}"
 export LDFLAGS="%{dotnet_ldflags}"
@@ -174,6 +200,16 @@ VERBOSE=1 ./build.sh \
   /v:diag \
   /p:MinimalConsoleLogOutput=false
 
+# build netcoredbg
+cat netcoredbg/nuget.config
+pushd netcoredbg-build
+CC=clang CXX=clang++ cmake ../netcoredbg \
+  -DCLR_DIR=../src/coreclr \
+  -DCMAKE_INSTALL_PREFIX=%{_libdir}/netcoredbg
+VERBOSE=1 make
+popd
+
+
 %install
 install -d -m 0755 %{buildroot}%{_libdir}/%{name}/
 ls bin/x64/Release
@@ -203,15 +239,27 @@ ln -s %{_libdir}/%{name}/dotnet %{buildroot}%{_bindir}/
 install -d -m 0755 %{buildroot}%{_mandir}/man1/
 find -iname 'dotnet*.1' -type f -exec cp {} %{buildroot}%{_mandir}/man1/ \;
 
+# Install netcoredbg
+pushd netcoredbg-build
+make DESTDIR=%{buildroot} install
+popd
+ln -s %{_libdir}/netcoredbg/netcoredbg %{buildroot}%{_bindir}/
+
+# Replace bundled copy of libdbgshim.so with symlink to original
+rm %{buildroot}/%{_libdir}/netcoredbg/libdbgshim.so
+ln -s %{_libdir}/%{name}/shared/Microsoft.NETCore.App/%{runtime_version}/libdbgshim.so %{buildroot}%{_libdir}/netcoredbg/
+
 # Check debug symbols in all elf objects. This is not in %%check
 # because native binaries are stripped by rpm-build after %%install.
 # So we need to do this check earlier.
 echo "Testing build results for debug symbols..."
 %{SOURCE1} -v %{buildroot}%{_libdir}/%{name}/
 
+
 %check
 %{buildroot}%{_libdir}/%{name}/dotnet --info
 
+
 %files
 # empty package useful for dependencies
 
@@ -240,7 +288,14 @@ echo "Testing build results for debug symbols..."
 %dir %{_libdir}/%{name}/sdk
 %{_libdir}/%{name}/sdk/%{sdk_version}
 
+%files -n netcoredbg
+%{_libdir}/netcoredbg
+%{_bindir}/netcoredbg
+
 %changelog
+* Wed Oct 24 2018 Omair Majid <omajid@redhat.com> - 2.1.403-3
+- Include netcoredbg
+
 * Mon Oct 15 2018 Omair Majid <omajid@redhat.com> - 2.1.403-2
 - Disable telemetry by default
 - Users have to manually export DOTNET_CLI_TELEMETRY_OPTOUT=0 to enable
diff --git a/netcoredbg-nuget.config.in b/netcoredbg-nuget.config.in
new file mode 100644
index 0000000..d597ce7
--- /dev/null
+++ b/netcoredbg-nuget.config.in
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <packageSources>
+    <clear />
+    <add key="source-built" value="@BUILD_DIR@/bin/obj/x64/Release/blob-feed" />
+    <add key="prebuilt" value="@BUILD_DIR@/prebuilt/nuget-packages" />
+ </packageSources>
+</configuration>

