From 67eada34db07986abde08d652cd249c977d4a55c Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 23 Sep 2021 11:50:33 -0400 Subject: rust: Refactor cfg and feature flag calculation Move the cfg and feature flag calculation out of compilerFlags so that it's a separate step. The previous arrangement resulted in overridden compilerFlags which must to set any additional cfgs/features before calling the base. This is a bit confusing and undocumented behavior, so instead break it out into a separate call that can itself be overriden. Bug: N/A Test: Soong tests pass Change-Id: I28e4f707b3b3ca6eb621b7613c3737817f877bb8 --- rust/compiler.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'rust/compiler.go') diff --git a/rust/compiler.go b/rust/compiler.go index 7bd9af4a8..1ce71f60b 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -231,6 +231,7 @@ func (compiler *baseCompiler) cfgsToFlags() []string { for _, cfg := range compiler.Properties.Cfgs { flags = append(flags, "--cfg '"+cfg+"'") } + return flags } @@ -239,6 +240,24 @@ func (compiler *baseCompiler) featuresToFlags() []string { for _, feature := range compiler.Properties.Features { flags = append(flags, "--cfg 'feature=\""+feature+"\"'") } + + return flags +} + +func (compiler *baseCompiler) featureFlags(ctx ModuleContext, flags Flags) Flags { + flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...) + flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...) + + return flags +} + +func (compiler *baseCompiler) cfgFlags(ctx ModuleContext, flags Flags) Flags { + if ctx.RustModule().UseVndk() { + compiler.Properties.Cfgs = append(compiler.Properties.Cfgs, "android_vndk") + } + + flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...) + flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...) return flags } @@ -269,10 +288,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag flags.RustFlags = append(flags.RustFlags, lintFlags) flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...) - flags.RustFlags = append(flags.RustFlags, compiler.cfgsToFlags()...) - flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags()...) - flags.RustdocFlags = append(flags.RustdocFlags, compiler.cfgsToFlags()...) - flags.RustdocFlags = append(flags.RustdocFlags, compiler.featuresToFlags()...) flags.RustFlags = append(flags.RustFlags, "--edition="+compiler.edition()) flags.RustdocFlags = append(flags.RustdocFlags, "--edition="+compiler.edition()) flags.LinkFlags = append(flags.LinkFlags, compiler.Properties.Ld_flags...) @@ -296,10 +311,6 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+"../"+rpath) } - if ctx.RustModule().UseVndk() { - flags.RustFlags = append(flags.RustFlags, "--cfg 'android_vndk'") - } - return flags } -- cgit v1.2.3-59-g8ed1b