Title: [282742] trunk/Tools
Revision
282742
Author
commit-qu...@webkit.org
Date
2021-09-20 01:08:49 -0700 (Mon, 20 Sep 2021)

Log Message

[Flatpak SDK] Move toolchains to UserFlatpak and improve SDK upgrades
https://bugs.webkit.org/show_bug.cgi?id=230201

Patch by Philippe Normand <pnorm...@igalia.com> on 2021-09-20
Reviewed by Carlos Alberto Lopez Perez.

As toolchain archives depend on the SDK runtime, it makes sense to move them in the
corresponding UserFlatpak folder, so that when SDK is upgraded, stale toolchains are
removed. The SDK upgrade is also now handling cached SSCache authentication tokens and
propagating those in the newly installed SDK. Finally, SDK upgrades will now also clear
CMake cache files on WebKit builds, so that hopefully, existing build directories no longer
need to be manually removed.

* flatpak/flatpakutils.py:
(WebkitFlatpak.__init__):
(WebkitFlatpak.clean_args):
(WebkitFlatpak.setup_gstbuild):
(WebkitFlatpak.run_in_sandbox):
(WebkitFlatpak.main):
(WebkitFlatpak.acquire_sccache_auth_token_from_config_file):
(WebkitFlatpak.save_config):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (282741 => 282742)


--- trunk/Tools/ChangeLog	2021-09-20 01:15:37 UTC (rev 282741)
+++ trunk/Tools/ChangeLog	2021-09-20 08:08:49 UTC (rev 282742)
@@ -1,3 +1,26 @@
+2021-09-20  Philippe Normand  <pnorm...@igalia.com>
+
+        [Flatpak SDK] Move toolchains to UserFlatpak and improve SDK upgrades
+        https://bugs.webkit.org/show_bug.cgi?id=230201
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        As toolchain archives depend on the SDK runtime, it makes sense to move them in the
+        corresponding UserFlatpak folder, so that when SDK is upgraded, stale toolchains are
+        removed. The SDK upgrade is also now handling cached SSCache authentication tokens and
+        propagating those in the newly installed SDK. Finally, SDK upgrades will now also clear
+        CMake cache files on WebKit builds, so that hopefully, existing build directories no longer
+        need to be manually removed.
+
+        * flatpak/flatpakutils.py:
+        (WebkitFlatpak.__init__):
+        (WebkitFlatpak.clean_args):
+        (WebkitFlatpak.setup_gstbuild):
+        (WebkitFlatpak.run_in_sandbox):
+        (WebkitFlatpak.main):
+        (WebkitFlatpak.acquire_sccache_auth_token_from_config_file):
+        (WebkitFlatpak.save_config):
+
 2021-09-17  Chris Dumez  <cdu...@apple.com>
 
         [ macOS Release ] TestWebKitAPI.NetworkProcess.BroadcastChannelCrashRecovery is flaky timing out

Modified: trunk/Tools/flatpak/flatpakutils.py (282741 => 282742)


--- trunk/Tools/flatpak/flatpakutils.py	2021-09-20 01:15:37 UTC (rev 282741)
+++ trunk/Tools/flatpak/flatpakutils.py	2021-09-20 08:08:49 UTC (rev 282742)
@@ -508,6 +508,8 @@
         # Where the source folder is mounted inside the sandbox.
         self.sandbox_source_root = "/app/webkit"
 
+        self.base_build_dir = 'WebKitBuild'
+
         self.build_gst = False
 
         self.sdk_branch = "0.3"
@@ -566,20 +568,19 @@
         if self.gdb is None and '--gdb' in sys.argv:
             self.gdb = True
 
-        base_build_dir = 'WebKitBuild'
-
         # This path doesn't take $WEBKIT_OUTPUTDIR in account because the standalone toolchains
         # paths depend on it and those are also hard-coded in the generated sccache config.
-        self.build_root = os.path.join(self.source_root, base_build_dir)
+        self.default_build_root = os.path.join(self.source_root, self.base_build_dir)
 
         self.config_file = os.path.join(self.flatpak_build_path, 'webkit_flatpak_config.json')
         self.sccache_config_file = os.path.join(self.flatpak_build_path, 'sccache.toml')
 
         build_root = os.environ.get("WEBKIT_OUTPUTDIR", self.source_root)
-        self.build_path = os.path.join(build_root, base_build_dir, self.platform, self.build_type)
+        self.build_root = os.path.join(build_root, self.base_build_dir)
+        self.build_path = os.path.join(self.build_root, self.platform, self.build_type)
         _log.debug("Building %s port in %s" % (self.platform, self.build_path))
 
-        self.toolchains_directory = os.path.join(self.build_root, "Toolchains")
+        self.toolchains_directory = os.path.join(self.flatpak_build_path, "Toolchains")
         if not os.path.isdir(self.toolchains_directory):
             os.makedirs(self.toolchains_directory)
 
@@ -638,8 +639,8 @@
         if not os.path.exists(os.path.join(gst_dir, 'gst-env.py')):
             raise RuntimeError('GST_BUILD_PATH set to %s but it doesn\'t seem to be a valid `gst-build` checkout.' % gst_dir)
 
-        gst_builddir = os.path.join(self.source_root, "WebKitBuild", 'gst-build')
-        if not os.path.exists(os.path.join(self.build_root, 'gst-build', 'build.ninja')):
+        gst_builddir = os.path.join(self.source_root, self.base_build_dir, 'gst-build')
+        if not os.path.exists(os.path.join(self.default_build_root, 'gst-build', 'build.ninja')):
             if not building:
                 raise RuntimeError('Trying to enter gst-build env from %s but it is not built, make sure to rebuild webkit.' % gst_dir)
 
@@ -721,7 +722,7 @@
         if not isinstance(args, list):
             args = list(args)
 
-        sandbox_build_path = os.path.join(self.sandbox_source_root, "WebKitBuild", self.build_type)
+        sandbox_build_path = os.path.join(self.sandbox_source_root, self.base_build_dir, self.build_type)
         sandbox_environment = {
             "TEST_RUNNER_INJECTED_BUNDLE_FILENAME": os.path.join(sandbox_build_path, "lib/libTestRunnerInjectedBundle.so"),
             "PATH": "/usr/lib/sdk/llvm11/bin:/usr/bin:/usr/lib/sdk/rust-stable/bin/",
@@ -886,9 +887,11 @@
             except KeyError:
                 Console.error_message("Toolchains configuration not found. Please run webkit-flatpak -r")
                 return 1
+            else:
+                toolchain_path = self.host_path_to_sandbox_path(toolchain_path)
             if "ICECC_VERSION_APPEND" in os.environ:
                 toolchain_path += ","
-                toolchain_path += os.environ["ICECC_VERSION_APPEND"]
+                toolchain_path += self.host_path_to_sandbox_path(os.environ["ICECC_VERSION_APPEND"])
             native_toolchain = toolchain_path.split(",")[0]
             if not os.path.isfile(native_toolchain):
                 Console.error_message("%s is not a valid IceCC toolchain. Please run webkit-flatpak -r", native_toolchain)
@@ -991,8 +994,21 @@
                 if package.name.startswith("org.webkit") \
                    and self.repos.is_package_installed(package.name) \
                    and not self.repos.is_package_installed(package.name, branch=self.sdk_branch):
+
+                    # Cache sccache auth token before removing UserFlatpak.
+                    self.acquire_sccache_auth_token_from_config_file()
+
                     Console.message("New SDK version available, removing local UserFlatpak directory before switching to new version")
                     shutil.rmtree(self.flatpak_build_path)
+
+                    Console.message("Forcing next WebKit build to re-run CMake")
+                    for platform in ('GTK', 'WPE'):
+                        for build_type in ('Release', 'Debug'):
+                            cache_path = os.path.join(self.build_root, platform, build_type, 'CMakeCache.txt')
+                            if os.path.isfile(cache_path):
+                                Console.message("Removing %s", cache_path)
+                                os.remove(cache_path)
+
                     self._reset_repository()
                     break
 
@@ -1006,6 +1022,17 @@
 
         result = self.setup_dev_env()
         if regenerate_toolchains:
+
+            # Toolchains used to be stored in WebKitBuild/Toolchains. Remove this path if found, to save
+            # up disk space.
+            old_toolchains_path = os.path.join(self.default_build_root, "Toolchains")
+            if os.path.isdir(old_toolchains_path):
+                Console.message("Purging obsolete toolchains")
+                shutil.rmtree(old_toolchains_path)
+
+            if not os.path.isdir(self.toolchains_directory):
+                os.makedirs(self.toolchains_directory)
+
             Console.message("Updating icecc/sccache standalone toolchain archives")
             self.icc_version = {}
             gcc_archive, toolchains = self.pack_toolchain(("gcc", "g++"), {"/usr/bin/c++": "g++",
@@ -1033,11 +1060,7 @@
     def has_environment(self):
         return os.path.exists(self.flatpak_build_path)
 
-    def save_config(self, toolchains):
-        with open(self.config_file, 'w') as config:
-            json_config = {'icecc_version': self.icc_version}
-            json.dump(json_config, config)
-
+    def acquire_sccache_auth_token_from_config_file(self):
         if os.path.isfile(self.sccache_config_file) and not self.sccache_token:
             Console.message("Reusing sccache auth token from old configuration file")
             with open(self.sccache_config_file) as config:
@@ -1044,6 +1067,13 @@
                 sccache_config = toml.load(config)
                 self.sccache_token = sccache_config['dist']['auth']['token']
 
+    def save_config(self, toolchains):
+        with open(self.config_file, 'w') as config:
+            json_config = {'icecc_version': self.icc_version}
+            json.dump(json_config, config)
+
+        self.acquire_sccache_auth_token_from_config_file()
+
         if not self.sccache_token:
             Console.message("No authentication token provided. Re-run this with the -t option if an sccache token was provided to you. Skipping sccache configuration for now.")
             return
@@ -1091,7 +1121,8 @@
             relative_filename = "webkit-sdk-{name}-{filename}".format(name=compilers[0], filename=icc_version_filename.decode())
             archive_filename = os.path.join(self.toolchains_directory, relative_filename)
             os.rename(icc_version_filename, archive_filename)
-            self.icc_version[compilers[0]] = archive_filename
+            archive_sandbox_path = self.host_path_to_sandbox_path(archive_filename)
+            self.icc_version[compilers[0]] = archive_sandbox_path
             Console.message("Created %s self-contained toolchain archive", archive_filename)
 
             sccache_toolchains = []
@@ -1098,7 +1129,7 @@
             for (compiler_executable, archive_compiler_executable) in path_mapping.items():
                 item = {'type': 'path_override',
                         'compiler_executable': compiler_executable,
-                        'archive': archive_filename,
+                        'archive': archive_sandbox_path,
                         'archive_compiler_executable': compiler_mapping[archive_compiler_executable]}
                 sccache_toolchains.append(item)
             return (relative_filename, sccache_toolchains)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to