Repository: spack/spack

Issue:
add get_arch to sqlite autotools builder
Problem: the refactor of sqlite to add the autotools builder needed to move get_arch to that class.
Solution: put it there.

I tested the build locally (on ubuntu 20.04) and at least it works here. The original failure can be seen in:

https://github.com/flux-framework/spack/actions/runs/7295482304/job/19881923847

This will close #41823 


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/sqlite/package.py b/var/spack/repos/builtin/packages/sqlite/package.py
--- a/var/spack/repos/builtin/packages/sqlite/package.py
+++ b/var/spack/repos/builtin/packages/sqlite/package.py
@@ -10,12 +10,13 @@
 from spack.package import *
 
 
-class Sqlite(AutotoolsPackage):
+class Sqlite(AutotoolsPackage, NMakePackage):
     """SQLite is a C-language library that implements a small, fast,
     self-contained, high-reliability, full-featured, SQL database engine.
     """
 
     homepage = "https://www.sqlite.org"
+    tags = ["windows"]
 
     license("blessing")
 
@@ -49,20 +50,40 @@ class Sqlite(AutotoolsPackage):
     # All versions prior to 3.26.0 are vulnerable to Magellan when FTS
     # is enabled, see https://blade.tencent.com/magellan/index_en.html
 
-    variant(
-        "functions",
-        default=False,
-        when="+dynamic_extensions",
-        description="Provide mathematical and string extension functions for SQL "
-        "queries using the loadable extensions mechanism",
-    )
-    variant("fts", default=True, description="Include fts4 and fts5 support")
-    variant("column_metadata", default=True, description="Build with COLUMN_METADATA")
-    variant("dynamic_extensions", default=True, description="Support loadable extensions")
-    variant("rtree", default=True, description="Build with Rtree module")
+    # no hard readline dep on Windows + no variant support, makefile has minimal to no options
+    for plat in ["linux", "darwin", "cray", "freebsd"]:
+        variant(
+            "functions",
+            default=False,
+            description="Provide mathematical and string extension functions for SQL "
+            "queries using the loadable extensions mechanism",
+            when=f"+dynamic_extensions platform={plat}",
+        )
+        variant(
+            "fts",
+            default=True,
+            description="Include fts4 and fts5 support",
+            when=f"platform={plat}",
+        )
+        variant(
+            "column_metadata",
+            default=True,
+            description="Build with COLUMN_METADATA",
+            when=f"platform={plat}",
+        )
+        variant(
+            "dynamic_extensions",
+            default=True,
+            description="Support loadable extensions",
+            when=f"platform={plat}",
+        )
+        variant(
+            "rtree", default=True, description="Build with Rtree module", when=f"platform={plat}"
+        )
+        depends_on("readline", when=f"platform={plat}")
 
-    depends_on("readline")
     depends_on("zlib-api")
+    depends_on("tcl", when="platform=windows")
 
     # See https://blade.tencent.com/magellan/index_en.html
     conflicts("+fts", when="@:3.25")
@@ -89,6 +110,10 @@ class Sqlite(AutotoolsPackage):
     # compiler is used.
     patch("remove_overflow_builtins.patch", when="@3.17.0:3.20%intel")
 
+    patch("quote_compiler_in_makefile.patch", when="platform=windows")
+
+    build_system("autotools", "nmake")
+
     executables = ["^sqlite3$"]
 
     @classmethod
@@ -186,10 +211,34 @@ def url_for_version(self, version):
     def libs(self):
         return find_libraries("libsqlite3", root=self.prefix.lib)
 
-    def get_arch(self):
-        host_platform = spack.platforms.host()
-        return str(host_platform.target("default_target"))
+    def test_example(self):
+        """check example table dump"""
+
+        test_data_dir = self.test_suite.current_test_data_dir
+        db_filename = test_data_dir.join("packages.db")
+
+        # Ensure the database only contains one table
+        sqlite3 = which(self.prefix.bin.sqlite3)
+        out = sqlite3(db_filename, ".tables", output=str.split, error=str.split)
+        assert "packages" in out
+
+        # Ensure the database dump matches expectations, where special
+        # characters are replaced with spaces in the expected and actual
+        # output to avoid pattern errors.
+        expected = get_escaped_text_output(test_data_dir.join("dump.out"))
+        out = sqlite3(db_filename, ".dump", output=str.split, error=str.split)
+        check_outputs(expected, out)
+
+    def test_version(self):
+        """ensure version is expected"""
+        vers_str = str(self.spec.version)
+
+        sqlite3 = which(self.prefix.bin.sqlite3)
+        out = sqlite3("-version", output=str.split, error=str.split)
+        assert vers_str in out
 
+
+class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder):
     def configure_args(self):
         args = []
 
@@ -211,6 +260,10 @@ def configure_args(self):
 
         return args
 
+    def get_arch(self):
+        host_platform = spack.platforms.host()
+        return str(host_platform.target("default_target"))
+
     @run_after("install")
     def build_libsqlitefunctions(self):
         if "+functions" in self.spec:
@@ -226,28 +279,18 @@ def build_libsqlitefunctions(self):
             )
             install(libraryname, self.prefix.lib)
 
-    def test_example(self):
-        """check example table dump"""
-
-        test_data_dir = self.test_suite.current_test_data_dir
-        db_filename = test_data_dir.join("packages.db")
-
-        # Ensure the database only contains one table
-        sqlite3 = which(self.prefix.bin.sqlite3)
-        out = sqlite3(db_filename, ".tables", output=str.split, error=str.split)
-        assert "packages" in out
-
-        # Ensure the database dump matches expectations, where special
-        # characters are replaced with spaces in the expected and actual
-        # output to avoid pattern errors.
-        expected = get_escaped_text_output(test_data_dir.join("dump.out"))
-        out = sqlite3(db_filename, ".dump", output=str.split, error=str.split)
-        check_outputs(expected, out)
 
-    def test_version(self):
-        """ensure version is expected"""
-        vers_str = str(self.spec.version)
-
-        sqlite3 = which(self.prefix.bin.sqlite3)
-        out = sqlite3("-version", output=str.split, error=str.split)
-        assert vers_str in out
+class NMakeBuilder(spack.build_systems.nmake.NMakeBuilder):
+    @property
+    def makefile_name(self):
+        return "Makefile.msc"
+
+    def install(self, pkg, spec, prefix):
+        with working_dir(self.build_directory):
+            mkdirp(prefix.include)
+            mkdirp(prefix.lib)
+            mkdirp(prefix.bin)
+            install(f"{self.build_directory}\\*.exe", prefix.bin)
+            install(f"{self.build_directory}\\*.dll", prefix.bin)
+            install(f"{self.build_directory}\\*.lib", prefix.lib)
+            install(f"{self.build_directory}\\*.h", prefix.include)


Test patch: