Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09ef474b authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes I0dcc9c7b,I9bc40642

* changes:
  Move cc.imageMutator into the android package
  Make CreateVariations return []android.Module
parents 4b49b768 7228ecd5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ bootstrap_go_package {
        "android/expand.go",
        "android/filegroup.go",
        "android/hooks.go",
        "android/image.go",
        "android/makevars.go",
        "android/module.go",
        "android/mutator.go",
+2 −4
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ package android
import (
	"sort"
	"sync"

	"github.com/google/blueprint"
)

// ApexModule is the interface that a module type is expected to implement if
@@ -69,7 +67,7 @@ type ApexModule interface {

	// Mutate this module into one or more variants each of which is built
	// for an APEX marked via BuildForApex().
	CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module
	CreateApexVariations(mctx BottomUpMutatorContext) []Module

	// Sets the name of the apex variant of this module. Called inside
	// CreateApexVariations.
@@ -176,7 +174,7 @@ func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
	}
}

func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module {
func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module {
	if len(m.apexVariations) > 0 {
		m.checkApexAvailableProperty(mctx)
		sort.Strings(m.apexVariations)

android/image.go

0 → 100644
+83 −0
Original line number Diff line number Diff line
// Copyright 2019 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

// ImageInterface is implemented by modules that need to be split by the ImageMutator.
type ImageInterface interface {
	// ImageMutatorBegin is called before any other method in the ImageInterface.
	ImageMutatorBegin(ctx BaseModuleContext)

	// CoreVariantNeeded should return true if the module needs a core variant (installed on the system image).
	CoreVariantNeeded(ctx BaseModuleContext) bool

	// RecoveryVariantNeeded should return true if the module needs a recovery variant (installed on the
	// recovery partition).
	RecoveryVariantNeeded(ctx BaseModuleContext) bool

	// ExtraImageVariations should return a list of the additional variations needed for the module.  After the
	// variants are created the SetImageVariation method will be called on each newly created variant with the
	// its variation.
	ExtraImageVariations(ctx BaseModuleContext) []string

	// SetImageVariation will be passed a newly created recovery variant of the module.  ModuleBase implements
	// SetImageVariation, most module types will not need to override it, and those that do must call the
	// overridden method.  Implementors of SetImageVariation must be careful to modify the module argument
	// and not the receiver.
	SetImageVariation(ctx BaseModuleContext, variation string, module Module)
}

const (
	// CoreVariation is the variant used for framework-private libraries, or
	// SDK libraries. (which framework-private libraries can use), which
	// will be installed to the system image.
	CoreVariation string = "core"

	// RecoveryVariation means a module to be installed to recovery image.
	RecoveryVariation string = "recovery"
)

// ImageMutator creates variants for modules that implement the ImageInterface that
// allow them to build differently for each partition (recovery, core, vendor, etc.).
func ImageMutator(ctx BottomUpMutatorContext) {
	if ctx.Os() != Android {
		return
	}

	if m, ok := ctx.Module().(ImageInterface); ok {
		m.ImageMutatorBegin(ctx)

		var variations []string

		if m.CoreVariantNeeded(ctx) {
			variations = append(variations, CoreVariation)
		}
		if m.RecoveryVariantNeeded(ctx) {
			variations = append(variations, RecoveryVariation)
		}

		extraVariations := m.ExtraImageVariations(ctx)
		variations = append(variations, extraVariations...)

		if len(variations) == 0 {
			return
		}

		mod := ctx.CreateVariations(variations...)
		for i, v := range variations {
			mod[i].base().setImageVariation(v)
			m.SetImageVariation(ctx, v, mod[i])
		}
	}
}
+18 −0
Original line number Diff line number Diff line
@@ -431,6 +431,9 @@ type commonProperties struct {
	DebugName       string   `blueprint:"mutated"`
	DebugMutators   []string `blueprint:"mutated"`
	DebugVariations []string `blueprint:"mutated"`

	// set by ImageMutator
	ImageVariation string `blueprint:"mutated"`
}

type hostAndDeviceProperties struct {
@@ -865,6 +868,21 @@ func (m *ModuleBase) NoticeFile() OptionalPath {
	return m.noticeFile
}

func (m *ModuleBase) setImageVariation(variant string) {
	m.commonProperties.ImageVariation = variant
}

func (m *ModuleBase) ImageVariation() blueprint.Variation {
	return blueprint.Variation{
		Mutator:   "image",
		Variation: m.base().commonProperties.ImageVariation,
	}
}

func (m *ModuleBase) InRecovery() bool {
	return m.base().commonProperties.ImageVariation == RecoveryVariation
}

func (m *ModuleBase) generateModuleTarget(ctx ModuleContext) {
	allInstalledFiles := Paths{}
	allCheckbuildFiles := Paths{}
+12 −8
Original line number Diff line number Diff line
@@ -143,8 +143,8 @@ type BottomUpMutatorContext interface {

	AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string)
	AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
	CreateVariations(...string) []blueprint.Module
	CreateLocalVariations(...string) []blueprint.Module
	CreateVariations(...string) []Module
	CreateLocalVariations(...string) []Module
	SetDependencyVariation(string)
	SetDefaultDependencyVariation(*string)
	AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
@@ -285,28 +285,32 @@ func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, t
	b.bp.AddReverseDependency(module, tag, name)
}

func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []blueprint.Module {
func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
	modules := b.bp.CreateVariations(variations...)

	aModules := make([]Module, len(modules))
	for i := range variations {
		base := modules[i].(Module).base()
		aModules[i] = modules[i].(Module)
		base := aModules[i].base()
		base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
		base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
	}

	return modules
	return aModules
}

func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []blueprint.Module {
func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
	modules := b.bp.CreateLocalVariations(variations...)

	aModules := make([]Module, len(modules))
	for i := range variations {
		base := modules[i].(Module).base()
		aModules[i] = modules[i].(Module)
		base := aModules[i].base()
		base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
		base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
	}

	return modules
	return aModules
}

func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
Loading