44# Stop script if command returns non-zero exit code.
55set -e
66
7- source=" ${BASH_SOURCE[0]} "
8-
97DEFAULT_TFM=net6.0
108
11- # resolve $SOURCE until the file is no longer a symlink
12- while [[ -h $source ]]; do
13- scriptroot=" $( cd -P " $( dirname " $source " ) " && pwd ) "
14- source=" $( readlink " $source " ) "
15-
16- # if $source was a relative symlink, we need to resolve it relative to the path where the
17- # symlink file was located
18- [[ $source != /* ]] && source=" $scriptroot /$source "
19- done
20-
9+ source=" $( readlink -f " ${BASH_SOURCE[0]} " ) "
2110scriptroot=" $( cd -P " $( dirname " $source " ) " && pwd ) "
2211
23- GREEN=' \033[0;32m'
2412RED=' \033[0;31m'
2513NC=' \033[0m'
2614
2715usage () {
2816 echo " usage: $0 [options]"
2917 echo " "
30- echo " Restores reference package(s) and dependencies and generates cs files and accompanying projects"
31- echo " to build a reference package. The generated artifacts are added to the /src/ directory of this repo"
32- echo " unless a different destination is specified. If a csv file of packages is specified, multiple"
33- echo " packages and their dependencies are generated."
18+ echo " Generates a reference package or a text-only package from the specified packages and versions. The"
19+ echo " type of the generated package is controlled via the --type option."
20+ echo " "
21+ echo " Reference package generation will restore reference package(s) and dependencies and generate cs files"
22+ echo " and with accompanying projects into the specified destination ('./src/referencePackages/' by default)."
23+ echo " Text-only package generation will restore the specified package and copy the source-build-usable content"
24+ echo " into the provided directory ('./src/textOnlyPackages/' by default)."
3425 echo " "
3526 echo " Either --pkg or --pkgCsv must be specified"
3627 echo " "
@@ -42,21 +33,25 @@ usage() {
4233 echo " --pkgCsv <pathToCSV> A path to a csv file of packages to generate. Format is the same as the --pkg"
4334 echo " option above, one per line. If specified, the --pkg option is ignored."
4435 echo " --dest <pathToDestRepo> A path to the root of the repo to copy source into."
36+ echo " --type <packageType> Type of the package to generate. Accepted values: text | ref."
37+ echo " Default: ref."
38+ echo " --feeds <nugetFeeds> A semicolon-separated list of additional NuGet feeds to use during restore."
4539 echo " "
4640}
4741
4842packageVersion=
4943defaultPathToCSV=" $scriptroot /artifacts/targetPackages.csv"
5044pathToCSV=
51- pathToDestRepo=" $scriptroot "
52- positional_args=()
53- requiredOptionSpecified=false
54- while : ; do
55- if [ $# -le 0 ]; then
56- break
57- fi
58- lowerI=" $( echo " $1 " | awk ' {print tolower($0)}' ) "
59- case $lowerI in
45+ pathToDestRepo=
46+ packageType=" ref"
47+
48+ if [[ $# -le 0 ]]; then
49+ usage
50+ exit 0
51+ fi
52+
53+ while [ $# -gt 0 ]; do
54+ case " $1 " in
6055 " -?" |-h|--help)
6156 usage
6257 exit 0
@@ -67,7 +62,6 @@ while :; do
6762 exit 1
6863 fi
6964 pathToCSV=" $( cd " $( dirname " $2 " ) " ; pwd) /$( basename " $2 " ) "
70- requiredOptionSpecified=true
7165 shift
7266 ;;
7367 --dest)
@@ -78,9 +72,21 @@ while :; do
7872 pathToDestRepo=" $( cd -P " $2 " && pwd) "
7973 shift
8074 ;;
75+ --type)
76+ packageType=" $2 "
77+ if [[ ! " $packageType " =~ ^(text| ref)$ ]]; then
78+ echo -e " ${RED} ERROR: unknown package type - $2 ${NC} "
79+ usage
80+ exit 1
81+ fi
82+ shift
83+ ;;
8184 --pkg)
8285 packageVersion=" $2 "
83- requiredOptionSpecified=true
86+ shift
87+ ;;
88+ --feeds)
89+ feeds=" $2 "
8490 shift
8591 ;;
8692 * )
@@ -93,7 +99,8 @@ while :; do
9399 shift
94100done
95101
96- if [ " $requiredOptionSpecified " != " true" ]; then
102+ if [ -z " $packageVersion " ] && [ -z " $pathToCSV " ]; then
103+ echo -e " ${RED} ERROR: Either --pkg or --pkgCsv must be specified!${NC} "
97104 usage
98105 exit 1
99106fi
@@ -107,6 +114,14 @@ if [ "$pathToCSV" == "" ]; then
107114 pathToCSV=" $defaultPathToCSV "
108115fi
109116
117+ if [[ -z " $pathToDestRepo " ]]; then
118+ if [ " $packageType " == " ref" ]; then
119+ pathToDestRepo=" $scriptroot /src/referencePackages/src"
120+ else
121+ pathToDestRepo=" $scriptroot /src/textOnlyPackages/src/"
122+ fi
123+ fi
124+
110125# Generate restore projects for each target package
111126# Packges are restored in their own project to eliminate any conflicts
112127# between different versions of the same package.
@@ -120,8 +135,8 @@ if [ -d "$restoreProjectsDir" ]; then
120135 rm -rf " $restoreProjectsDir "
121136fi
122137mkdir -p " $restoreProjectsDir "
123- [ ! -f $INPUT ] && { echo " $INPUT file not found" ; exit 99; }
124- while read pkgName pkgVersion tfm
138+ [ ! -f " $INPUT " ] && { echo " $INPUT file not found" ; exit 99; }
139+ while read -r pkgName pkgVersion tfm
125140do
126141 sed " s/##PackageName##/${pkgName} /g" " $targetPackageTemplate " > " $restoreProjectsDir /$pkgName .$pkgVersion .csproj"
127142 sed -i " s/##PackageVersion##/${pkgVersion} /g" " $restoreProjectsDir /$pkgName .$pkgVersion .csproj"
130145 else
131146 sed -i " s/##Tfm##/${DEFAULT_TFM} /g" " $restoreProjectsDir /$pkgName .$pkgVersion .csproj"
132147 fi
133- done < $INPUT
148+ done < " $INPUT "
134149IFS=$OLDIFS
135150
136- # Build the projects to generate source and projects
137- " $scriptroot /eng/common/build.sh " --build --restore -bl /p:GeneratePackageSource=true /p:GeneratorVersion=2 $@
151+ if [[ " $packageType " == " ref " ]] ; then
152+ pathToRepoSrc= " $pathToDestRepo "
138153
139- # Copy source to destination
140- pathToGeneratedSrc=" $scriptroot /artifacts/generatedSrc"
141- pathToRepoSrc=" $pathToDestRepo /src/referencePackages/src"
154+ # Build the projects to generate source and projects
155+ " $scriptroot /eng/common/build.sh" --build --restore -bl /p:GeneratePackageSource=true /p:GeneratorVersion=2 /p:PathToRepoSrc=" $pathToRepoSrc " /p:RestoreAdditionalProjectSources=" \" $feeds \" " " $@ "
156+ else
157+ # -p:RestoreAdditionalProjectSources -> specifies additional Nuget package sources, including feeds: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-properties
158+ # -p:RestoreUsingNuGetTargets -> switch that controls who will restore the project; if set to `false`, Arcade's Build.proj will execute the Restore target of the project itself.
159+ # Otherwise, Build.proj will trigger its own instance of Nuget.targets.Restore and delegate the restore of all applicable projects to it. In this case, the Restore target is
160+ # outside the project and we cannot hook our post-processing logic to it. For more info see:
161+ # https://github.com/dotnet/arcade/blob/5b838a3ed7f8e53c3082724605e5237fa614a43c/src/Microsoft.DotNet.Arcade.Sdk/tools/Build.proj#L227
142162
143- pushd " $pathToGeneratedSrc "
144- chmod 755 ./CopyProjects.sh
145- ./CopyProjects.sh " $pathToRepoSrc "
146- popd
147-
148- echo
149- echo -e " Copied generated projects from ${GREEN} $pathToGeneratedSrc ${NC} to ${GREEN} " $pathToRepoSrc " ${NC} "
150- echo
163+ " $scriptroot /eng/common/build.sh" -bl --restore --projects " $scriptroot /src/textOnlyPackageGenerator/PackageGenerator.proj" /p:RestoreUsingNuGetTargets=false /p:TextOnlyPackageDestination=" $pathToDestRepo " /p:PathToCsv=" $pathToCSV " /p:RestoreAdditionalProjectSources=" \" $feeds \" "
164+ fi
0 commit comments