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

Commit 45c647d4 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Gerrit Code Review
Browse files

Merge changes I59439b77,I7dbaf8be

* changes:
  bloaty: measure stripped Rust binaries
  rust: do not strip static library
parents 9e7cea2c e4dd14b2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ bootstrap_go_package {
    ],
    srcs: [
        "bloaty.go",
        "testing.go",
    ],
    pluginFor: ["soong_build"],
}
+32 −15
Original line number Diff line number Diff line
@@ -52,12 +52,28 @@ func init() {
	pctx.SourcePathVariable("bloaty", "prebuilts/build-tools/${hostPrebuiltTag}/bin/bloaty")
	pctx.HostBinToolVariable("bloatyMerger", "bloaty_merger")
	android.RegisterSingletonType("file_metrics", fileSizesSingleton)
	fileSizeMeasurerKey = blueprint.NewProvider(android.ModuleOutPath{})
	fileSizeMeasurerKey = blueprint.NewProvider(measuredFiles{})
}

// MeasureSizeForPath should be called by binary producers (e.g. in builder.go).
func MeasureSizeForPath(ctx android.ModuleContext, filePath android.WritablePath) {
	ctx.SetProvider(fileSizeMeasurerKey, filePath)
// measuredFiles contains the paths of the files measured by a module.
type measuredFiles struct {
	paths []android.WritablePath
}

// MeasureSizeForPaths should be called by binary producers to measure the
// sizes of artifacts. It must only be called once per module; it will panic
// otherwise.
func MeasureSizeForPaths(ctx android.ModuleContext, paths ...android.OptionalPath) {
	mf := measuredFiles{}
	for _, p := range paths {
		if !p.Valid() {
			continue
		}
		if p, ok := p.Path().(android.WritablePath); ok {
			mf.paths = append(mf.paths, p)
		}
	}
	ctx.SetProvider(fileSizeMeasurerKey, mf)
}

type sizesSingleton struct{}
@@ -68,13 +84,13 @@ func fileSizesSingleton() android.Singleton {

func (singleton *sizesSingleton) GenerateBuildActions(ctx android.SingletonContext) {
	var deps android.Paths
	// Visit all modules. If the size provider give us a binary path to measure,
	// create the rule to measure it.
	ctx.VisitAllModules(func(m android.Module) {
		if !ctx.ModuleHasProvider(m, fileSizeMeasurerKey) {
			return
		}
		filePath := ctx.ModuleProvider(m, fileSizeMeasurerKey).(android.ModuleOutPath)
		filePaths := ctx.ModuleProvider(m, fileSizeMeasurerKey).(measuredFiles)
		for _, path := range filePaths.paths {
			filePath := path.(android.ModuleOutPath)
			sizeFile := filePath.InSameDir(ctx, filePath.Base()+bloatyDescriptorExt)
			ctx.Build(pctx, android.BuildParams{
				Rule:        bloaty,
@@ -83,6 +99,7 @@ func (singleton *sizesSingleton) GenerateBuildActions(ctx android.SingletonConte
				Output:      sizeFile,
			})
			deps = append(deps, sizeFile)
		}
	})

	ctx.Build(pctx, android.BuildParams{

bloaty/testing.go

0 → 100644
+25 −0
Original line number Diff line number Diff line
// Copyright 2021 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 bloaty

import (
	"android/soong/android"
)

// Preparer that will define the default bloaty singleton.
var PrepareForTestWithBloatyDefaultModules = android.GroupFixturePreparers(
	android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
		ctx.RegisterSingletonType("file_metrics", fileSizesSingleton)
	}))
+0 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import (
	"github.com/google/blueprint"

	"android/soong/android"
	"android/soong/bloaty"
	"android/soong/rust/config"
)

@@ -254,8 +253,6 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
		implicits = append(implicits, clippyFile)
	}

	bloaty.MeasureSizeForPath(ctx, outputFile)

	ctx.Build(pctx, android.BuildParams{
		Rule:            rustc,
		Description:     "rustc " + main.Rel(),
+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
		TransformSrctoShared(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)
	}

	if !library.rlib() && library.stripper.NeedsStrip(ctx) {
	if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
		strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName)
		library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
		library.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
Loading