Quellcode durchsuchen

Fix writing soong.variables .

ConfiguredJarList had a marshaler but no unmarshaler.

Bug: 182965747
Test: Presubmits.
Change-Id: Id03669f4a0a3d389063a4e4b11af6d6be63dbba3
Lukacs T. Berki vor 3 Jahren
Ursprung
Commit
720b3964fe
4 geänderte Dateien mit 51 neuen und 58 gelöschten Zeilen
  1. 15 0
      android/config.go
  2. 32 0
      android/config_test.go
  3. 3 0
      android/variable.go
  4. 1 58
      bootstrap_test.sh

+ 15 - 0
android/config.go

@@ -19,6 +19,7 @@ package android
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -1635,6 +1636,20 @@ func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error {
 	return nil
 }
 
+func (l *ConfiguredJarList) MarshalJSON() ([]byte, error) {
+	if len(l.apexes) != len(l.jars) {
+		return nil, errors.New(fmt.Sprintf("Inconsistent ConfiguredJarList: apexes: %q, jars: %q", l.apexes, l.jars))
+	}
+
+	list := make([]string, 0, len(l.apexes))
+
+	for i := 0; i < len(l.apexes); i++ {
+		list = append(list, l.apexes[i]+":"+l.jars[i])
+	}
+
+	return json.Marshal(list)
+}
+
 // ModuleStem hardcodes the stem of framework-minus-apex to return "framework".
 //
 // TODO(b/139391334): hard coded until we find a good way to query the stem of a

+ 32 - 0
android/config_test.go

@@ -16,6 +16,7 @@ package android
 
 import (
 	"fmt"
+	"path/filepath"
 	"reflect"
 	"strings"
 	"testing"
@@ -87,6 +88,37 @@ func TestMissingVendorConfig(t *testing.T) {
 	}
 }
 
+func verifyProductVariableMarshaling(t *testing.T, v productVariables) {
+	dir := t.TempDir()
+	path := filepath.Join(dir, "test.variables")
+	err := saveToConfigFile(&v, path)
+	if err != nil {
+		t.Errorf("Couldn't save default product config: %q", err)
+	}
+
+	var v2 productVariables
+	err = loadFromConfigFile(&v2, path)
+	if err != nil {
+		t.Errorf("Couldn't load default product config: %q", err)
+	}
+}
+func TestDefaultProductVariableMarshaling(t *testing.T) {
+	v := productVariables{}
+	v.SetDefaultConfig()
+	verifyProductVariableMarshaling(t, v)
+}
+
+func TestBootJarsMarshaling(t *testing.T) {
+	v := productVariables{}
+	v.SetDefaultConfig()
+	v.BootJars = ConfiguredJarList{
+		apexes: []string{"apex"},
+		jars:   []string{"jar"},
+	}
+
+	verifyProductVariableMarshaling(t, v)
+}
+
 func assertStringEquals(t *testing.T, expected, actual string) {
 	if actual != expected {
 		t.Errorf("expected %q found %q", expected, actual)

+ 3 - 0
android/variable.go

@@ -426,6 +426,9 @@ func (v *productVariables) SetDefaultConfig() {
 		Malloc_zero_contents:         boolPtr(true),
 		Malloc_pattern_fill_contents: boolPtr(false),
 		Safestack:                    boolPtr(false),
+
+		BootJars:          ConfiguredJarList{apexes: []string{}, jars: []string{}},
+		UpdatableBootJars: ConfiguredJarList{apexes: []string{}, jars: []string{}},
 	}
 
 	if runtime.GOOS == "linux" {

+ 1 - 58
bootstrap_test.sh

@@ -4,7 +4,7 @@
 # in a source tree that only contains enough files for Bazel and Soong to work.
 
 HARDWIRED_MOCK_TOP=
-# Uncomment this for to be able to view the source tree after a test is run
+# Uncomment this to be able to view the source tree after a test is run
 # HARDWIRED_MOCK_TOP=/tmp/td
 
 REAL_TOP="$(readlink -f "$(dirname "$0")"/../..)"
@@ -85,63 +85,6 @@ function setup() {
   export ALLOW_MISSING_DEPENDENCIES=true
 
   mkdir -p out/soong
-  # This is necessary because the empty soong.variables file written to satisfy
-  # Ninja would contain "BootJars: {}" instead of "BootJars: []" which cannot
-  # be parsed back
-  # TODO(b/182965747): Fix this.
-  cat > out/soong/soong.variables <<'EOF'
-{
-    "BuildNumberFile": "build_number.txt",
-    "Platform_version_name": "S",
-    "Platform_sdk_version": 30,
-    "Platform_sdk_codename": "S",
-    "Platform_sdk_final": false,
-    "Platform_version_active_codenames": [
-        "S"
-    ],
-    "Platform_vndk_version": "S",
-    "DeviceName": "generic_arm64",
-    "DeviceArch": "arm64",
-    "DeviceArchVariant": "armv8-a",
-    "DeviceCpuVariant": "generic",
-    "DeviceAbi": [
-        "arm64-v8a"
-    ],
-    "DeviceSecondaryArch": "arm",
-    "DeviceSecondaryArchVariant": "armv8-a",
-    "DeviceSecondaryCpuVariant": "generic",
-    "DeviceSecondaryAbi": [
-        "armeabi-v7a",
-        "armeabi"
-    ],
-    "HostArch": "x86_64",
-    "HostSecondaryArch": "x86",
-    "CrossHost": "windows",
-    "CrossHostArch": "x86",
-    "CrossHostSecondaryArch": "x86_64",
-    "AAPTCharacteristics": "nosdcard",
-    "AAPTConfig": [
-        "normal",
-        "large",
-        "xlarge",
-        "hdpi",
-        "xhdpi",
-        "xxhdpi"
-    ],
-    "AAPTPreferredConfig": "xhdpi",
-    "AAPTPrebuiltDPI": [
-        "xhdpi",
-        "xxhdpi"
-    ],
-    "Malloc_not_svelte": true,
-    "Malloc_zero_contents": true,
-    "Malloc_pattern_fill_contents": false,
-    "Safestack": false,
-    "BootJars": [],
-    "UpdatableBootJars": [],
-    "Native_coverage": null
-}
-EOF
 }
 
 function run_soong() {