Refactor vendor snapshot to use LinkableInterface.

Refactors the vendor snapshot support to use the LinkableInterface
so that support can be extended to Rust. This CL does not add
vendor snapshot support for Rust; that is left for a follow-on CL.

Bug: 184042776
Test: m nothing
Change-Id: Id0c4970ca00053484a52677d182153cbc454c301
diff --git a/rust/Android.bp b/rust/Android.bp
index f45404f..b611672 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -31,8 +31,9 @@
         "protobuf.go",
         "rust.go",
         "sanitize.go",
-        "strip.go",
         "source_provider.go",
+        "snapshot_utils.go",
+        "strip.go",
         "test.go",
         "testing.go",
     ],
diff --git a/rust/compiler.go b/rust/compiler.go
index a3f02c0..1598ebf 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -341,6 +341,11 @@
 	return compiler.Properties.Crate_name
 }
 
+func (compiler *baseCompiler) everInstallable() bool {
+	// Most modules are installable, so return true by default.
+	return true
+}
+
 func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath {
 	dir := compiler.dir
 	if ctx.toolchain().Is64Bit() && compiler.dir64 != "" {
diff --git a/rust/proc_macro.go b/rust/proc_macro.go
index 4eead32..c217959 100644
--- a/rust/proc_macro.go
+++ b/rust/proc_macro.go
@@ -82,3 +82,8 @@
 func (procMacro *procMacroDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
 	return rlibAutoDep
 }
+
+func (procMacro *procMacroDecorator) everInstallable() bool {
+	// Proc_macros are never installed
+	return false
+}
diff --git a/rust/rust.go b/rust/rust.go
index bb97142..f068b3d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -97,6 +97,7 @@
 
 	PreventInstall bool
 	HideFromMake   bool
+	Installable    *bool
 }
 
 type Module struct {
@@ -143,6 +144,10 @@
 	mod.Properties.HideFromMake = true
 }
 
+func (c *Module) HiddenFromMake() bool {
+	return c.Properties.HideFromMake
+}
+
 func (mod *Module) SanitizePropDefined() bool {
 	// Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
 	// nil since we need compiler to actually sanitize.
@@ -210,6 +215,38 @@
 	return false
 }
 
+func (mod *Module) Dylib() bool {
+	if mod.compiler != nil {
+		if library, ok := mod.compiler.(libraryInterface); ok {
+			return library.dylib()
+		}
+	}
+	return false
+}
+
+func (mod *Module) Rlib() bool {
+	if mod.compiler != nil {
+		if library, ok := mod.compiler.(libraryInterface); ok {
+			return library.rlib()
+		}
+	}
+	return false
+}
+
+func (mod *Module) Binary() bool {
+	if mod.compiler != nil {
+		if _, ok := mod.compiler.(*binaryDecorator); ok {
+			return true
+		}
+	}
+	return false
+}
+
+func (mod *Module) Object() bool {
+	// Rust has no modules which produce only object files.
+	return false
+}
+
 func (mod *Module) Toc() android.OptionalPath {
 	if mod.compiler != nil {
 		if _, ok := mod.compiler.(libraryInterface); ok {
@@ -223,12 +260,13 @@
 	return false
 }
 
-// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
-// "product" and "vendor" variant modules return true for this function.
-// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
-// "soc_specific: true" and more vendor installed modules are included here.
-// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
-// "product_specific: true" modules are included here.
+func (mod *Module) RelativeInstallPath() string {
+	if mod.compiler != nil {
+		return mod.compiler.relativeInstallPath()
+	}
+	return ""
+}
+
 func (mod *Module) UseVndk() bool {
 	return mod.Properties.VndkVersion != ""
 }
@@ -250,6 +288,10 @@
 	return false
 }
 
+func (mod *Module) IsVndkSp() bool {
+	return false
+}
+
 func (c *Module) IsVndkPrivate() bool {
 	return false
 }
@@ -274,6 +316,14 @@
 	return false
 }
 
+func (mod *Module) HasLlndkStubs() bool {
+	return false
+}
+
+func (mod *Module) StubsVersion() string {
+	panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName()))
+}
+
 func (mod *Module) SdkVersion() string {
 	return ""
 }
@@ -362,6 +412,7 @@
 	inData() bool
 	install(ctx ModuleContext)
 	relativeInstallPath() string
+	everInstallable() bool
 
 	nativeCoverage() bool
 
@@ -423,8 +474,12 @@
 	return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
 }
 
-func (mod *Module) PreventInstall() {
-	mod.Properties.PreventInstall = true
+func (mod *Module) VndkVersion() string {
+	return mod.Properties.VndkVersion
+}
+
+func (mod *Module) PreventInstall() bool {
+	return mod.Properties.PreventInstall
 }
 
 func (mod *Module) HideFromMake() {
@@ -676,6 +731,16 @@
 	return mod.compiler != nil && mod.compiler.nativeCoverage()
 }
 
+func (mod *Module) EverInstallable() bool {
+	return mod.compiler != nil &&
+		// Check to see whether the module is actually ever installable.
+		mod.compiler.everInstallable()
+}
+
+func (mod *Module) Installable() *bool {
+	return mod.Properties.Installable
+}
+
 func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
 	if mod.cachedToolchain == nil {
 		mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
diff --git a/rust/sanitize.go b/rust/sanitize.go
index 0a53f98..3d14d51 100644
--- a/rust/sanitize.go
+++ b/rust/sanitize.go
@@ -189,6 +189,22 @@
 	}
 }
 
+func (m *Module) UbsanRuntimeNeeded() bool {
+	return false
+}
+
+func (m *Module) MinimalRuntimeNeeded() bool {
+	return false
+}
+
+func (m *Module) UbsanRuntimeDep() bool {
+	return false
+}
+
+func (m *Module) MinimalRuntimeDep() bool {
+	return false
+}
+
 // Check if the sanitizer is explicitly disabled (as opposed to nil by
 // virtue of not being set).
 func (sanitize *sanitize) isSanitizerExplicitlyDisabled(t cc.SanitizerType) bool {
diff --git a/rust/snapshot_utils.go b/rust/snapshot_utils.go
new file mode 100644
index 0000000..e0ed1f7
--- /dev/null
+++ b/rust/snapshot_utils.go
@@ -0,0 +1,54 @@
+// Copyright 2021 The Android Open Source Project
+//
+// 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 rust
+
+import (
+	"android/soong/android"
+)
+
+func (mod *Module) ExcludeFromVendorSnapshot() bool {
+	// TODO Rust does not yet support snapshotting
+	return true
+}
+
+func (mod *Module) ExcludeFromRecoverySnapshot() bool {
+	// TODO Rust does not yet support snapshotting
+	return true
+}
+
+func (mod *Module) IsSnapshotLibrary() bool {
+	// TODO Rust does not yet support snapshotting
+	return false
+}
+
+func (mod *Module) SnapshotRuntimeLibs() []string {
+	// TODO Rust does not yet support a runtime libs notion similar to CC
+	return []string{}
+}
+
+func (mod *Module) SnapshotSharedLibs() []string {
+	// TODO Rust does not yet support snapshotting
+	return []string{}
+}
+
+func (mod *Module) Symlinks() []string {
+	// TODO update this to return the list of symlinks when Rust supports defining symlinks
+	return nil
+}
+
+func (m *Module) SnapshotHeaders() android.Paths {
+	// TODO Rust does not yet support snapshotting
+	return android.Paths{}
+}