summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nelson Li <nelsonli@google.com> 2024-09-27 09:06:36 +0000
committer Nelson Li <nelsonli@google.com> 2024-09-27 09:06:36 +0000
commitfb09145a9fead98b9fa4eda2dad54b7fd3d6df4e (patch)
tree4774533f200e8fec11344c5f352784e68581ca10
parent199e86eca84e287d28e2970b72219710afa6ea03 (diff)
Add install_symlink_host Soong module type
The `install_symlink_host` module type allows Soong to create symbolic links on the host side. This functionality addresses the issue where a `cc_binary` with `symlink_preferred_arch: true` cannot be used as a tool in a `cc_genrule`. The solution involves setting `symlink_preferred_arch` to `false` for the `tool` and then using `install_symlink_host` to explicitly create the originally intended symbolic link. Bug: 342330305 Test: Unit test and CI Change-Id: I850060be25bdea3aa37febaf499a30c18cfd181b
-rw-r--r--etc/install_symlink.go9
-rw-r--r--etc/install_symlink_test.go30
2 files changed, 39 insertions, 0 deletions
diff --git a/etc/install_symlink.go b/etc/install_symlink.go
index 2182b8669..aa33445e1 100644
--- a/etc/install_symlink.go
+++ b/etc/install_symlink.go
@@ -26,6 +26,7 @@ func init() {
func RegisterInstallSymlinkBuildComponents(ctx android.RegistrationContext) {
ctx.RegisterModuleType("install_symlink", InstallSymlinkFactory)
+ ctx.RegisterModuleType("install_symlink_host", InstallSymlinkHostFactory)
}
// install_symlink can be used to install an symlink with an arbitrary target to an arbitrary path
@@ -37,6 +38,14 @@ func InstallSymlinkFactory() android.Module {
return module
}
+// install_symlink can be used to install an symlink to an arbitrary path on the host.
+func InstallSymlinkHostFactory() android.Module {
+ module := &InstallSymlink{}
+ module.AddProperties(&module.properties)
+ android.InitAndroidMultiTargetsArchModule(module, android.HostSupported, android.MultilibCommon)
+ return module
+}
+
type InstallSymlinkProperties struct {
// Where to install this symlink, relative to the partition it's installed on.
// Which partition it's installed on can be controlled by the vendor, system_ext, ramdisk, etc.
diff --git a/etc/install_symlink_test.go b/etc/install_symlink_test.go
index d7165e5de..2662868c6 100644
--- a/etc/install_symlink_test.go
+++ b/etc/install_symlink_test.go
@@ -133,3 +133,33 @@ func TestErrorOnInstalledPathStartingWithSlash(t *testing.T) {
}
`)
}
+
+func TestInstallSymlinkHostBasic(t *testing.T) {
+ result := prepareForInstallSymlinkTest.RunTestWithBp(t, `
+ install_symlink_host {
+ name: "foo",
+ installed_location: "bin/foo",
+ symlink_target: "folder/foo-realpath",
+ }
+ `)
+
+ foo_variants := result.ModuleVariantsForTests("foo")
+ if len(foo_variants) != 1 {
+ t.Fatalf("expected 1 variant, got %#v", foo_variants)
+ }
+
+ foo := result.ModuleForTests("foo", "linux_glibc_common").Module()
+ androidMkEntries := android.AndroidMkEntriesForTest(t, result.TestContext, foo)
+ if len(androidMkEntries) != 1 {
+ t.Fatalf("expected 1 androidmkentry, got %d", len(androidMkEntries))
+ }
+
+ symlinks := androidMkEntries[0].EntryMap["LOCAL_SOONG_INSTALL_SYMLINKS"]
+ if len(symlinks) != 1 {
+ t.Fatalf("Expected 1 symlink, got %d", len(symlinks))
+ }
+
+ if !strings.HasSuffix(symlinks[0], "host/linux-x86/bin/foo") {
+ t.Fatalf("Expected symlink install path to end in ost/linux-x86/bin/foo, got: %s", symlinks[0])
+ }
+}