From nobody Fri Sep 20 22:15:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632394117; cv=none; d=zohomail.com; s=zohoarc; b=K4DCe5ES2Jew0KgPtINROMqw1ojGw/GQktiBx75KMScSI4bY1YNt3EXEC96xcRIt9QgOX85IoHzNImNihBEUCuIak1IyFPrTp148mDmKoSHn+WyKFt6R7rCAvxqpG1jiBz49hYbM5EBI05UtiYlZ1dTDi97mFE2Ko2qosxVmuJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632394117; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=kIar+mxw5QUmMYPH9Y7jjwFWrkoO0mw6aGVf0qNwuAA=; b=G8syyqRN5Yya6oDlv6Swycj/ugPtcWxaITxbBYSo3/zy41d6C3/3wR8AMA4jsGSpEKeZJck3kpV9zOaR6SSzo8rRVFGOFm4mU3aJgtLsvgbz8lzlODG9iP8pfygvPpHs2m0oCkr9Tz7gx93MpFwek+HARsXIUIv5B9q1Qg8wIXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632394117750625.5992621511465; Thu, 23 Sep 2021 03:48:37 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-seYMAqY2PSePXf11asdpQw-1; Thu, 23 Sep 2021 06:48:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEE64835DF7; Thu, 23 Sep 2021 10:48:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9722679450; Thu, 23 Sep 2021 10:48:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 218B34E58E; Thu, 23 Sep 2021 10:48:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18NAmFw5006253 for ; Thu, 23 Sep 2021 06:48:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 65F705F707; Thu, 23 Sep 2021 10:48:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.194.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 568E17621B; Thu, 23 Sep 2021 10:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632394116; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kIar+mxw5QUmMYPH9Y7jjwFWrkoO0mw6aGVf0qNwuAA=; b=A2Ccd0su5AtbT92tlsacDZeBNtXGJAWeBDydP9V1F14gY7fiGa7cmGZ9GH8aPuZY58934c fOdizpOLKpi3y78MJal1JnwGQHfice9vPwYv+eXhu2/AQheRXEwgVZlz8AHb3wmsLoOSZM pTzpMh8ryD4nM5iRVvCFFYkjvgg7J/U= X-MC-Unique: seYMAqY2PSePXf11asdpQw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH] scripts: include function versions in API definition Date: Thu, 23 Sep 2021 11:47:58 +0100 Message-Id: <20210923104758.2691774-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Victor Toso X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632394119087100001 In order to auto-generate more of the language binding code, it is desirable to know what libvirt version an API was introduced in. We can extract this information from the .syms files and expose it in the API description eg instead of we now have This will benefit this proposal: https://gitlab.com/libvirt/libvirt-go-module/-/merge_requests/7 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik Tested-by: Victor Toso --- scripts/apibuild.py | 68 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/scripts/apibuild.py b/scripts/apibuild.py index 9b29466e1d..bdd3077c48 100755 --- a/scripts/apibuild.py +++ b/scripts/apibuild.py @@ -2030,8 +2030,9 @@ class CParser: =20 class docBuilder: """A documentation builder""" - def __init__(self, name, path=3D'.', directories=3D['.'], includes=3D[= ]): + def __init__(self, name, syms, path=3D'.', directories=3D['.'], includ= es=3D[]): self.name =3D name + self.syms =3D syms self.path =3D path self.directories =3D directories if name =3D=3D "libvirt": @@ -2044,6 +2045,7 @@ class docBuilder: self.includes =3D includes + list(admin_included_files.keys()) self.modules =3D {} self.headers =3D {} + self.versions =3D {} self.idx =3D index() self.xref =3D {} self.index =3D {} @@ -2114,6 +2116,44 @@ class docBuilder: self.modules[module] =3D idx self.idx.merge_public(idx) =20 + def scanVersions(self): + prefix =3D self.name.upper().replace("-", "_") + "_" + + version =3D None + prevversion =3D None + with open(self.syms, "r") as syms: + while True: + line =3D syms.readline() + if not line: + break + line =3D line.strip() + if line.startswith("#"): + continue + if line =3D=3D "": + continue + + if line.startswith(prefix) and line.endswith(" {"): + version =3D line[len(prefix):-2] + elif line =3D=3D "global:": + continue + elif line =3D=3D "local:": + continue + elif line.startswith("}"): + if prevversion is None: + if line !=3D "};": + raise Exception("Unexpected closing version") + else: + if line !=3D ("} %s%s;" % (prefix, prevversion)): + raise Exception("Unexpected end of version '%s= ': %s'" % (line, "} " + prefix + version)) + + prevversion =3D version + version =3D None + elif line.endswith(";") and version is not None: + func =3D line[:-1] + self.versions[func] =3D version + else: + raise Exception("Unexpected line in syms file: %s" % l= ine) + def scan(self): for directory in self.directories: files =3D glob.glob(directory + "/*.c") @@ -2136,6 +2176,7 @@ class docBuilder: self.headers[file] =3D None self.scanHeaders() self.scanModules() + self.scanVersions() =20 def modulename_file(self, file): module =3D os.path.basename(file) @@ -2275,9 +2316,17 @@ class docBuilder: print("=3D>", id) =20 # NB: this is consumed by a regex in 'getAPIFilenames' in hvsuppor= t.pl - output.write(" <%s name=3D'%s' file=3D'%s' module=3D'%s'>\n" % = (id.type, - name, self.modulename_file(id.header), - self.modulename_file(id.module))) + if id.type =3D=3D "function": + ver =3D self.versions[name] + if ver is None: + raise Exception("Missing version for '%s'" % name) + output.write(" \n" % ( + name, self.modulename_file(id.header), + self.modulename_file(id.module), self.versions[name])) + else: + output.write(" \n" % ( + name, self.modulename_file(id.header), + self.modulename_file(id.module))) # # Processing of conditionals modified by Bill 1/1/05 # @@ -2406,9 +2455,16 @@ class app: print(msg) =20 def rebuild(self, name, srcdir, builddir): - if name not in ["libvirt", "libvirt-qemu", "libvirt-lxc", "libvirt= -admin"]: + syms =3D { + "libvirt": srcdir + "/../src/libvirt_public.syms", + "libvirt-qemu": srcdir + "/../src/libvirt_qemu.syms", + "libvirt-lxc": srcdir + "/../src/libvirt_lxc.syms", + "libvirt-admin": srcdir + "/../src/admin/libvirt_admin_public.= syms", + } + if name not in syms: self.warning("rebuild() failed, unknown module %s" % name) return None + builder =3D None if glob.glob(srcdir + "/../src/libvirt.c") !=3D []: if not quiet: @@ -2418,7 +2474,7 @@ class app: srcdir + "/../src/util", srcdir + "/../include/libvirt", builddir + "/../include/libvirt"] - builder =3D docBuilder(name, builddir, dirs, []) + builder =3D docBuilder(name, syms[name], builddir, dirs, []) else: self.warning("rebuild() failed, unable to guess the module") return None --=20 2.31.1