aede88c1c7
APEX variants that share the same SDK version and updatability almost always use identical command line arguments to build but with different intermediates directories. This causes unnecessary build time and disk space for duplicated work. Deduplicate APEX variants that would build identically. Create aliases from the per-APEX variations to the new shared variations so that the APEX modules can continue to depend on them via the APEX name as the variation. This has one significant change in behavior. Before this change, if an APEX had two libraries in its direct dependencies and one of those libraries depended on the other, and the second library had stubs, then the first library would depend on the implementation of the second library and not the stubs. After this change, if the first library is also present in a second APEX but the second library is not, then the common variant shared between the two APEXes would use the stubs, not the implementation. In a correctly configured set of build rules this change will be irrelevant, because if the compilation worked for the second APEX using stubs then it will work for the common variant using stubs. However, if an incorrect change to the build rules is made this could lead to confusing errors, as a previously-working common variant could suddenly stop building when a module is added to a new APEX without its dependencies that require implementation APIs to compile. This change reduces the number of modules in an AOSP arm64-userdebug build by 3% (52242 to 50586), reduces the number of variants of the libcutils module from 74 to 53, and reduces the number of variants of the massive libart[d] modules from 44 to 32. This relands I0529837476a253c32b3dfb98dcccf107427c742c with a fix to always mark permissions XML files of java_sdk_library modules as unique per apex since they contain the APEX filename, and a fix to UpdateUniqueApexVariationsForDeps to check ApexInfo.InApexes instead of DepIsInSameApex to check if two modules are in the same apex to account for a module that depends on another in a way that doesn't normally include the dependency in the APEX (e.g. a libs property), but the dependency is directly included in the APEX. Bug: 164216768 Test: go test ./build/soong/apex/... Change-Id: I2ae170601f764e5b88d0be2e0e6adc84e3a4d9cc
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
// Copyright 2020 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package android
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func Test_mergeApexVariations(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in []ApexInfo
|
|
wantMerged []ApexInfo
|
|
wantAliases [][2]string
|
|
}{
|
|
{
|
|
name: "single",
|
|
in: []ApexInfo{
|
|
{"foo", 10000, false, nil, []string{"foo"}},
|
|
},
|
|
wantMerged: []ApexInfo{
|
|
{"apex10000", 10000, false, nil, []string{"foo"}},
|
|
},
|
|
wantAliases: [][2]string{
|
|
{"foo", "apex10000"},
|
|
},
|
|
},
|
|
{
|
|
name: "merge",
|
|
in: []ApexInfo{
|
|
{"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
|
|
{"bar", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar"}},
|
|
},
|
|
wantMerged: []ApexInfo{
|
|
{"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"bar", "foo"}},
|
|
},
|
|
wantAliases: [][2]string{
|
|
{"bar", "apex10000_baz_1"},
|
|
{"foo", "apex10000_baz_1"},
|
|
},
|
|
},
|
|
{
|
|
name: "don't merge version",
|
|
in: []ApexInfo{
|
|
{"foo", 10000, false, nil, []string{"foo"}},
|
|
{"bar", 30, false, nil, []string{"bar"}},
|
|
},
|
|
wantMerged: []ApexInfo{
|
|
{"apex30", 30, false, nil, []string{"bar"}},
|
|
{"apex10000", 10000, false, nil, []string{"foo"}},
|
|
},
|
|
wantAliases: [][2]string{
|
|
{"bar", "apex30"},
|
|
{"foo", "apex10000"},
|
|
},
|
|
},
|
|
{
|
|
name: "merge updatable",
|
|
in: []ApexInfo{
|
|
{"foo", 10000, false, nil, []string{"foo"}},
|
|
{"bar", 10000, true, nil, []string{"bar"}},
|
|
},
|
|
wantMerged: []ApexInfo{
|
|
{"apex10000", 10000, true, nil, []string{"bar", "foo"}},
|
|
},
|
|
wantAliases: [][2]string{
|
|
{"bar", "apex10000"},
|
|
{"foo", "apex10000"},
|
|
},
|
|
},
|
|
{
|
|
name: "don't merge sdks",
|
|
in: []ApexInfo{
|
|
{"foo", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
|
|
{"bar", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
|
|
},
|
|
wantMerged: []ApexInfo{
|
|
{"apex10000_baz_2", 10000, false, SdkRefs{{"baz", "2"}}, []string{"bar"}},
|
|
{"apex10000_baz_1", 10000, false, SdkRefs{{"baz", "1"}}, []string{"foo"}},
|
|
},
|
|
wantAliases: [][2]string{
|
|
{"bar", "apex10000_baz_2"},
|
|
{"foo", "apex10000_baz_1"},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotMerged, gotAliases := mergeApexVariations(tt.in)
|
|
if !reflect.DeepEqual(gotMerged, tt.wantMerged) {
|
|
t.Errorf("mergeApexVariations() gotMerged = %v, want %v", gotMerged, tt.wantMerged)
|
|
}
|
|
if !reflect.DeepEqual(gotAliases, tt.wantAliases) {
|
|
t.Errorf("mergeApexVariations() gotAliases = %v, want %v", gotAliases, tt.wantAliases)
|
|
}
|
|
})
|
|
}
|
|
}
|