From nobody Sun Oct 5 17:34:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519933903219848.1941670045411; Thu, 1 Mar 2018 11:51:43 -0800 (PST) Received: from localhost ([::1]:58975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erUEk-0006u1-5H for importer@patchew.org; Thu, 01 Mar 2018 14:51:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erU6p-0000pk-Cs for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erU6o-0007Xl-Dh for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1erU6o-0007WV-5D for qemu-devel@nongnu.org; Thu, 01 Mar 2018 14:43:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 569487ECE8; Thu, 1 Mar 2018 19:43:17 +0000 (UTC) Received: from red.redhat.com (ovpn-122-122.rdu2.redhat.com [10.10.122.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF2CE6046B; Thu, 1 Mar 2018 19:43:16 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 13:42:26 -0600 Message-Id: <20180301194245.29854-12-eblake@redhat.com> In-Reply-To: <20180301194245.29854-1-eblake@redhat.com> References: <20180301194245.29854-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 01 Mar 2018 19:43:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/30] qapi: Improve include file name reporting in error messages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster Error messages print absolute file names of included files even if the user gave a relative one on the command line: $ PYTHONPATH=3Dscripts python -B tests/qapi-schema/test-qapi.py tests/q= api-schema/include-cycle.json In file included from tests/qapi-schema/include-cycle.json:1: In file included from /work/armbru/qemu/tests/qapi-schema/include-cycle= -b.json:1: /work/armbru/qemu/tests/qapi-schema/include-cycle-c.json:1: Inclusion l= oop for include-cycle.json Improve this to In file included from tests/qapi-schema/include-cycle.json:1: In file included from tests/qapi-schema/include-cycle-b.json:1: tests/qapi-schema/include-cycle-c.json:1: Inclusion loop for include-cy= cle.json The error message when an include file can't be opened prints the include directive's file name, which is relative to the including file. Change this to print the file name relative to the working directory. Visible in tests/qapi-schema/include-no-file.err. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20180211093607.27351-12-armbru@redhat.com> Reviewed-by: Michael Roth Signed-off-by: Eric Blake --- scripts/qapi/common.py | 12 ++++++------ tests/qapi-schema/include-no-file.err | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 47673928dcc..bfa9bfec01d 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -259,9 +259,8 @@ class QAPIDoc(object): class QAPISchemaParser(object): def __init__(self, fp, previously_included=3D[], incl_info=3DNone): - abs_fname =3D os.path.abspath(fp.name) self.fname =3D fp.name - previously_included.append(abs_fname) + previously_included.append(os.path.abspath(fp.name)) self.incl_info =3D incl_info self.src =3D fp.read() if self.src =3D=3D '' or self.src[-1] !=3D '\n': @@ -292,7 +291,7 @@ class QAPISchemaParser(object): if not isinstance(include, str): raise QAPISemError(info, "Value of 'include' must be a strin= g") - self._include(include, info, os.path.dirname(abs_fname), + self._include(include, info, os.path.dirname(self.fname), previously_included) elif "pragma" in expr: self.reject_expr_doc(cur_doc) @@ -325,7 +324,8 @@ class QAPISchemaParser(object): % doc.symbol) def _include(self, include, info, base_dir, previously_included): - incl_abs_fname =3D os.path.join(base_dir, include) + incl_fname =3D os.path.join(base_dir, include) + incl_abs_fname =3D os.path.abspath(incl_fname) # catch inclusion cycle inf =3D info while inf: @@ -337,9 +337,9 @@ class QAPISchemaParser(object): if incl_abs_fname in previously_included: return try: - fobj =3D open(incl_abs_fname, 'r') + fobj =3D open(incl_fname, 'r') except IOError as e: - raise QAPISemError(info, '%s: %s' % (e.strerror, include)) + raise QAPISemError(info, '%s: %s' % (e.strerror, incl_fname)) exprs_include =3D QAPISchemaParser(fobj, previously_included, info) self.exprs.extend(exprs_include.exprs) self.docs.extend(exprs_include.docs) diff --git a/tests/qapi-schema/include-no-file.err b/tests/qapi-schema/incl= ude-no-file.err index d5b9b22d85d..e42bcf4bc1a 100644 --- a/tests/qapi-schema/include-no-file.err +++ b/tests/qapi-schema/include-no-file.err @@ -1 +1 @@ -tests/qapi-schema/include-no-file.json:1: No such file or directory: inclu= de-no-file-sub.json +tests/qapi-schema/include-no-file.json:1: No such file or directory: tests= /qapi-schema/include-no-file-sub.json --=20 2.14.3