[fint] Generate args.gn more similar to `fx set`

1. Include all the `*_labels` vars in args.gn even if they're empty, to
   make it easier to add new labels to those lists manually using `fx
   args`.
2. Put all list appends last, so that all the `*_labels` will be at the
   end of args.gn, which `fx set` does.

This will make the transition to the new fint-based version of `fx set`
less noticeable for people who use `fx args` or otherwise frequently
inspect args.gn.

Bug: 68465
Change-Id: I894561fdb670dfb4c059b17580892beaba6e54d1
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/541865
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Gary Boone <gboone@google.com>
diff --git a/tools/integration/fint/set.go b/tools/integration/fint/set.go
index 2cf3bcf..31cf69d 100644
--- a/tools/integration/fint/set.go
+++ b/tools/integration/fint/set.go
@@ -253,9 +253,6 @@
 		"universe_package_labels": staticSpec.UniversePackages,
 		"host_labels":             staticSpec.HostLabels,
 	} {
-		if len(values) == 0 {
-			continue
-		}
 		// If product is set, append to the corresponding list variable instead
 		// of overwriting it to avoid overwriting any packages set in the
 		// imported product file.
@@ -288,36 +285,39 @@
 		vars["rust_incremental"] = filepath.Join(contextSpec.CacheDir, "rust_cache")
 	}
 
-	var normalArgs []string
-	var importArgs []string
+	var importArgs, varArgs, appendArgs []string
 	for _, arg := range staticSpec.GnArgs {
 		if strings.HasPrefix(arg, "import(") {
 			importArgs = append(importArgs, arg)
+		} else if strings.Contains(arg, "+=") {
+			appendArgs = append(appendArgs, arg)
 		} else {
-			normalArgs = append(normalArgs, arg)
+			varArgs = append(varArgs, arg)
 		}
 	}
 
 	for k, v := range vars {
-		normalArgs = append(normalArgs, fmt.Sprintf("%s=%s", k, toGNValue(v)))
+		varArgs = append(varArgs, fmt.Sprintf("%s=%s", k, toGNValue(v)))
 	}
+	sort.Strings(varArgs)
+
 	for k, v := range appends {
-		normalArgs = append(normalArgs, fmt.Sprintf("%s+=%s", k, toGNValue(v)))
+		appendArgs = append(appendArgs, fmt.Sprintf("%s+=%s", k, toGNValue(v)))
 	}
-	sort.Strings(normalArgs)
+	sort.Strings(appendArgs)
 
 	for _, p := range imports {
 		importArgs = append(importArgs, fmt.Sprintf(`import("//%s")`, p))
 	}
 	sort.Strings(importArgs)
 
-	var finalArgs []string
-
 	// Ensure that imports come before args that set or modify variables, as
 	// otherwise the imported files might blindly redefine variables set or
 	// modified by other arguments.
+	var finalArgs []string
 	finalArgs = append(finalArgs, importArgs...)
-	finalArgs = append(finalArgs, normalArgs...)
+	finalArgs = append(finalArgs, varArgs...)
+	finalArgs = append(finalArgs, appendArgs...)
 	return finalArgs, nil
 }