From d13ae7f2f458ba6be93b1dee4d2224a52b92da08 Mon Sep 17 00:00:00 2001 From: Recolic K <bensl@microsoft.com> Date: Wed, 12 May 2021 16:14:06 +0800 Subject: [PATCH] allow debug output --- tools/nuget-download-package/main.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/nuget-download-package/main.go b/tools/nuget-download-package/main.go index 6e7cdca..6d53fb8 100644 --- a/tools/nuget-download-package/main.go +++ b/tools/nuget-download-package/main.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "sync" ) @@ -176,7 +177,7 @@ func decidePackageVersionRange(packageName, frameworkVersion string, indexJsons // If frameworkVersion != "", then I find the latest available package for this framework. // If packageVersion != "", then I find the url for this version. // You must only set ONE OF THEM! If you set both, the `frameworkVersion` would be ignored. -func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, indexJsons_Login []string) (maxAvailableVersion, maxAvailableVersionUrl, maxAvailableVersionUrlLogin string) { +func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, indexJsons_Login []string, debugOutput bool) (maxAvailableVersion, maxAvailableVersionUrl, maxAvailableVersionUrlLogin string) { // The golang json parse library sucks. Prevent it from crashing // on a json syntax error. // @@ -204,7 +205,9 @@ func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, i jCatalogEntry := jPkgVersionItem["catalogEntry"].(map[string]interface{}) myVersionText := jCatalogEntry["version"].(string) myVersionUrl := jPkgVersionItem["packageContent"].(string) - // log.Println("DEBUG: reaching " + myVersionText) + if debugOutput { + log.Println("DEBUG: reaching " + myVersionText) + } // Let's check if this version is ok thisPkgVersionIsOk, thisPkgVersionIsPossibleOk := false, false @@ -214,7 +217,9 @@ func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, i for _, j6 := range j5.([]interface{}) { j7 := j6.(map[string]interface{}) if j8, ok := j7["targetFramework"]; ok { - // log.Println("DEBUG: " + frameworkVersion +" vs "+ netVersionNugetFormatToStandardFormat(j8.(string))) + if debugOutput { + log.Println("DEBUG: " + frameworkVersion +" vs "+ netVersionNugetFormatToStandardFormat(j8.(string))) + } if frameworkVersion == netVersionNugetFormatToStandardFormat(j8.(string)) { thisPkgVersionIsOk = true break @@ -231,6 +236,9 @@ func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, i } if packageVersion != "" { + if debugOutput { + log.Println("DEBUG: " + packageVersion + " vs " + myVersionText) + } // It should be a percise match here. However, someone in ControlPlane using PkgNewtonsoft_json_12. // They only provide parts of the version number. It sucks. thisPkgVersionIsOk = packageVersion == myVersionText @@ -261,7 +269,9 @@ func decidePackageVersion(frameworkVersion, packageVersion string, indexJsons, i PossibleAvailableVersionUrlLogin = indexJsons_Login[indexJson_currIndex] } } - // log.Println("DEBUG: leaving " + myVersionText) + if(debugOutput) { + log.Println("DEBUG: leaving " + myVersionText + ". IsOk=" + strconv.FormatBool(thisPkgVersionIsOk) + ", IsPossibleOk=" + strconv.FormatBool(thisPkgVersionIsPossibleOk)) + } }() // catch exception and continue } } @@ -299,9 +309,9 @@ func main() { pkgVer, targetUrl, targetUrlLogin := "", "", "" if strings.HasPrefix(pkgVerOrNetVer, "net") { - pkgVer, targetUrl, targetUrlLogin = decidePackageVersion(pkgVerOrNetVer, "", indexJsons, indexJsons_Login) - } else { - pkgVer, targetUrl, targetUrlLogin = decidePackageVersion("", pkgVerOrNetVer, indexJsons, indexJsons_Login) + pkgVer, targetUrl, targetUrlLogin = decidePackageVersion(pkgVerOrNetVer, "", indexJsons, indexJsons_Login, os.Getenv("OPENXT_DEBUG") == "1") + } else { + pkgVer, targetUrl, targetUrlLogin = decidePackageVersion("", pkgVerOrNetVer, indexJsons, indexJsons_Login, os.Getenv("OPENXT_DEBUG") == "1") } if pkgVer == "" { -- GitLab