diff --git a/src/SourceBuild/content/eng/bootstrap/README.template.md b/src/SourceBuild/content/eng/bootstrap/README.template.md index e79c35fc4..f6d91d55f 100644 --- a/src/SourceBuild/content/eng/bootstrap/README.template.md +++ b/src/SourceBuild/content/eng/bootstrap/README.template.md @@ -139,6 +139,12 @@ ln -s $HOME/.dotnet/dotnet /usr/bin/dotnet You can also utilize [GitHub Codespaces](https://github.com/features/codespaces) where you can find preset containers in this repository. +### Exporting a source archive + +In case you'd like to export a more lightweight archive of sources that can be built outside of this git repository, a simple copy of the working tree won't do. +The build is using some git metadata (information from the `.git` directory) that are needed to be kept with the sources. +To export a `tar.gz` archive of the sources, you need to use the `eng/pack-sources.sh` script from within a clone of the VMR checked out at the revision that you're interested in. + ## List of components To enable full offline source-building of the VMR, we have no other choice than to synchronize all the necessary code into the VMR. This also includes any code referenced via git submodules. More details on why and how this is done can be found here: diff --git a/src/SourceBuild/content/eng/pack-sources.sh b/src/SourceBuild/content/eng/pack-sources.sh new file mode 100755 index 000000000..ecb2c8920 --- /dev/null +++ b/src/SourceBuild/content/eng/pack-sources.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +### This script exports the sources of VMR (dotnet/dotnet) as an archive that can be used +### to build the .NET SDK. +### It expects you clone the dotnet/dotnet repo locally and check out the desired revision. +### +### USAGE: +### ./pack-sources.sh -o dotnet.tar.gz +### Options: +### -o, --output PATH +### Optional. Path or dir where the archive is created. +### Defaults to artifacts/packages/dotnet-[SHA].tar.gz + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + +function print_help () { + sed -n '/^### /,/^$/p' "$source" | cut -b 5- +} + +GIT_ROOT=$(realpath "$scriptroot/../") + +output='' + +while [[ $# -gt 0 ]]; do + opt="$(echo "$1" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -o|--output) + output=$2 + shift + ;; + -h|--help) + print_help + exit 0 + ;; + *) + fail "Invalid argument: $1" + usage + exit 1 + ;; + esac + + shift +done + +revision=$(git -C "$GIT_ROOT" rev-parse HEAD) +filename="dotnet-$revision" + +if [[ -z "$output" ]]; then + output="$GIT_ROOT/artifacts/packages/$filename.tar.gz" +fi + +# If output is directory, use the default filename +if [[ -d "$output" ]]; then + output="$output/$filename.tar.gz" +fi + +set -e + +echo "Packing sources of $revision to $output.." +mkdir -p "$(dirname "$output")" +rm -f "$output" + +tmp="$GIT_ROOT/artifacts/tmp" +mkdir -p "$tmp" +config_file="$tmp/config" +HEAD_file="$tmp/HEAD" + +start_time=$(date +%s) + +# We need to had `.git/HEAD` and `.git/config` to the archive as the build expects those +echo $'[remote "origin"]\nurl="http://github.com/dotnet/dotnet"' > "$config_file" +echo "$revision" > "$HEAD_file" + +git -C "$GIT_ROOT" archive \ + -o "$output" \ + --prefix "$filename/.git/" \ + --add-file "$config_file" \ + --add-file "$HEAD_file" \ + --prefix "$filename/" \ + "$revision" "$GIT_ROOT" + +end_time=$(date +%s) +elapsed=$(( end_time - start_time )) + +duration=$(date -u +%H:%M:%S "-d@$elapsed") +echo "Archive created in $duration" diff --git a/src/redist/targets/GenerateMSIs.targets b/src/redist/targets/GenerateMSIs.targets index 22dd63038..ccb6baf69 100644 --- a/src/redist/targets/GenerateMSIs.targets +++ b/src/redist/targets/GenerateMSIs.targets @@ -70,15 +70,15 @@ $(LayoutDirectory)MSBuildExtensions--> + + + Condition=" '$(GitCommitCount)' == '' AND '$(_PatchNumber)' == '' "> - - $(GitCommitCount.PadLeft(6,'0'))