From 725eac60a241f19ca507dd894499a009a06ecf50 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 3 Oct 2022 15:31:29 -0700 Subject: [PATCH] Add AllowMissingDependencies support for prebuilt_etc module with no src property Arch-specific prebuilt_etc modules may be missing source files for new architectures. Allow build analysis to continue when there is no source file when AllowMissingDependencies is set. Bug: 250918230 Test: lunch aosp_riscv64-userdebug && m ALLOW_MISSING_DEPENDENCIES=true nothing Test: TestPrebuiltEtcAllowMissingDependencies Change-Id: I647c7305339e3ed80283be5e59e6f4ef15ae2384 --- etc/prebuilt_etc.go | 44 ++++++++++++++++++++++++---------------- etc/prebuilt_etc_test.go | 24 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index 362a8ef3c..baad58eed 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -296,27 +296,37 @@ func (p *PrebuiltEtc) ExcludeFromRecoverySnapshot() bool { } func (p *PrebuiltEtc) GenerateAndroidBuildActions(ctx android.ModuleContext) { - if p.properties.Src == nil { - ctx.PropertyErrorf("src", "missing prebuilt source file") - return - } - p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src)) - - // Determine the output file basename. - // If Filename is set, use the name specified by the property. - // If Filename_from_src is set, use the source file name. - // Otherwise use the module name. filename := proptools.String(p.properties.Filename) filenameFromSrc := proptools.Bool(p.properties.Filename_from_src) - if filename != "" { - if filenameFromSrc { - ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") - return + if p.properties.Src != nil { + p.sourceFilePath = android.PathForModuleSrc(ctx, proptools.String(p.properties.Src)) + + // Determine the output file basename. + // If Filename is set, use the name specified by the property. + // If Filename_from_src is set, use the source file name. + // Otherwise use the module name. + if filename != "" { + if filenameFromSrc { + ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true") + return + } + } else if filenameFromSrc { + filename = p.sourceFilePath.Base() + } else { + filename = ctx.ModuleName() + } + } else if ctx.Config().AllowMissingDependencies() { + // If no srcs was set and AllowMissingDependencies is enabled then + // mark the module as missing dependencies and set a fake source path + // and file name. + ctx.AddMissingDependencies([]string{"MISSING_PREBUILT_SRC_FILE"}) + p.sourceFilePath = android.PathForModuleSrc(ctx) + if filename == "" { + filename = ctx.ModuleName() } - } else if filenameFromSrc { - filename = p.sourceFilePath.Base() } else { - filename = ctx.ModuleName() + ctx.PropertyErrorf("src", "missing prebuilt source file") + return } p.outputFilePath = android.PathForModuleOut(ctx, filename).OutputPath diff --git a/etc/prebuilt_etc_test.go b/etc/prebuilt_etc_test.go index cf1f6d717..a6477dd6a 100644 --- a/etc/prebuilt_etc_test.go +++ b/etc/prebuilt_etc_test.go @@ -195,6 +195,30 @@ func TestPrebuiltEtcHost(t *testing.T) { } } +func TestPrebuiltEtcAllowMissingDependencies(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForPrebuiltEtcTest, + android.PrepareForTestDisallowNonExistentPaths, + android.FixtureModifyConfig( + func(config android.Config) { + config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true) + }), + ).RunTestWithBp(t, ` + prebuilt_etc { + name: "foo.conf", + filename_from_src: true, + arch: { + x86: { + src: "x86.conf", + }, + }, + } + `) + + android.AssertStringEquals(t, "expected error rule", "android/soong/android.Error", + result.ModuleForTests("foo.conf", "android_arm64_armv8-a").Output("foo.conf").Rule.String()) +} + func TestPrebuiltRootInstallDirPath(t *testing.T) { result := prepareForPrebuiltEtcTest.RunTestWithBp(t, ` prebuilt_root {