]> git.ipfire.org Git - pbs.git/commitdiff
packages: Implement sending debuginfo
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2023 15:02:23 +0000 (15:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 6 Oct 2023 15:02:23 +0000 (15:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/packages.py
src/web/__init__.py
src/web/debuginfo.py [new file with mode: 0644]

index 88052273578b99d69f805d200cddf3aa1a929ac4..1d506fbcbe05ae2c65235fdbab4b3f84710ab3ea 100644 (file)
@@ -129,6 +129,7 @@ web_PYTHON = \
        src/web/bugs.py \
        src/web/builders.py \
        src/web/builds.py \
+       src/web/debuginfo.py \
        src/web/distributions.py \
        src/web/errors.py \
        src/web/events.py \
index 4c2d10c821d318c7618aa9276fbc7249fb9fba2c..d0d714081a1575a498392d57c1c13149212edf89 100644 (file)
@@ -78,6 +78,19 @@ class Packages(base.Object):
                        """, uuid,
                )
 
+       async def get_by_buildid(self, buildid):
+               """
+                       Fetches the debug information for the given BuildID
+               """
+               # Make the path
+               path = buildid_to_path(buildid)
+
+               # Search for the package containing this file
+               for package in self.search_by_filename(path, limit=1):
+                       log.debug("Found debuginfo for %s in %s" % (buildid, package))
+
+                       return package
+
        async def create(self, upload, distro=None, commit=None):
                """
                        Creates a new package from an uploaded file
@@ -620,6 +633,11 @@ class Package(base.DataObject):
                        """, self.id, path,
                )
 
+       def get_debuginfo(self, buildid):
+               path = buildid_to_path(buildid)
+
+               return self.get_file(path)
+
        # Open
 
        async def open(self):
@@ -766,3 +784,10 @@ class File(base.Object):
 
                # Read everything in a separate thread
                return await asyncio.to_thread(f.readall)
+
+
+def buildid_to_path(buildid):
+       """
+               Returns the path where we expect to find the BuildID
+       """
+       return "/usr/lib/debug/.build-id/%s/%s.debug" % (buildid[0:2], buildid[2:])
index 7ea0eab58993d3d7152cf7ff17663f8bbfbe32dd..daedd8bcc3014f29d2e2dec9180f3c6beaa61dad 100644 (file)
@@ -16,6 +16,7 @@ from . import auth
 from . import bugs
 from . import builders
 from . import builds
+from . import debuginfo
 from . import distributions
 from . import errors
 from . import events
@@ -246,6 +247,9 @@ class Application(tornado.web.Application):
                        # Log
                        (r"/log", handlers.LogHandler),
 
+                       # Debuginfo
+                       (r"/buildid/([0-9a-f]{40})/debuginfo", debuginfo.DebugInfoHandler),
+
                        # Repositories
                        (r"/api/v1/repos/([\w\d\-]+)", repos.APIv1IndexHandler),
                        (r"/api/v1/repos/([\w\d\-]+)/([\w\d\-]+)", repos.APIv1ShowHandler),
diff --git a/src/web/debuginfo.py b/src/web/debuginfo.py
new file mode 100644 (file)
index 0000000..a3b1474
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+import tornado.web
+
+from . import base
+
+class DebugInfoHandler(base.BaseHandler):
+       async def get(self, buildid):
+               package = await self.backend.packages.get_by_buildid(buildid)
+               if not package:
+                       raise tornado.web.HTTPError(404, "Could not find package providing BuildID %s" % buildid)
+
+               # Fetch the debuginfo
+               file = package.get_debuginfo(buildid)
+               if not file:
+                       raise tornado.web.HTTPError(404, "Could not find debuginfo in %s" % package)
+
+               # Send the payload
+               await file.sendfile(self)