From 696f4dc167a377b39539e49842a142929c034036 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Wed, 9 Mar 2016 17:33:05 -0800 Subject: [PATCH] Add Shared Framework debian packaging --- .../dotnet-sharedframework-debian_config.json | 35 +++++ scripts/dotnet-cli-build/InstallerTargets.cs | 20 +++ scripts/dotnet-cli-build/Utils/Monikers.cs | 7 + .../package/package-sharedframework-debian.sh | 132 ++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json create mode 100755 scripts/package/package-sharedframework-debian.sh diff --git a/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json b/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json new file mode 100644 index 000000000..866a67515 --- /dev/null +++ b/packaging/sharedframework/debian/dotnet-sharedframework-debian_config.json @@ -0,0 +1,35 @@ +{ + "maintainer_name":"Microsoft", + "maintainer_email": "dotnetcore@microsoft.com", + + "package_name": "%SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME%", + "install_root": "/usr/share/dotnet", + + "short_description": ".NET Core Shared Framework %SHARED_FRAMEWORK_NUGET_NAME% %SHARED_FRAMEWORK_NUGET_VERSION%", + "long_description": ".NET Core is a cross-platform implementation of .NET Framework, a modern, modular platform\n for building diverse kinds of applications, from command-line applications to microservices and \n modern websites.\n This package contains a runtime and framework which can be used by .NET Core applications.", + "homepage": "https://dotnet.github.io/core", + + "release":{ + "package_version":"1.0.0.0", + "package_revision":"1", + "urgency" : "low", + "changelog_message" : "Inital shared framework." + }, + + "control": { + "priority":"standard", + "section":"libs", + "architecture":"amd64" + }, + + "copyright": "2015 Microsoft", + "license": { + "type": "MIT", + "full_text": "Copyright (c) 2015 Microsoft\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE." + }, + + "debian_dependencies":{ + "libssl-dev" : {}, + "libcurl3" : {} + } +} diff --git a/scripts/dotnet-cli-build/InstallerTargets.cs b/scripts/dotnet-cli-build/InstallerTargets.cs index 88b36c800..f822b4ad8 100644 --- a/scripts/dotnet-cli-build/InstallerTargets.cs +++ b/scripts/dotnet-cli-build/InstallerTargets.cs @@ -104,6 +104,26 @@ namespace Microsoft.DotNet.Cli.Build [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", SharedFrameworkTargets.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/Utils/Monikers.cs b/scripts/dotnet-cli-build/Utils/Monikers.cs index 56eac7ee1..b69c0d05b 100644 --- a/scripts/dotnet-cli-build/Utils/Monikers.cs +++ b/scripts/dotnet-cli-build/Utils/Monikers.cs @@ -38,6 +38,13 @@ namespace Microsoft.DotNet.Cli.Build return packageName; } + public static string GetDebianSharedFrameworkPackageName(BuildTargetContext c) + { + var sharedFrameworkNugetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); + + return $"dotnet-sharedframework-{SharedFrameworkTargets.SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower(); + } + public static string GetOSShortName() { string osname = ""; diff --git a/scripts/package/package-sharedframework-debian.sh b/scripts/package/package-sharedframework-debian.sh new file mode 100755 index 000000000..f4d993c98 --- /dev/null +++ b/scripts/package/package-sharedframework-debian.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash +# +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +# Debian Packaging Script +# Currently Intended to build on ubuntu14.04 + +set -e + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$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 )" + +source "$DIR/../common/_common.sh" +REPOROOT="$DIR/../.." + +help(){ + echo "Usage: $0" + echo "" + 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-sharedframework'" + echo " --framework-nuget-name The name of the nuget package that produced this shared framework." + echo " --framework-nuget-version The versionf of the nuget package that produced this shared framework." + echo " --obj-root Root folder for intermediate objects." + echo " --version Version for the debain package." + exit 1 +} + +while [[ $# > 0 ]]; do + lowerI="$(echo $1 | awk '{print tolower($0)}')" + case $lowerI in + -o|--output) + OUTPUT_DEBIAN_FILE=$2 + shift + ;; + -i|--input) + REPO_BINARIES_DIR=$2 + shift + ;; + -p|--package-name) + SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME=$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 + ;; + --version) + SHARED_FRAMEWORK_DEBIAN_VERSION=$2 + shift + ;; + --help) + help + ;; + *) + break + ;; + esac + shift +done + +PACKAGING_ROOT="$REPOROOT/packaging/sharedframework/debian" +PACKAGING_TOOL_DIR="$REPOROOT/tools/DebianPackageTool" + +PACKAGE_OUTPUT_DIR="$OBJECT_DIR/deb_output" +PACKAGE_LAYOUT_DIR="$OBJECT_DIR/deb_intermediate" + +execute_build(){ + create_empty_debian_layout + copy_files_to_debian_layout + update_debian_json + create_debian_package +} + +create_empty_debian_layout(){ + header "Creating empty debian package layout" + + rm -rf "$PACKAGE_LAYOUT_DIR" + mkdir -p "$PACKAGE_LAYOUT_DIR" + + mkdir "$PACKAGE_LAYOUT_DIR/\$" + mkdir "$PACKAGE_LAYOUT_DIR/package_root" + mkdir "$PACKAGE_LAYOUT_DIR/samples" + mkdir "$PACKAGE_LAYOUT_DIR/docs" +} + +copy_files_to_debian_layout(){ + header "Copying files to debian layout" + + # Copy Built Binaries + cp -a "$REPO_BINARIES_DIR/." "$PACKAGE_LAYOUT_DIR/package_root" + + # Copy config file + cp "$PACKAGING_ROOT/dotnet-sharedframework-debian_config.json" "$PACKAGE_LAYOUT_DIR/debian_config.json" +} + +create_debian_package(){ + header "Packing .deb" + + mkdir -p "$PACKAGE_OUTPUT_DIR" + + "$PACKAGING_TOOL_DIR/package_tool" -i "$PACKAGE_LAYOUT_DIR" -o "$PACKAGE_OUTPUT_DIR" -n "$SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME" -v "$SHARED_FRAMEWORK_DEBIAN_VERSION" +} + +update_debian_json() +{ + header "Updating debian.json file" + sed -i "s/%SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME%/$SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME/g" "$PACKAGE_LAYOUT_DIR"/debian_config.json + 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 +} + +execute_build + +DEBIAN_FILE=$(find $PACKAGE_OUTPUT_DIR -iname "*.deb") + +mv -f "$DEBIAN_FILE" "$OUTPUT_DEBIAN_FILE"