From 97a01213ac50dc3753aca23bee25bee0274f505b Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Tue, 15 Mar 2016 16:41:18 -0700 Subject: [PATCH] Fix debian packages --- packaging/debian/dotnet-debian_config.json | 4 +- .../debian/dotnet-nightly-debian_config.json | 3 +- .../dotnet-sharedhost-debian_config.json | 4 + .../dotnet-sharedframework-debian_config.json | 1 + scripts/dotnet-cli-build/DebTargets.cs | 172 ++++++++++++++++++ scripts/dotnet-cli-build/InstallerTargets.cs | 91 +-------- scripts/dotnet-cli-build/PackageTargets.cs | 1 + scripts/dotnet-cli-build/Utils/Monikers.cs | 7 + scripts/package/package-debian.sh | 39 ++-- .../package/package-sharedframework-debian.sh | 2 +- scripts/package/package-sharedhost-debian.sh | 9 +- scripts/run-build.sh | 2 + .../Commands/TestCommand.cs | 8 +- 13 files changed, 222 insertions(+), 121 deletions(-) create mode 100644 scripts/dotnet-cli-build/DebTargets.cs diff --git a/packaging/debian/dotnet-debian_config.json b/packaging/debian/dotnet-debian_config.json index a3c4873a2..be5b4406f 100644 --- a/packaging/debian/dotnet-debian_config.json +++ b/packaging/debian/dotnet-debian_config.json @@ -28,9 +28,8 @@ }, "debian_dependencies":{ - "libssl1.0.0" : {}, "clang-3.5" : {}, - "libcurl3" : {} + "SHARED_FRAMEWORK_NUGET_NAME" : {} }, "package_conflicts" : [ @@ -38,7 +37,6 @@ ], "symlinks": { - "bin/dotnet" : "usr/bin/dotnet", "bin/dotnet-compile-native" : "/usr/bin/dotnet-compile-native" } } diff --git a/packaging/debian/dotnet-nightly-debian_config.json b/packaging/debian/dotnet-nightly-debian_config.json index cc7d7e9ab..fa1d47bb0 100644 --- a/packaging/debian/dotnet-nightly-debian_config.json +++ b/packaging/debian/dotnet-nightly-debian_config.json @@ -28,9 +28,8 @@ }, "debian_dependencies":{ - "libssl1.0.0" : {}, "clang-3.5" : {}, - "libcurl3" : {} + "SHARED_FRAMEWORK_NUGET_NAME" : {} }, "package_conflicts" : [ diff --git a/packaging/host/debian/dotnet-sharedhost-debian_config.json b/packaging/host/debian/dotnet-sharedhost-debian_config.json index 840e5945f..1afa060b9 100644 --- a/packaging/host/debian/dotnet-sharedhost-debian_config.json +++ b/packaging/host/debian/dotnet-sharedhost-debian_config.json @@ -31,5 +31,9 @@ "debian_dependencies":{ "libssl-dev" : {}, "libcurl3" : {} + }, + + "symlinks": { + "dotnet" : "/usr/bin/dotnet" } } diff --git a/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json b/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json index 93d32d198..588e20981 100644 --- a/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json +++ b/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json @@ -29,6 +29,7 @@ }, "debian_dependencies":{ + "dotnet-host" : {}, "libssl1.0.0" : {}, "libcurl3" : {} } diff --git a/scripts/dotnet-cli-build/DebTargets.cs b/scripts/dotnet-cli-build/DebTargets.cs new file mode 100644 index 000000000..538fcf60f --- /dev/null +++ b/scripts/dotnet-cli-build/DebTargets.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Runtime.InteropServices; +using Microsoft.DotNet.Cli.Build.Framework; +using Microsoft.Extensions.PlatformAbstractions; + +using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; + +namespace Microsoft.DotNet.Cli.Build +{ + public class DebTargets + { + [Target(nameof(GenerateSharedHostDeb), + nameof(GenerateSharedFrameworkDeb), + nameof(GenerateSdkDeb))] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult GenerateDebs(BuildTargetContext c) + { + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult GenerateSdkDeb(BuildTargetContext c) + { + var channel = c.BuildContext.Get("Channel").ToLower(); + var packageName = Monikers.GetDebianPackageName(c); + var version = c.BuildContext.Get("BuildVersion").SimpleVersion; + var debFile = c.BuildContext.Get("SdkInstallerFile"); + var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages"); + var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb"; + + var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sdk"); + + if (Directory.Exists(objRoot)) + { + Directory.Delete(objRoot, true); + } + + Directory.CreateDirectory(objRoot); + + Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"), + "-v", version, "-i", Dirs.Stage2, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL, "--obj-root", objRoot) + .Execute() + .EnsureSuccessful(); + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult GenerateSharedHostDeb(BuildTargetContext c) + { + var packageName = Monikers.GetDebianSharedHostPackageName(c); + var version = c.BuildContext.Get("BuildVersion").SimpleVersion; + var inputRoot = c.BuildContext.Get("SharedHostPublishRoot"); + var debFile = c.BuildContext.Get("SharedHostInstallerFile"); + var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedhost"); + + if (Directory.Exists(objRoot)) + { + Directory.Delete(objRoot, true); + } + + Directory.CreateDirectory(objRoot); + + Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedhost-debian.sh"), + "--input", inputRoot, "--output", debFile, "--obj-root", objRoot, "--version", version) + .Execute() + .EnsureSuccessful(); + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult GenerateSharedFrameworkDeb(BuildTargetContext c) + { + var packageName = Monikers.GetDebianSharedFrameworkPackageName(c); + var version = c.BuildContext.Get("BuildVersion").SimpleVersion; + var inputRoot = c.BuildContext.Get("SharedFrameworkPublishRoot"); + var debFile = c.BuildContext.Get("SharedFrameworkInstallerFile"); + var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedframework"); + + if (Directory.Exists(objRoot)) + { + Directory.Delete(objRoot, true); + } + + Directory.CreateDirectory(objRoot); + + Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedframework-debian.sh"), + "--input", inputRoot, "--output", debFile, "--package-name", packageName, + "--framework-nuget-name", Monikers.SharedFrameworkName, + "--framework-nuget-version", c.BuildContext.Get("SharedFrameworkNugetVersion"), + "--obj-root", objRoot, "--version", version) + .Execute() + .EnsureSuccessful(); + return c.Success(); + } + + [Target(nameof(InstallPackages), + nameof(RunE2ETest), + nameof(RemovePackages))] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult TestDebInstaller(BuildTargetContext c) + { + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult InstallPackages(BuildTargetContext c) + { + IEnumerable orderedPackageFiles = new List() + { + c.BuildContext.Get("SharedHostInstallerFile"), + c.BuildContext.Get("SharedFrameworkInstallerFile"), + c.BuildContext.Get("SdkInstallerFile") + }; + + foreach(var fileName in orderedPackageFiles) + { + Cmd("sudo", "dpkg", "-i", fileName) + .Execute() + .EnsureSuccessful(); + } + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult RunE2ETest(BuildTargetContext c) + { + Directory.SetCurrentDirectory(Path.Combine(Dirs.RepoRoot, "test", "EndToEnd")); + + Cmd("dotnet", "build") + .Execute() + .EnsureSuccessful(); + + var testResultsPath = Path.Combine(Dirs.Output, "obj", "debian", "test", "debian-endtoend-testResults.xml"); + + Cmd("dotnet", "test", "-xml", testResultsPath) + .Execute() + .EnsureSuccessful(); + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult RemovePackages(BuildTargetContext c) + { + IEnumerable orderedPackageFiles = new List() + { + Monikers.GetDebianPackageName(c), + Monikers.GetDebianSharedFrameworkPackageName(c), + Monikers.GetDebianSharedHostPackageName(c) + }; + + foreach(var packageFile in orderedPackageFiles) + { + Cmd("sudo", "dpkg", "-r", packageFile) + .Execute() + .EnsureSuccessful(); + } + + return c.Success(); + } + } +} diff --git a/scripts/dotnet-cli-build/InstallerTargets.cs b/scripts/dotnet-cli-build/InstallerTargets.cs index 7d5a8cba8..d90bd4fb6 100644 --- a/scripts/dotnet-cli-build/InstallerTargets.cs +++ b/scripts/dotnet-cli-build/InstallerTargets.cs @@ -14,99 +14,18 @@ namespace Microsoft.DotNet.Cli.Build { [Target(nameof(MsiTargets.GenerateMsis), nameof(MsiTargets.GenerateBundles), - nameof(PkgTargets.GeneratePkgs))]//, - //nameof(InstallerTargets.GenerateDebs))] + nameof(PkgTargets.GeneratePkgs), + nameof(DebTargets.GenerateDebs))] public static BuildTargetResult GenerateInstaller(BuildTargetContext c) { return c.Success(); } + + [Target(nameof(DebTargets.TestDebInstaller))] + public static BuildTargetResult TestInstaller(BuildTargetContext c) - [Target( - nameof(InstallerTargets.GenerateSdkDeb), - nameof(InstallerTargets.GenerateSharedFrameworkDeb), - nameof(InstallerTargets.GenerateSharedHostDeb))] - [BuildPlatforms(BuildPlatform.Ubuntu)] - public static BuildTargetResult GenerateDebs(BuildTargetContext c) { return c.Success(); } - - [Target] - [BuildPlatforms(BuildPlatform.Ubuntu)] - public static BuildTargetResult GenerateSdkDeb(BuildTargetContext c) - { - var channel = c.BuildContext.Get("Channel").ToLower(); - var packageName = Monikers.GetDebianPackageName(c); - var version = c.BuildContext.Get("BuildVersion").SimpleVersion; - var debFile = c.BuildContext.Get("CombinedFrameworkSDKHostInstallerFile"); - var input = c.BuildContext.Get("CLISDKRoot"); - var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages"); - var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb"; - - var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sdk"); - - if (Directory.Exists(objRoot)) - { - Directory.Delete(objRoot, true); - } - - Directory.CreateDirectory(objRoot); - - Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"), - "-v", version, "-i", input, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL, "--obj-root", objRoot) - .Execute() - .EnsureSuccessful(); - return c.Success(); - } - - [Target] - [BuildPlatforms(BuildPlatform.Ubuntu)] - public static BuildTargetResult GenerateSharedHostDeb(BuildTargetContext c) - { - var version = c.BuildContext.Get("BuildVersion").SimpleVersion; - var inputRoot = c.BuildContext.Get("SharedHostPublishRoot"); - var debFile = c.BuildContext.Get("SharedHostInstallerFile"); - var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedhost"); - - if (Directory.Exists(objRoot)) - { - Directory.Delete(objRoot, true); - } - - Directory.CreateDirectory(objRoot); - - Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedhost-debian.sh"), - "--input", inputRoot, "--output", debFile, "--obj-root", objRoot, "--version", version) - .Execute() - .EnsureSuccessful(); - return c.Success(); - } - - [Target] - [BuildPlatforms(BuildPlatform.Ubuntu)] - public static BuildTargetResult GenerateSharedFrameworkDeb(BuildTargetContext c) - { - var packageName = Monikers.GetDebianSharedFrameworkPackageName(c); - var version = c.BuildContext.Get("BuildVersion").SimpleVersion; - var inputRoot = c.BuildContext.Get("SharedFrameworkPublishRoot"); - var debFile = c.BuildContext.Get("SharedFrameworkInstallerFile"); - var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sharedframework"); - - if (Directory.Exists(objRoot)) - { - Directory.Delete(objRoot, true); - } - - Directory.CreateDirectory(objRoot); - - Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedframework-debian.sh"), - "--input", inputRoot, "--output", debFile, "--package-name", packageName, - "--framework-nuget-name", Monikers.SharedFrameworkName, - "--framework-nuget-version", c.BuildContext.Get("SharedFrameworkNugetVersion"), - "--obj-root", objRoot, "--version", version) - .Execute() - .EnsureSuccessful(); - return c.Success(); - } } } diff --git a/scripts/dotnet-cli-build/PackageTargets.cs b/scripts/dotnet-cli-build/PackageTargets.cs index 2719439e4..50e20a640 100644 --- a/scripts/dotnet-cli-build/PackageTargets.cs +++ b/scripts/dotnet-cli-build/PackageTargets.cs @@ -28,6 +28,7 @@ namespace Microsoft.DotNet.Cli.Build nameof(PackageTargets.GenerateVersionBadge), nameof(PackageTargets.GenerateCompressedFile), nameof(InstallerTargets.GenerateInstaller), + nameof(InstallerTargets.TestInstaller), nameof(PackageTargets.GenerateNugetPackages))] [Environment("DOTNET_BUILD_SKIP_PACKAGING", null, "0", "false")] public static BuildTargetResult Package(BuildTargetContext c) diff --git a/scripts/dotnet-cli-build/Utils/Monikers.cs b/scripts/dotnet-cli-build/Utils/Monikers.cs index 7fb3562e4..417b0517e 100644 --- a/scripts/dotnet-cli-build/Utils/Monikers.cs +++ b/scripts/dotnet-cli-build/Utils/Monikers.cs @@ -47,6 +47,13 @@ namespace Microsoft.DotNet.Cli.Build return $"dotnet-sharedframework-{SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower(); } + public static string GetDebianSharedHostPackageName(BuildTargetContext c) + { + var sharedFrameworkNugetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); + + return $"dotnet-host".ToLower(); + } + public static string GetOSShortName() { string osname = ""; diff --git a/scripts/package/package-debian.sh b/scripts/package/package-debian.sh index 1b54bfb02..63eba0280 100755 --- a/scripts/package/package-debian.sh +++ b/scripts/package/package-debian.sh @@ -62,6 +62,14 @@ parseargs(){ PREVIOUS_VERSION_URL=$2 shift ;; + --framework-nuget-name) + SHARED_FRAMEWORK_NUGET_NAME=$2 + shift + ;; + --framework-nuget-version) + SHARED_FRAMEWORK_NUGET_VERSION=$2 + shift + ;; --obj-root) OBJECT_DIR=$2 shift @@ -118,6 +126,7 @@ rm -f "$PACKAGE_OUTPUT_DIR/*.deb" execute_build(){ create_empty_debian_layout copy_files_to_debian_layout + update_debian_json create_debian_package } @@ -158,15 +167,18 @@ create_debian_package(){ "$PACKAGING_TOOL_DIR/package_tool" -i "$PACKAGE_LAYOUT_DIR" -o "$PACKAGE_OUTPUT_DIR" -v $DOTNET_CLI_VERSION -n $DOTNET_DEB_PACKAGE_NAME } +update_debian_json() +{ + header "Updating debian.json file" + sed -i "s/%SHARED_FRAMEWORK_NUGET_NAME%/$SHARED_FRAMEWORK_NUGET_NAME/g" "$PACKAGE_LAYOUT_DIR"/debian_config.json + sed -i "s/%SHARED_FRAMEWORK_NUGET_VERSION%/$SHARED_FRAMEWORK_NUGET_VERSION/g" "$PACKAGE_LAYOUT_DIR"/debian_config.json +} + test_debian_package(){ header "Testing debian package" install_bats run_package_integrity_tests - - install_debian_package - run_e2e_test - remove_debian_package } install_bats() { @@ -174,14 +186,6 @@ install_bats() { git clone https://github.com/sstephenson/bats.git $TEST_STAGE_DIR } -install_debian_package() { - sudo dpkg -i $DEBIAN_FILE -} - -remove_debian_package() { - sudo dpkg -r $DOTNET_DEB_PACKAGE_NAME -} - run_package_integrity_tests() { # Set LAST_VERSION_URL to enable upgrade tests export LAST_VERSION_URL="$PREVIOUS_VERSION_URL" @@ -189,17 +193,6 @@ run_package_integrity_tests() { $TEST_STAGE_DIR/bin/bats $PACKAGE_OUTPUT_DIR/test_package.bats } -run_e2e_test(){ - local dotnet_path="/usr/bin/dotnet" - - header "Running EndToEnd Tests against debian package using ${dotnet_path}" - - # Won't affect outer functions - cd $REPOROOT/test/EndToEnd - $dotnet_path build - $dotnet_path test -xml $TEST_STAGE_DIR/debian-endtoend-testResults.xml -} - execute_build DEBIAN_FILE=$(find $PACKAGE_OUTPUT_DIR -iname "*.deb") diff --git a/scripts/package/package-sharedframework-debian.sh b/scripts/package/package-sharedframework-debian.sh index ef904c0ee..bb2d07a4a 100755 --- a/scripts/package/package-sharedframework-debian.sh +++ b/scripts/package/package-sharedframework-debian.sh @@ -127,7 +127,7 @@ update_debian_json() } test_debian_package(){ - header "Testing debian package" + header "Testing debian Shared Framework package" install_bats run_package_integrity_tests diff --git a/scripts/package/package-sharedhost-debian.sh b/scripts/package/package-sharedhost-debian.sh index 4c4ecb8db..19a0dd86e 100755 --- a/scripts/package/package-sharedhost-debian.sh +++ b/scripts/package/package-sharedhost-debian.sh @@ -25,6 +25,7 @@ help(){ echo "Options:" echo " --input Package the entire contents of the directory tree." echo " --output The full path to which the package will be written." + echo " --package-name Package to identify during installation. Example - 'dotnet-sharedhost'" echo " --obj-root Root folder for intermediate objects." echo " --version Version for the debain package." exit 1 @@ -41,6 +42,10 @@ while [[ $# > 0 ]]; do REPO_BINARIES_DIR=$2 shift ;; + -p|--package-name) + SHARED_HOST_DEBIAN_PACKAGE_NAME=$2 + shift + ;; --obj-root) OBJECT_DIR=$2 shift @@ -99,11 +104,11 @@ create_debian_package(){ mkdir -p "$PACKAGE_OUTPUT_DIR" - "$PACKAGING_TOOL_DIR/package_tool" -i "$PACKAGE_LAYOUT_DIR" -o "$PACKAGE_OUTPUT_DIR" -v "$SHARED_HOST_DEBIAN_VERSION" + "$PACKAGING_TOOL_DIR/package_tool" -i "$PACKAGE_LAYOUT_DIR" -o "$PACKAGE_OUTPUT_DIR" -n "$SHARED_HOST_DEBIAN_PACKAGE_NAME" -v "$SHARED_HOST_DEBIAN_VERSION" } test_debian_package(){ - header "Testing debian package" + header "Testing debian Shared Host package" install_bats run_package_integrity_tests diff --git a/scripts/run-build.sh b/scripts/run-build.sh index 58fae0bea..01a07cfb5 100755 --- a/scripts/run-build.sh +++ b/scripts/run-build.sh @@ -13,6 +13,7 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +OLDPATH="$PATH" source "$DIR/common/_prettyprint.sh" @@ -109,6 +110,7 @@ echo "Restoring Build Script projects..." echo "Compiling Build Scripts..." dotnet publish "$DIR/dotnet-cli-build" -o "$DIR/dotnet-cli-build/bin" --framework netstandardapp1.5 +export PATH="$OLDPATH" # Run the builder echo "Invoking Build Scripts..." echo "Configuration: $CONFIGURATION" diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs index ef0f086e2..df8b1fa8d 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities var commandPath = _command; ResolveCommand(ref commandPath, ref args); - Console.WriteLine($"Executing - {_command} {args}"); + Console.WriteLine($"Executing - {commandPath} {args}"); var stdOut = new StreamForwarder(); var stdErr = new StreamForwarder(); @@ -38,12 +38,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities public virtual CommandResult ExecuteWithCapturedOutput(string args = "") { - Console.WriteLine($"Executing (Captured Output) - {_command} {args}"); - var command = _command; ResolveCommand(ref command, ref args); var commandPath = Env.GetCommandPath(command, ".exe", ".cmd", "") ?? Env.GetCommandPathFromRootPath(AppContext.BaseDirectory, command, ".exe", ".cmd", ""); + + Console.WriteLine($"Executing (Captured Output) - {commandPath} {args}"); var stdOut = new StreamForwarder(); var stdErr = new StreamForwarder(); @@ -64,7 +64,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities newArgs += " " + args; } args = newArgs; - executable = "corehost"; + executable = "dotnet"; } if (!Path.IsPathRooted(executable))