From patchwork Sun Jul 2 16:32:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 115106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp49172vqx; Sun, 2 Jul 2023 09:42:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75aJJBK2dF0yucOPyf/B6FTRs+ZQHxV4rnKHWJKmzMjdvSwMcgaXKZLqAnaih2sA9CeruI X-Received: by 2002:a17:906:16c4:b0:989:1a52:72b5 with SMTP id t4-20020a17090616c400b009891a5272b5mr5569205ejd.45.1688316141219; Sun, 02 Jul 2023 09:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688316141; cv=none; d=google.com; s=arc-20160816; b=Yun+plX74yunW9TkRtUL/6tHBaFnoifM1Znho/qsVgF47Ce57TfgJMAf3KuJQgTLK2 6uQMe0dlrnjqelCil/GqP8VMZnM3GTiwE6ooqH5rQBzUkuwlIeKkDr2qqSCxoo9oIRqa Vs+XNTHHP29bKVIzbYNgzs5Wc4L1E6+TPhzsoE4lh5pdyaCjbqZVi9k8IKcSVYGoClYQ guMc8IkKzmdad5QI3OfeeKzl8vRXuFdGjXPxjxFnTPuj3UqWB3OF3ybTn4vcxaUQpG1g 0OIRX3A20pnXeOYOWUmwjtDAXnrmlL95im6R+svXYsFYYfdsE5pDisExcu07EOhRM7z3 DYUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=GkV3TqKHe0jLjBrlWR7jIyBCdtYFxPyc+yHD+8BXsuI=; fh=WmOQlEQshjW1IyckmJV5Nh43dgdMAM2UcuXDxiXBGYo=; b=z0cSJlGG1e9jT3g5PHB1AbhO2QLNHZ6ByUKXmKIvUwprl0AXSYWws9j3gI4jLVBZbI Vc/+Sgf13K4YFsZaXhipcsHgrdZQV/ncuLI1n7JVuKTnqrYgifv6jd9ceEYJ3BpKkmbg Swsw9kfJZSJHLOBqD7+yLLWDrG1WyNRwLAtdAqCfxJxAn6Qy+b+Ixqb5mpMigKincl3p SQHMUEp3nah5y3lBw59PkHLeHavcUzGydChpqTopbKCWuIDQkGxxQOj1/kMHuv6tmEy1 ExMO4P4yRxufv76NCdKyG47MUTlF3bi/dMzM/ZdyxNXKrHpf4wZTz0iGLUbqZCQPpJeZ WVvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NMG+QEKt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id pg28-20020a170907205c00b0099316735a60si1953107ejb.1042.2023.07.02.09.42.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NMG+QEKt; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDD25392AC09 for ; Sun, 2 Jul 2023 16:36:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDD25392AC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688315783; bh=GkV3TqKHe0jLjBrlWR7jIyBCdtYFxPyc+yHD+8BXsuI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NMG+QEKth9vopPFNZ2kJRvX8o01WKlCQ4mzyAfcbnsMkjnAyZKq8Emb4r+LKqxajQ 3fPQoT1mk1SYtwaRglpHwyBibSK+1w06kMsNyZ1VWQacl3dRHV4SKnkXOqZLRE2xW7 fXxcBaji3WrvggrgYRezWK+nnGtVgMxe+eoNU/10= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by sourceware.org (Postfix) with ESMTPS id 659C53858434 for ; Sun, 2 Jul 2023 16:32:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 659C53858434 Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-40292285362so29493191cf.3 for ; Sun, 02 Jul 2023 09:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688315542; x=1690907542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GkV3TqKHe0jLjBrlWR7jIyBCdtYFxPyc+yHD+8BXsuI=; b=LFXZnvIxkJfQ562VJVtgH9lXyF1h1N4uL7i3GT1KcpE89StEUeWl5okd8TR343nAqe SQLZjR0z+ii4kL/F8PPaUS6qESqrrUDhIAsj9A+M+dz7sBIqscJL28fkeKXAVEmSncEn 6jB2AFVN92+eyVht0p8Yb34Bi2xJTUxV4klCDnIr9j3cQWaUPeqZJWALbKgzujCLDtn4 KS/j03WdoJikUZW3t2lUSA1ahCthWVl10NS/r3JCTMsh5feLPda/otp16k+NQB7WUvmK WjY24wQGLJM7YBhyjpExTWAlS2qquQymqKBD85zBs0/1H+yjSkAvRJOUZ9kVyJFxGm60 kINQ== X-Gm-Message-State: AC+VfDw4LNS5g07x5Zkbcnt/OMcf6K5Zw33I/OmUf3cLrDqh0zxGjKZS jPHg9iR7KsfUBD/I0i171srmVVw3u1ApPW0mYSyzVw== X-Received: by 2002:a05:622a:1442:b0:3fd:dd80:52a6 with SMTP id v2-20020a05622a144200b003fddd8052a6mr10411915qtx.16.1688315541288; Sun, 02 Jul 2023 09:32:21 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id l27-20020ac8459b000000b003e4dab0776esm2742272qtn.40.2023.07.02.09.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:32:20 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v7 2/4] p1689r5: initial support Date: Sun, 2 Jul 2023 12:32:09 -0400 Message-Id: <20230702163211.3396210-3-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230702163211.3396210-1-ben.boeckel@kitware.com> References: <20230702163211.3396210-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770327785936416614?= X-GMAIL-MSGID: =?utf-8?q?1770327785936416614?= This patch implements support for [P1689R5][] to communicate to a build system the C++20 module dependencies to build systems so that they may build `.gcm` files in the proper order. Support is communicated through the following three new flags: - `-fdeps-format=` specifies the format for the output. Currently named `p1689r5`. - `-fdeps-file=` specifies the path to the file to write the format to. - `-fdeps-target=` specifies the `.o` that will be written for the TU that is scanned. This is required so that the build system can correlate the dependency output with the actual compilation that will occur. CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0) using an experimental feature selection (to allow for future usage evolution without committing to how it works today). While it remains experimental, docs may be found in CMake's documentation for experimental features. Future work may include using this format for Fortran module dependencies as well, however this is still pending work. [P1689R5]: https://isocpp.org/files/papers/P1689R5.html [cmake-experimental]: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst TODO: - header-unit information fields Header units (including the standard library headers) are 100% unsupported right now because the `-E` mechanism wants to import their BMIs. A new mode (i.e., something more workable than existing `-E` behavior) that mocks up header units as if they were imported purely from their path and content would be required. - non-utf8 paths The current standard says that paths that are not unambiguously represented using UTF-8 are not supported (because these cases are rare and the extra complication is not worth it at this time). Future versions of the format might have ways of encoding non-UTF-8 paths. For now, this patch just doesn't support non-UTF-8 paths (ignoring the "unambiguously representable in UTF-8" case). - figure out why junk gets placed at the end of the file Sometimes it seems like the file gets a lot of `NUL` bytes appended to it. It happens rarely and seems to be the result of some `ftruncate`-style call which results in extra padding in the contents. Noting it here as an observation at least. libcpp/ * include/cpplib.h: Add cpp_fdeps_format enum. (cpp_options): Add fdeps_format field (cpp_finish): Add structured dependency fdeps_stream parameter. * include/mkdeps.h (deps_add_module_target): Add flag for whether a module is exported or not. (fdeps_add_target): Add function. (deps_write_p1689r5): Add function. * init.cc (cpp_finish): Add new preprocessor parameter used for C++ module tracking. * mkdeps.cc (mkdeps): Implement P1689R5 output. gcc/ * doc/invoke.texi: Document -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. * gcc.cc: add defaults for -fdeps-target= and -fdeps-file= when only -fdeps-format= is specified. * json.h: Add a TODO item to refactor out to share with `libcpp/mkdeps.cc`. gcc/c-family/ * c-opts.cc (c_common_handle_option): Add fdeps_file variable and -fdeps-format=, -fdeps-file=, and -fdeps-target= parsing. * c.opt: Add -fdeps-format=, -fdeps-file=, and -fdeps-target= flags. gcc/cp/ * module.cc (preprocessed_module): Pass whether the module is exported to dependency tracking. gcc/testsuite/ * g++.dg/modules/depflags-f-MD.C: New test. * g++.dg/modules/depflags-f.C: New test. * g++.dg/modules/depflags-fi.C: New test. * g++.dg/modules/depflags-fj-MD.C: New test. * g++.dg/modules/depflags-fj.C: New test. * g++.dg/modules/depflags-fjo-MD.C: New test. * g++.dg/modules/depflags-fjo.C: New test. * g++.dg/modules/depflags-fo-MD.C: New test. * g++.dg/modules/depflags-fo.C: New test. * g++.dg/modules/depflags-j-MD.C: New test. * g++.dg/modules/depflags-j.C: New test. * g++.dg/modules/depflags-jo-MD.C: New test. * g++.dg/modules/depflags-jo.C: New test. * g++.dg/modules/depflags-o-MD.C: New test. * g++.dg/modules/depflags-o.C: New test. * g++.dg/modules/p1689-1.C: New test. * g++.dg/modules/p1689-1.exp.ddi: New test expectation. * g++.dg/modules/p1689-2.C: New test. * g++.dg/modules/p1689-2.exp.ddi: New test expectation. * g++.dg/modules/p1689-3.C: New test. * g++.dg/modules/p1689-3.exp.ddi: New test expectation. * g++.dg/modules/p1689-4.C: New test. * g++.dg/modules/p1689-4.exp.ddi: New test expectation. * g++.dg/modules/p1689-5.C: New test. * g++.dg/modules/p1689-5.exp.ddi: New test expectation. * g++.dg/modules/modules.exp: Load new P1689 library routines. * g++.dg/modules/test-p1689.py: New tool for validating P1689 output. * lib/modules.exp: Support for validating P1689 outputs. Signed-off-by: Ben Boeckel --- gcc/c-family/c-opts.cc | 44 +++- gcc/c-family/c.opt | 12 + gcc/cp/module.cc | 3 +- gcc/doc/invoke.texi | 27 +++ gcc/gcc.cc | 4 +- gcc/json.h | 3 + gcc/testsuite/g++.dg/modules/depflags-f-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-f.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fi.C | 4 + gcc/testsuite/g++.dg/modules/depflags-fj-MD.C | 3 + .../g++.dg/modules/depflags-fj-MF-share.C | 6 + gcc/testsuite/g++.dg/modules/depflags-fj.C | 4 + .../g++.dg/modules/depflags-fjo-MD.C | 4 + gcc/testsuite/g++.dg/modules/depflags-fjo.C | 5 + gcc/testsuite/g++.dg/modules/depflags-fo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-j-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-j.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-o-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-o.C | 3 + gcc/testsuite/g++.dg/modules/modules.exp | 1 + gcc/testsuite/g++.dg/modules/p1689-1.C | 17 ++ gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi | 27 +++ gcc/testsuite/g++.dg/modules/p1689-2.C | 15 ++ gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi | 16 ++ gcc/testsuite/g++.dg/modules/p1689-3.C | 13 + gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi | 16 ++ gcc/testsuite/g++.dg/modules/p1689-4.C | 13 + gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi | 14 ++ gcc/testsuite/g++.dg/modules/p1689-5.C | 13 + gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi | 14 ++ .../g++.dg/modules/p1689-file-default.C | 16 ++ .../g++.dg/modules/p1689-file-default.exp.ddi | 27 +++ .../g++.dg/modules/p1689-target-default.C | 16 ++ .../modules/p1689-target-default.exp.ddi | 27 +++ gcc/testsuite/g++.dg/modules/test-p1689.py | 222 ++++++++++++++++++ gcc/testsuite/lib/modules.exp | 71 ++++++ libcpp/include/cpplib.h | 12 +- libcpp/include/mkdeps.h | 9 +- libcpp/init.cc | 13 +- libcpp/mkdeps.cc | 153 +++++++++++- 43 files changed, 859 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fi.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj-MF-share.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-file-default.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-file-default.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-target-default.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-target-default.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/test-p1689.py create mode 100644 gcc/testsuite/lib/modules.exp diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index af19140e382..9d794b2f4de 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -77,6 +77,9 @@ static bool verbose; /* Dependency output file. */ static const char *deps_file; +/* Structured dependency output file. */ +static const char *fdeps_file; + /* The prefix given by -iprefix, if any. */ static const char *iprefix; @@ -361,6 +364,24 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, deps_file = arg; break; + case OPT_fdeps_format_: + /* https://wg21.link/p1689r5 */ + if (!strcmp (arg, "p1689r5")) + cpp_opts->deps.fdeps_format = DEPS_FMT_P1689R5; + else + error ("%<-fdeps-format=%> unknown format %<%s%>", arg); + break; + + case OPT_fdeps_file_: + deps_seen = true; + fdeps_file = arg; + break; + + case OPT_fdeps_target_: + deps_seen = true; + defer_opt (code, arg); + break; + case OPT_MF: deps_seen = true; deps_file = arg; @@ -1280,6 +1301,7 @@ void c_common_finish (void) { FILE *deps_stream = NULL; + FILE *fdeps_stream = NULL; /* Note that we write the dependencies even if there are errors. This is useful for handling outdated generated headers that now trigger errors @@ -1308,9 +1330,27 @@ c_common_finish (void) locations with input_location, which would be incorrect now. */ override_libcpp_locations = false; + if (cpp_opts->deps.fdeps_format != DEPS_FMT_NONE) + { + if (!fdeps_file) + fdeps_stream = out_stream; + else if (fdeps_file[0] == '-' && fdeps_file[1] == '\0') + fdeps_stream = stdout; + else + { + fdeps_stream = fopen (fdeps_file, "w"); + if (!fdeps_stream) + fatal_error (input_location, "opening dependency file %s: %m", + fdeps_file); + } + if (fdeps_stream == deps_stream && fdeps_stream != stdout) + fatal_error (input_location, "%<-MF%> and %<-fdeps-file=%> cannot share an output file %s: %m", + fdeps_file); + } + /* For performance, avoid tearing down cpplib's internal structures with cpp_destroy (). */ - cpp_finish (parse_in, deps_stream); + cpp_finish (parse_in, deps_stream, fdeps_stream); if (deps_stream && deps_stream != out_stream && deps_stream != stdout && (ferror (deps_stream) || fclose (deps_stream))) @@ -1382,6 +1422,8 @@ handle_deferred_opts (void) if (opt->code == OPT_MT || opt->code == OPT_MQ) deps_add_target (deps, opt->arg, opt->code == OPT_MQ); + else if (opt->code == OPT_fdeps_target_) + fdeps_add_target (deps, opt->arg, true); } } diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 4abdc8d0e77..4781ca831d6 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -256,6 +256,18 @@ MT C ObjC C++ ObjC++ Joined Separate MissingArgError(missing makefile target after %qs) -MT Add a target that does not require quoting. +fdeps-format= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing format after %qs) +Structured format for output dependency information. Supported (\"p1689r5\"). + +fdeps-file= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing output path after %qs) +File for output dependency information. + +fdeps-target= +C ObjC C++ ObjC++ NoDriverArg Joined MissingArgError(missing path after %qs) +-fdeps-target=obj.o Output file for the compile step. + P C ObjC C++ ObjC++ Do not generate #line directives. diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index ea362bdffa4..9df60d695b1 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -19834,7 +19834,8 @@ preprocessed_module (cpp_reader *reader) && (module->is_interface () || module->is_partition ())) deps_add_module_target (deps, module->get_flatname (), maybe_add_cmi_prefix (module->filename), - module->is_header()); + module->is_header (), + module->is_exported ()); else deps_add_module_dep (deps, module->get_flatname ()); } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index efcf3bfb3d6..d3582049582 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2820,6 +2820,33 @@ is @option{-fpermitted-flt-eval-methods=c11}. The default when in a GNU dialect (@option{-std=gnu11} or similar) is @option{-fpermitted-flt-eval-methods=ts-18661-3}. +@opindex fdeps- +The @samp{-fdeps-*} options are used to extract structured dependency +information for a source. This involves determining what resources provided by +other source files will be required to compile the source as well as what +resources are provided by the source. This information can be used to add +required dependencies between compilation rules of dependent sources based on +their contents rather than requiring such information be reflected within the +build tools as well. + +@opindex fdeps-file +@item -fdeps-file=@var{file} +Where to write structured dependency information. + +@opindex fdeps-format +@item -fdeps-format=@var{format} +The format to use for structured dependency information. @samp{p1689r5} is the +only supported format right now. Note that when this argument is specified, the +output of @samp{-MF} is stripped of some information (namely C++ modules) so +that it does not use extended makefile syntax not understood by most tools. + +@opindex fdeps-target +@item -fdeps-target=@var{file} +Analogous to @option{-MT} but for structured dependency information. This +indicates the target which will ultimately need any required resources and +provide any resources extracted from the source that may be required by other +sources. + @opindex fplan9-extensions @item -fplan9-extensions Accept some non-standard constructs used in Plan 9 code. diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 44433b80d61..0a9818374f0 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -1236,7 +1236,9 @@ static const char *cpp_unique_options = %{remap} %{%:debug-level-gt(2):-dD}\ %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ %{H} %C %{D*&U*&A*} %{i*} %Z %i\ - %{E|M|MM:%W{o*}}"; + %{E|M|MM:%W{o*}}\ + %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\ + %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}"; /* This contains cpp options which are common with cc1_options and are passed only when preprocessing only to avoid duplication. We pass the cc1 spec diff --git a/gcc/json.h b/gcc/json.h index 057119db277..6cc58c8ae0c 100644 --- a/gcc/json.h +++ b/gcc/json.h @@ -30,6 +30,9 @@ along with GCC; see the file COPYING3. If not see Supports creating a DOM-like tree of json::value *, and then dumping json::value * to text. */ +/* TODO: `libcpp/mkdeps.cc` wants JSON writing support for p1689r5 output; + extract this code and move to libiberty. */ + namespace json { diff --git a/gcc/testsuite/g++.dg/modules/depflags-f-MD.C b/gcc/testsuite/g++.dg/modules/depflags-f-MD.C new file mode 100644 index 00000000000..2bd980c0047 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-f-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-f.C b/gcc/testsuite/g++.dg/modules/depflags-f.C new file mode 100644 index 00000000000..789b18f59e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-f.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fi.C b/gcc/testsuite/g++.dg/modules/depflags-fi.C new file mode 100644 index 00000000000..d8e75ad9089 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fi.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-format=invalid } + +// { dg-prune-output "error: '-fdeps-format=' unknown format 'invalid'" } +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C new file mode 100644 index 00000000000..3a9452345a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fj-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fj-MF-share.C b/gcc/testsuite/g++.dg/modules/depflags-fj-MF-share.C new file mode 100644 index 00000000000..723014f7a0e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fj-MF-share.C @@ -0,0 +1,6 @@ +// { dg-additional-options -MD } +// { dg-additional-options "-MF depflags-3.ddi" } +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: '-MF' and '-fdeps-file=' cannot share an output file" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fj.C b/gcc/testsuite/g++.dg/modules/depflags-fj.C new file mode 100644 index 00000000000..063e0ee5514 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fj.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C new file mode 100644 index 00000000000..84da337f9f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C @@ -0,0 +1,4 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-target=depflags-1.C } +// { dg-additional-options -fdeps-format=p1689r5 } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fjo.C b/gcc/testsuite/g++.dg/modules/depflags-fjo.C new file mode 100644 index 00000000000..760d8f26f66 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fjo.C @@ -0,0 +1,5 @@ +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-target=depflags-1.C } +// { dg-additional-options -fdeps-format=p1689r5 } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C new file mode 100644 index 00000000000..6da03f9133f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fo-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-fo.C b/gcc/testsuite/g++.dg/modules/depflags-fo.C new file mode 100644 index 00000000000..5deb27a4598 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-fo.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-j-MD.C b/gcc/testsuite/g++.dg/modules/depflags-j-MD.C new file mode 100644 index 00000000000..92a2af61e78 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-j-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.ddi } diff --git a/gcc/testsuite/g++.dg/modules/depflags-j.C b/gcc/testsuite/g++.dg/modules/depflags-j.C new file mode 100644 index 00000000000..2eb5890938e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-j.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-file=depflags-3.ddi } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C b/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C new file mode 100644 index 00000000000..ba2b21e3066 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-jo-MD.C @@ -0,0 +1,3 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-jo.C b/gcc/testsuite/g++.dg/modules/depflags-jo.C new file mode 100644 index 00000000000..a015d35141f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-jo.C @@ -0,0 +1,4 @@ +// { dg-additional-options -fdeps-file=depflags-3.ddi } +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/depflags-o-MD.C b/gcc/testsuite/g++.dg/modules/depflags-o-MD.C new file mode 100644 index 00000000000..1b67558b687 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-o-MD.C @@ -0,0 +1,2 @@ +// { dg-additional-options -MD } +// { dg-additional-options -fdeps-target=depflags-1.C } diff --git a/gcc/testsuite/g++.dg/modules/depflags-o.C b/gcc/testsuite/g++.dg/modules/depflags-o.C new file mode 100644 index 00000000000..38d645081b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depflags-o.C @@ -0,0 +1,3 @@ +// { dg-additional-options -fdeps-target=depflags-1.C } + +// { dg-prune-output "error: to generate dependencies you must specify either '-M' or '-MM'" } diff --git a/gcc/testsuite/g++.dg/modules/modules.exp b/gcc/testsuite/g++.dg/modules/modules.exp index dc302d3d0af..b6929544c59 100644 --- a/gcc/testsuite/g++.dg/modules/modules.exp +++ b/gcc/testsuite/g++.dg/modules/modules.exp @@ -28,6 +28,7 @@ # { dg-module-do [link|run] [xfail] [options] } # link [and run] load_lib g++-dg.exp +load_lib modules.exp # If a testcase doesn't have special options, use these. global DEFAULT_CXXFLAGS diff --git a/gcc/testsuite/g++.dg/modules/p1689-1.C b/gcc/testsuite/g++.dg/modules/p1689-1.C new file mode 100644 index 00000000000..3c138c8f82e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-1.C @@ -0,0 +1,17 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-1.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-1.o } +// { dg-additional-options -fdeps-file=p1689-1.ddi } + +// Export a module that uses modules, re-exports modules, and partitions. + +export module foo; +export import foo:part1; +import foo:part2; + +export import bar; + +// { dg-final { run-check-p1689-valid p1689-1.ddi p1689-1.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi new file mode 100644 index 00000000000..c5648ac7ae5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi @@ -0,0 +1,27 @@ +{ + "rules": [ + { + "primary-output": "p1689-1.o", + "provides": [ + { + "logical-name": "foo", + "is-interface": true + } + ], + "requires": [ + "__P1689_unordered__", + { + "logical-name": "bar" + }, + { + "logical-name": "foo:part1" + }, + { + "logical-name": "foo:part2" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-2.C b/gcc/testsuite/g++.dg/modules/p1689-2.C new file mode 100644 index 00000000000..5d7fe52a809 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-2.C @@ -0,0 +1,15 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-2.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-2.o } +// { dg-additional-options -fdeps-file=p1689-2.ddi } + +// Export a module partition that uses modules. + +export module foo:part1; + +#include + +// { dg-final { run-check-p1689-valid p1689-2.ddi p1689-2.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi new file mode 100644 index 00000000000..6901172f277 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi @@ -0,0 +1,16 @@ +{ + "rules": [ + { + "primary-output": "p1689-2.o", + "provides": [ + { + "logical-name": "foo:part1", + "is-interface": true + } + ], + "requires": [] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-3.C b/gcc/testsuite/g++.dg/modules/p1689-3.C new file mode 100644 index 00000000000..6c0aced5419 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-3.C @@ -0,0 +1,13 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-3.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-3.o } +// { dg-additional-options -fdeps-file=p1689-3.ddi } + +// Provide a module partition. + +module foo:part2; + +// { dg-final { run-check-p1689-valid p1689-3.ddi p1689-3.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi new file mode 100644 index 00000000000..5a40beacd22 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi @@ -0,0 +1,16 @@ +{ + "rules": [ + { + "primary-output": "p1689-3.o", + "provides": [ + { + "logical-name": "foo:part2", + "is-interface": false + } + ], + "requires": [] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-4.C b/gcc/testsuite/g++.dg/modules/p1689-4.C new file mode 100644 index 00000000000..922f0158440 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-4.C @@ -0,0 +1,13 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-4.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-4.o } +// { dg-additional-options -fdeps-file=p1689-4.ddi } + +// Module implementation unit. + +module foo; + +// { dg-final { run-check-p1689-valid p1689-4.ddi p1689-4.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi new file mode 100644 index 00000000000..b119f5654b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi @@ -0,0 +1,14 @@ +{ + "rules": [ + { + "primary-output": "p1689-4.o", + "requires": [] + { + "logical-name": "foo" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-5.C b/gcc/testsuite/g++.dg/modules/p1689-5.C new file mode 100644 index 00000000000..94908bf8a03 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-5.C @@ -0,0 +1,13 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-5.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-5.o } +// { dg-additional-options -fdeps-file=p1689-5.ddi } + +// Use modules, don't provide anything. + +import bar; + +// { dg-final { run-check-p1689-valid p1689-5.ddi p1689-5.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi new file mode 100644 index 00000000000..18704ac8820 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi @@ -0,0 +1,14 @@ +{ + "rules": [ + { + "primary-output": "p1689-5.o", + "requires": [ + { + "logical-name": "bar" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-file-default.C b/gcc/testsuite/g++.dg/modules/p1689-file-default.C new file mode 100644 index 00000000000..4e1f5bbd2f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-file-default.C @@ -0,0 +1,16 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-file-default.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-target=p1689-file-default.o } + +// Scan without `-fdeps-file=` + +export module foo; +export import foo:part1; +import foo:part2; + +export import bar; + +// { dg-final { run-check-p1689-valid p1689-file-default.o.ddi p1689-file-default.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-file-default.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-file-default.exp.ddi new file mode 100644 index 00000000000..187eab6141a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-file-default.exp.ddi @@ -0,0 +1,27 @@ +{ + "rules": [ + { + "primary-output": "p1689-file-default.o", + "provides": [ + { + "logical-name": "foo", + "is-interface": true + } + ], + "requires": [ + "__P1689_unordered__", + { + "logical-name": "bar" + }, + { + "logical-name": "foo:part1" + }, + { + "logical-name": "foo:part2" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/p1689-target-default.C b/gcc/testsuite/g++.dg/modules/p1689-target-default.C new file mode 100644 index 00000000000..67088ed2769 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-target-default.C @@ -0,0 +1,16 @@ +// { dg-additional-options -E } +// { dg-additional-options "-MT p1689-target-default.ddi" } +// { dg-additional-options -MD } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fdeps-format=p1689r5 } +// { dg-additional-options -fdeps-file=p1689-target-default.ddi } + +// Scan without `-fdeps-target=` + +export module foo; +export import foo:part1; +import foo:part2; + +export import bar; + +// { dg-final { run-check-p1689-valid p1689-target-default.ddi p1689-target-default.exp.ddi } } diff --git a/gcc/testsuite/g++.dg/modules/p1689-target-default.exp.ddi b/gcc/testsuite/g++.dg/modules/p1689-target-default.exp.ddi new file mode 100644 index 00000000000..dd3d9c44705 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/p1689-target-default.exp.ddi @@ -0,0 +1,27 @@ +{ + "rules": [ + { + "primary-output": "p1689-target-default.o", + "provides": [ + { + "logical-name": "foo", + "is-interface": true + } + ], + "requires": [ + "__P1689_unordered__", + { + "logical-name": "bar" + }, + { + "logical-name": "foo:part1" + }, + { + "logical-name": "foo:part2" + } + ] + } + ], + "version": 0, + "revision": 0 +} diff --git a/gcc/testsuite/g++.dg/modules/test-p1689.py b/gcc/testsuite/g++.dg/modules/test-p1689.py new file mode 100644 index 00000000000..2f07cc361aa --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/test-p1689.py @@ -0,0 +1,222 @@ +import json + + +# Parameters. +ALL_ERRORS = False +REPLACEMENTS = {} + + +def _print_path(path): + '''Format a JSON path for output.''' + return '/'.join(path) + + +def _report_error(msg): + '''Report an error.''' + full_msg = 'ERROR: ' + msg + if ALL_ERRORS: + print(full_msg) + else: + raise RuntimeError(full_msg) + + +def _error_type_mismatch(path, actual, expect): + '''Report that there is a type mismatch.''' + _report_error('type mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_unknown_type(path, typ): + '''Report that there is an unknown type in the JSON object.''' + _report_error('unknown type at %s: "%s"' % (_print_path(path), typ)) + + +def _error_length_mismatch(path, actual, expect): + '''Report a length mismatch in an object or array.''' + _report_error('length mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_unexpect_value(path, actual, expect): + '''Report a value mismatch.''' + _report_error('value mismatch at %s: actual: "%s" expect: "%s"' % (_print_path(path), actual, expect)) + + +def _error_extra_key(path, key): + '''Report on a key that is unexpected.''' + _report_error('extra key at %s: "%s"' % (_print_path(path), key)) + + +def _error_missing_key(path, key): + '''Report on a key that is missing.''' + _report_error('extra key at %s: %s' % (_print_path(path), key)) + + +def _compare_object(path, actual, expect): + '''Compare a JSON object.''' + is_ok = True + + if not len(actual) == len(expect): + _error_length_mismatch(path, len(actual), len(expect)) + is_ok = False + + for key in actual: + if key not in expect: + _error_extra_key(path, key) + is_ok = False + else: + sub_error = compare_json(path + [key], actual[key], expect[key]) + if sub_error: + is_ok = False + + for key in expect: + if key not in actual: + _error_missing_key(path, key) + is_ok = False + + return is_ok + + +def _compare_array(path, actual, expect): + '''Compare a JSON array.''' + is_ok = True + + if not len(actual) == len(expect): + _error_length_mismatch(path, len(actual), len(expect)) + is_ok = False + + for (idx, (a, e)) in enumerate(zip(actual, expect)): + sub_error = compare_json(path + [str(idx)], a, e) + if sub_error: + is_ok = False + + return is_ok + + +def _make_replacements(value): + for (old, new) in REPLACEMENTS.values(): + value = value.replace(old, new) + return value + + +def _compare_string(path, actual, expect): + '''Compare a JSON string supporting replacements in the expected output.''' + expect = _make_replacements(expect) + + if not actual == expect: + _error_unexpect_value(path, actual, expect) + return False + else: + print('%s is ok: %s' % (_print_path(path), actual)) + return True + + +def _compare_number(path, actual, expect): + '''Compare a JSON integer.''' + if not actual == expect: + _error_unexpect_value(path, actual, expect) + return False + else: + print('%s is ok: %s' % (_print_path(path), actual)) + return True + + +def _inspect_ordering(arr): + req_ordering = True + + if not arr: + return arr, req_ordering + + if arr[0] == '__P1689_unordered__': + arr.pop(0) + req_ordering = False + + return arr, req_ordering + + +def compare_json(path, actual, expect): + actual_type = type(actual) + expect_type = type(expect) + + is_ok = True + + if not actual_type == expect_type: + _error_type_mismatch(path, actual_type, expect_type) + is_ok = False + elif actual_type == dict: + is_ok = _compare_object(path, actual, expect) + elif actual_type == list: + expect, req_ordering = _inspect_ordering(expect) + if not req_ordering: + actual = set(actual) + expect = set(expect) + is_ok = _compare_array(path, actual, expect) + elif actual_type == str: + is_ok = _compare_string(path, actual, expect) + elif actual_type == float: + is_ok = _compare_number(path, actual, expect) + elif actual_type == int: + is_ok = _compare_number(path, actual, expect) + elif actual_type == bool: + is_ok = _compare_number(path, actual, expect) + elif actual_type == type(None): + pass + else: + _error_unknown_type(path, actual_type) + is_ok = False + + return is_ok + + +def validate_p1689(actual, expect): + '''Validate a P1689 file against an expected output file. + + Returns `False` if it fails, `True` if they are the same. + ''' + with open(actual, 'r') as fin: + actual_content = fin.read() + with open(expect, 'r') as fin: + expect_content = fin.read() + + actual_json = json.loads(actual_content) + expect_json = json.loads(expect_content) + + return compare_json([], actual_json, expect_json) + + +if __name__ == '__main__': + import sys + + actual = None + expect = None + + # Parse arguments. + args = sys.argv[1:] + while args: + # Take an argument. + arg = args.pop(0) + + # Parse out replacement expressions. + if arg == '-r' or arg == '--replace': + replacement = args.pop(0) + (key, value) = replacement.split('=', maxsplit=1) + REPLACEMENTS[key] = value + # Flag to change how errors are reported. + elif arg == '-A' or arg == '--all': + ALL_ERRORS = True + # Required arguments. + elif arg == '-a' or arg == '--actual': + actual = args.pop(0) + elif arg == '-e' or arg == '--expect': + expect = args.pop(0) + + # Validate that we have the required arguments. + if actual is None: + raise RuntimeError('missing "actual" file') + if expect is None: + raise RuntimeError('missing "expect" file') + + # Do the actual work. + is_ok = validate_p1689(actual, expect) + + # Fail if errors are found. + if not is_ok: + sys.exit(1) diff --git a/gcc/testsuite/lib/modules.exp b/gcc/testsuite/lib/modules.exp new file mode 100644 index 00000000000..d466a73cbe1 --- /dev/null +++ b/gcc/testsuite/lib/modules.exp @@ -0,0 +1,71 @@ +# Copyright (C) 1997-2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Verify various kinds of gcov output: line counts, branch percentages, +# and call return percentages. None of this is language-specific. + +load_lib "target-supports.exp" + +# +# clean-p1689-file -- delete a working file the compiler creates for p1689 +# +# TESTCASE is the name of the test. +# SUFFIX is file suffix + +proc clean-p1689-file { testcase suffix } { + set basename [file tail $testcase] + set base [file rootname $basename] + remote_file host delete $base.$suffix +} + +# +# clean-p1689 -- delete the working files the compiler creates for p1689 +# +# TESTCASE is the name of the test. +# +proc clean-p1689 { testcase } { + clean-p1689-file $testcase "d" + clean-p1689-file $testcase "ddi" +} + +# Call by dg-final to check a P1689 dependency file + +proc run-check-p1689-valid { depfile template } { + global srcdir subdir + # Extract the test file name from the arguments. + set testcase [file rootname [file tail $depfile]] + + verbose "Running P1689 validation for $testcase in $srcdir/$subdir" 2 + set testcase [remote_download host $testcase] + + set pytest_script "test-p1689.py" + if { ![check_effective_target_recent_python3] } { + unsupported "$pytest_script python3 is missing" + return + } + + verbose "running script" 1 + spawn -noecho python3 $srcdir/$subdir/$pytest_script --all --actual $depfile --expect $srcdir/$subdir/$template + + expect { + -re "ERROR: (\[^\r\n\]*)" { + fail $expect_out(0,string) + exp_continue + } + } + + clean-p1689 $testcase +} diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index aef703f8111..141cfd60eda 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -302,6 +302,9 @@ typedef CPPCHAR_SIGNED_T cppchar_signed_t; /* Style of header dependencies to generate. */ enum cpp_deps_style { DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM }; +/* Structured format of module dependencies to generate. */ +enum cpp_fdeps_format { DEPS_FMT_NONE = 0, DEPS_FMT_P1689R5 }; + /* The possible normalization levels, from most restrictive to least. */ enum cpp_normalize_level { /* In NFKC. */ @@ -589,6 +592,9 @@ struct cpp_options /* Style of header dependencies to generate. */ enum cpp_deps_style style; + /* Structured format of module dependencies to generate. */ + enum cpp_fdeps_format fdeps_format; + /* Assume missing files are generated files. */ bool missing_files; @@ -1112,9 +1118,9 @@ extern void cpp_post_options (cpp_reader *); extern void cpp_init_iconv (cpp_reader *); /* Call this to finish preprocessing. If you requested dependency - generation, pass an open stream to write the information to, - otherwise NULL. It is your responsibility to close the stream. */ -extern void cpp_finish (cpp_reader *, FILE *deps_stream); + generation, pass open stream(s) to write the information to, + otherwise NULL. It is your responsibility to close the stream(s). */ +extern void cpp_finish (cpp_reader *, FILE *deps_stream, FILE *fdeps_stream = NULL); /* Call this to release the handle at the end of preprocessing. Any use of the handle after this function returns is invalid. */ diff --git a/libcpp/include/mkdeps.h b/libcpp/include/mkdeps.h index 920e2791334..7025e634caf 100644 --- a/libcpp/include/mkdeps.h +++ b/libcpp/include/mkdeps.h @@ -53,11 +53,15 @@ extern void deps_add_default_target (class mkdeps *, const char *); /* Adds a module target. The module name and cmi name are copied. */ extern void deps_add_module_target (struct mkdeps *, const char *module, - const char *cmi, bool is_header); + const char *cmi, bool is_header, + bool is_exported); /* Adds a module dependency. The module name is copied. */ extern void deps_add_module_dep (struct mkdeps *, const char *module); +/* Add a structured dependency target. */ +extern void fdeps_add_target (struct mkdeps *, const char *, bool); + /* Add a dependency (appears on the right side of the colon) to the deps list. Dependencies will be printed in the order that they were entered with this function. By convention, the first @@ -68,6 +72,9 @@ extern void deps_add_dep (class mkdeps *, const char *); is the number of columns to word-wrap at (0 means don't wrap). */ extern void deps_write (const cpp_reader *, FILE *, unsigned int); +/* Write out a deps buffer to a specified file in P1689R5 format. */ +extern void deps_write_p1689r5 (const struct mkdeps *, FILE *); + /* Write out a deps buffer to a file, in a form that can be read back with deps_restore. Returns nonzero on error, in which case the error number will be in errno. */ diff --git a/libcpp/init.cc b/libcpp/init.cc index 693feaa31ed..f974d8f2d41 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -860,7 +860,7 @@ read_original_directory (cpp_reader *pfile) Maybe it should also reset state, such that you could call cpp_start_read with a new filename to restart processing. */ void -cpp_finish (cpp_reader *pfile, FILE *deps_stream) +cpp_finish (struct cpp_reader *pfile, FILE *deps_stream, FILE *fdeps_stream) { /* Warn about unused macros before popping the final buffer. */ if (CPP_OPTION (pfile, warn_unused_macros)) @@ -874,8 +874,15 @@ cpp_finish (cpp_reader *pfile, FILE *deps_stream) while (pfile->buffer) _cpp_pop_buffer (pfile); - if (deps_stream) - deps_write (pfile, deps_stream, 72); + cpp_fdeps_format fdeps_format = CPP_OPTION (pfile, deps.fdeps_format); + if (fdeps_format == DEPS_FMT_P1689R5 && fdeps_stream) + deps_write_p1689r5 (pfile->deps, fdeps_stream); + + if (CPP_OPTION (pfile, deps.style) != DEPS_NONE + && deps_stream) + { + deps_write (pfile, deps_stream, 72); + } /* Report on headers that could use multiple include guards. */ if (CPP_OPTION (pfile, print_include_names)) diff --git a/libcpp/mkdeps.cc b/libcpp/mkdeps.cc index 8f9585c3c0a..762bde6ea55 100644 --- a/libcpp/mkdeps.cc +++ b/libcpp/mkdeps.cc @@ -81,7 +81,8 @@ public: }; mkdeps () - : module_name (NULL), cmi_name (NULL), is_header_unit (false), quote_lwm (0) + : primary_output (NULL), module_name (NULL), cmi_name (NULL) + , is_header_unit (false), is_exported (false), quote_lwm (0) { } ~mkdeps () @@ -90,6 +91,9 @@ public: for (i = targets.size (); i--;) free (const_cast (targets[i])); + free (const_cast (primary_output)); + for (i = fdeps_targets.size (); i--;) + free (const_cast (fdeps_targets[i])); for (i = deps.size (); i--;) free (const_cast (deps[i])); for (i = vpath.size (); i--;) @@ -103,6 +107,8 @@ public: public: vec targets; vec deps; + const char * primary_output; + vec fdeps_targets; vec vpath; vec modules; @@ -110,6 +116,7 @@ public: const char *module_name; const char *cmi_name; bool is_header_unit; + bool is_exported; unsigned short quote_lwm; }; @@ -288,6 +295,26 @@ deps_add_default_target (class mkdeps *d, const char *tgt) } } +/* Adds a target O. We make a copy, so it need not be a permanent + string. + + This is the target associated with the rule that (in a C++ modules build) + compiles the source that is being scanned for dynamic dependencies. It is + used to associate the structured dependency information with that rule as + needed. */ +void +fdeps_add_target (struct mkdeps *d, const char *o, bool is_primary) +{ + o = apply_vpath (d, o); + if (is_primary) + { + if (d->primary_output) + d->fdeps_targets.push (d->primary_output); + d->primary_output = xstrdup (o); + } else + d->fdeps_targets.push (xstrdup (o)); +} + void deps_add_dep (class mkdeps *d, const char *t) { @@ -325,12 +352,13 @@ deps_add_vpath (class mkdeps *d, const char *vpath) void deps_add_module_target (struct mkdeps *d, const char *m, - const char *cmi, bool is_header_unit) + const char *cmi, bool is_header_unit, bool is_exported) { gcc_assert (!d->module_name); d->module_name = xstrdup (m); d->is_header_unit = is_header_unit; + d->is_exported = is_exported; d->cmi_name = xstrdup (cmi); } @@ -395,10 +423,16 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) if (colmax && colmax < 34) colmax = 34; + /* Write out C++ modules information if no other `-fdeps-format=` + option is given. */ + cpp_fdeps_format fdeps_format = CPP_OPTION (pfile, deps.fdeps_format); + bool write_make_modules_deps = fdeps_format == DEPS_FMT_NONE && + CPP_OPTION (pfile, deps.modules); + if (d->deps.size ()) { column = make_write_vec (d->targets, fp, 0, colmax, d->quote_lwm); - if (CPP_OPTION (pfile, deps.modules) && d->cmi_name) + if (write_make_modules_deps && d->cmi_name) column = make_write_name (d->cmi_name, fp, column, colmax); fputs (":", fp); column++; @@ -409,7 +443,7 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) fprintf (fp, "%s:\n", munge (d->deps[i])); } - if (!CPP_OPTION (pfile, deps.modules)) + if (!write_make_modules_deps) return; if (d->modules.size ()) @@ -473,6 +507,117 @@ deps_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax) make_write (pfile, fp, colmax); } +static void +p1689r5_write_filepath (const char *name, FILE *fp) +{ + if (cpp_valid_utf8_p (name, strlen (name))) + { + fputc ('"', fp); + for (const char* c = name; *c; c++) + { + // Escape control characters. + if (ISCNTRL (*c)) + fprintf (fp, "\\u%04x", *c); + // JSON escape characters. + else if (*c == '"' || *c == '\\') + { + fputc ('\\', fp); + fputc (*c, fp); + } + // Everything else. + else + fputc (*c, fp); + } + fputc ('"', fp); + } + else + { + // TODO: print an error + } +} + +static void +p1689r5_write_vec (const mkdeps::vec &vec, FILE *fp) +{ + for (unsigned ix = 0; ix != vec.size (); ix++) + { + p1689r5_write_filepath (vec[ix], fp); + if (ix < vec.size () - 1) + fputc (',', fp); + fputc ('\n', fp); + } +} + +/* Ideally this (and the above `p1689r5_` functions) would use `gcc/json.h`, + but since this is `libcpp`, we cannot use `gcc/` code. + + TODO: move `json.h` to libiberty. */ +void +deps_write_p1689r5 (const struct mkdeps *d, FILE *fp) +{ + fputs ("{\n", fp); + + fputs ("\"rules\": [\n", fp); + fputs ("{\n", fp); + + if (d->primary_output) + { + fputs ("\"primary-output\": ", fp); + p1689r5_write_filepath (d->primary_output, fp); + fputs (",\n", fp); + } + + if (d->fdeps_targets.size ()) + { + fputs ("\"outputs\": [\n", fp); + p1689r5_write_vec (d->fdeps_targets, fp); + fputs ("],\n", fp); + } + + if (d->module_name) + { + fputs ("\"provides\": [\n", fp); + fputs ("{\n", fp); + + fputs ("\"logical-name\": ", fp); + p1689r5_write_filepath (d->module_name, fp); + fputs (",\n", fp); + + fprintf (fp, "\"is-interface\": %s\n", d->is_exported ? "true" : "false"); + + // TODO: header-unit information + + fputs ("}\n", fp); + fputs ("],\n", fp); + } + + fputs ("\"requires\": [\n", fp); + for (size_t i = 0; i < d->modules.size (); i++) + { + if (i != 0) + fputs (",\n", fp); + fputs ("{\n", fp); + + fputs ("\"logical-name\": ", fp); + p1689r5_write_filepath (d->modules[i], fp); + fputs ("\n", fp); + + // TODO: header-unit information + + fputs ("}\n", fp); + } + fputs ("]\n", fp); + + fputs ("}\n", fp); + + fputs ("],\n", fp); + + fputs ("\"version\": 0,\n", fp); + fputs ("\"revision\": 0\n", fp); + + fputs ("}\n", fp); +} + /* Write out a deps buffer to a file, in a form that can be read back with deps_restore. Returns nonzero on error, in which case the error number will be in errno. */ From patchwork Sun Jul 2 16:32:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 115102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp46272vqx; Sun, 2 Jul 2023 09:34:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlETiumVXAOJwzSFOZ0w0sAOuDr+QKJuc4s+sWeaEC1QIsMdZg1xhD+raqnPVHeAUH5YdAFh X-Received: by 2002:a17:906:10dc:b0:992:2f67:cd34 with SMTP id v28-20020a17090610dc00b009922f67cd34mr9771215ejv.22.1688315667735; Sun, 02 Jul 2023 09:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688315667; cv=none; d=google.com; s=arc-20160816; b=HJaS52GTJx56EBD0lKSKOLYaK2cVPdDcYEsa1pFuap7VxJdlVjP3zAYYSeAyocAiUJ qgkwx/nr+tNDANZ/QrZBMLXiG4FLsAy9Gy9+esxiGV0Plw+oYhQkDONam60nfAHMBMAi P0RyECS+ElxjcXCzhtFf0vvKKppCwoHsOyjFk9wL6c+X4yex2iAeDimrjX1CU6Z9qzsA v27Xqi8trtfqiT/idnuHaYbxUL5m8GhfhyRL1b1KUv3PHvxM9G5donIeFoMi3szlExNu yP7VjlbgVEhUJtO9R28ZM+CzG78c4Ix8CBpxXQe+YVfmGCzKEpxR7pvv3D+IQzCaejM0 s89Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=DcitMMybUfPBuzj7MYfk8s1f8Mo7g5RL3ya9lCEzb3I=; fh=WmOQlEQshjW1IyckmJV5Nh43dgdMAM2UcuXDxiXBGYo=; b=nDo8yuF5mV+E7Ia2K6jEdYhl3FSL6VWD8wHl9VMpvSe7JgwJJZZjkjezh+XdR95Wy6 CbWpf2kuWL+F6cgaNHVhynerrxUCoTCXjqe0yAgJ21MnBTzfV85BjxGlnBcvNDaxyYTI FSxqgkBho7BYrAEOKRabQKd5zenDQE7IB1Ia0w0XErKVJACXLBpKWzVkcM15VCaT5e4/ rTrA/Bag5TQ5sc3r1j2ocaTVtEegVUm4YjA3EYGX4FJa8iS8KDXAZ63zXsJ7qBdhGJwJ ZYRUr07T7fDIBuYdjpTHOeTEoIlXgCwfIHHfR+IpEWdOFsbBmoYqmMo+TmdN9TKin96o aq3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Vcpc+zEg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qq17-20020a17090720d100b009930c925bd9si2043430ejb.945.2023.07.02.09.34.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Vcpc+zEg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 727ED3857343 for ; Sun, 2 Jul 2023 16:33:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 727ED3857343 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688315595; bh=DcitMMybUfPBuzj7MYfk8s1f8Mo7g5RL3ya9lCEzb3I=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Vcpc+zEgIWUwtTb3LmIW9cqhXjpQkzLzoSkAwcAnM6dT/i5eTbhIKLrsVdYMV0vJW xybwKTxi2rDMo3mLBkUqCNUjZtk2NcYwBTco6IhHDzMtDQ935ip2uCAoU5MJekYcD1 Kr64FHJtwG0NRylRkQiD7sUQTIltxN2JsliXyN1g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by sourceware.org (Postfix) with ESMTPS id 79B903857B98 for ; Sun, 2 Jul 2023 16:32:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79B903857B98 Received: by mail-qv1-xf2b.google.com with SMTP id 6a1803df08f44-634a3682c25so28797496d6.3 for ; Sun, 02 Jul 2023 09:32:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688315542; x=1690907542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DcitMMybUfPBuzj7MYfk8s1f8Mo7g5RL3ya9lCEzb3I=; b=hYnSGQXb0lITH3fW+3XmD3CPjS8+tbmRtDnNj9yTgXr0MqhiuKjFH58pIpr4pXfHzt InL6KxzSNl6CBuY3JK2hHrpUikjeYovGDJI3Bq68UaHEKTe5EQBTrmn9AM7p9utV4jda rPADI32ttFY2HFRqRYmlXuwXNbvsCcjmu1npErYjCZbRQKMz2ynxFGyuRp3mOTk/5/0o 5++2aOXWZ3kbOwkkGDEEmA5kivKHa/0wxr5wosuSxvGAh3U5LnX7fuQIzPaX5mFkyjzr K0OPI0cxJCy8f8d1olqel5nX4JE8tCtDz+G8uLQbP9OXQwHUnXsQCrPcZxRWoYbeCi44 kraA== X-Gm-Message-State: ABy/qLaZt5HaAT3UwuaWuuahhCjyMR95ge0+jLouuipHM1O9Tt3nHiy2 yNQC0ZipOsIy861cN2xSlmp567oZpZ2jkr7sOcWeHg== X-Received: by 2002:a05:6214:2aa3:b0:631:eb39:b7a6 with SMTP id js3-20020a0562142aa300b00631eb39b7a6mr10093886qvb.33.1688315542708; Sun, 02 Jul 2023 09:32:22 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id i4-20020a05620a144400b0076728319575sm4552839qkl.27.2023.07.02.09.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:32:22 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v7 3/4] c++modules: report imported CMI files as dependencies Date: Sun, 2 Jul 2023 12:32:10 -0400 Message-Id: <20230702163211.3396210-4-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230702163211.3396210-1-ben.boeckel@kitware.com> References: <20230702163211.3396210-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770327289523750710?= X-GMAIL-MSGID: =?utf-8?q?1770327289523750710?= They affect the build, so report them via `-MF` mechanisms. gcc/cp/ * module.cc (do_import): Report imported CMI files as dependencies. gcc/testsuite/ * g++.dg/modules/depreport-1_a.C: New test. * g++.dg/modules/depreport-1_b.C: New test. * g++.dg/modules/test-depfile.py: New tool for validating depfile information. * lib/modules.exp: Support for validating depfile contents. Signed-off-by: Ben Boeckel --- gcc/cp/module.cc | 3 + gcc/testsuite/g++.dg/modules/depreport-1_a.C | 10 + gcc/testsuite/g++.dg/modules/depreport-1_b.C | 12 ++ gcc/testsuite/g++.dg/modules/test-depfile.py | 187 +++++++++++++++++++ gcc/testsuite/lib/modules.exp | 29 +++ 5 files changed, 241 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/depreport-1_a.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-1_b.C create mode 100644 gcc/testsuite/g++.dg/modules/test-depfile.py diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 9df60d695b1..f3acc4e02fe 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -18968,6 +18968,9 @@ module_state::do_import (cpp_reader *reader, bool outermost) dump () && dump ("CMI is %s", file); if (note_module_cmi_yes || inform_cmi_p) inform (loc, "reading CMI %qs", file); + /* Add the CMI file to the dependency tracking. */ + if (cpp_get_deps (reader)) + deps_add_dep (cpp_get_deps (reader), file); fd = open (file, O_RDONLY | O_CLOEXEC | O_BINARY); e = errno; } diff --git a/gcc/testsuite/g++.dg/modules/depreport-1_a.C b/gcc/testsuite/g++.dg/modules/depreport-1_a.C new file mode 100644 index 00000000000..241701728a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depreport-1_a.C @@ -0,0 +1,10 @@ +// { dg-additional-options -fmodules-ts } + +export module Foo; +// { dg-module-cmi Foo } + +export class Base +{ +public: + int m; +}; diff --git a/gcc/testsuite/g++.dg/modules/depreport-1_b.C b/gcc/testsuite/g++.dg/modules/depreport-1_b.C new file mode 100644 index 00000000000..b6e317c6703 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depreport-1_b.C @@ -0,0 +1,12 @@ +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -MD } +// { dg-additional-options "-MF depreport-1.d" } + +import Foo; + +void foo () +{ + Base b; +} + +// { dg-final { run-check-module-dep-expect-input "depreport-1.d" "gcm.cache/Foo.gcm" } } diff --git a/gcc/testsuite/g++.dg/modules/test-depfile.py b/gcc/testsuite/g++.dg/modules/test-depfile.py new file mode 100644 index 00000000000..ea4edb61434 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/test-depfile.py @@ -0,0 +1,187 @@ +import json + + +# Parameters. +ALL_ERRORS = False + + +def _report_error(msg): + '''Report an error.''' + full_msg = 'ERROR: ' + msg + if ALL_ERRORS: + print(full_msg) + else: + raise RuntimeError(full_msg) + + +class Token(object): + pass + + +class Output(Token): + def __init__(self, path): + self.path = path + + +class Input(Token): + def __init__(self, path): + self.path = path + + +class Colon(Token): + pass + + +class Append(Token): + pass + + +class Variable(Token): + def __init__(self, name): + self.name = name + + +class Word(Token): + def __init__(self, name): + self.name = name + + +def validate_depfile(depfile, expect_input=None): + '''Validate a depfile contains some information + + Returns `False` if the information is not found. + ''' + with open(depfile, 'r') as fin: + depfile_content = fin.read() + + real_lines = [] + join_line = False + for line in depfile_content.split('\n'): + # Join the line if needed. + if join_line: + line = real_lines.pop() + line + + # Detect line continuations. + join_line = line.endswith('\\') + # Strip line continuation characters. + if join_line: + line = line[:-1] + + # Add to the real line set. + real_lines.append(line) + + # Perform tokenization. + tokenized_lines = [] + for line in real_lines: + tokenized = [] + join_word = False + for word in line.split(' '): + if join_word: + word = tokenized.pop() + ' ' + word + + # Detect word joins. + join_word = word.endswith('\\') + # Strip escape character. + if join_word: + word = word[:-1] + + # Detect `:` at the end of a word. + if word.endswith(':'): + tokenized.append(word[:-1]) + word = word[-1] + + # Add word to the tokenized set. + tokenized.append(word) + + tokenized_lines.append(tokenized) + + # Parse. + ast = [] + for line in tokenized_lines: + kind = None + for token in line: + if token == ':': + kind = 'dependency' + elif token == '+=': + kind = 'append' + if line == ['']: + kind = 'empty' + + if kind is None: + _report_error('unknown line kind: %s' % line) + + line_parse = [] + if kind == 'dependency': + after_colon = False + for token in line: + if token == ':': + after_colon = True + elif after_colon: + line_parse.append(Input(token)) + else: + line_parse.append(Output(token)) + elif kind == 'append': + after_op = False + for token in line: + if token == '+=': + after_op = True + elif after_op: + line_parse.append(Word(token)) + else: + line_parse.append(Variable(token)) + + ast.append(line_parse) + + for node in ast: + for token in node: + if expect_input is not None: + # If the input is found, clear the expectation. + if isinstance(token, Input) and token.path == expect_input: + expect_input = None + + result = True + if expect_input: + _report_error('missing input: %s' % expect_input) + result = False + + return result + + +if __name__ == '__main__': + import sys + + depfile = None + have_expect = False + expect_input = None + + # Parse arguments. + args = sys.argv[1:] + while args: + # Take an argument. + arg = args.pop(0) + + # Flag to change how errors are reported. + if arg == '-A' or arg == '--all': + ALL_ERRORS = True + # Required arguments. + elif arg == '-d' or arg == '--depfile': + depfile = args.pop(0) + elif arg == '-i' or arg == '--expect-input': + expect_input = args.pop(0) + have_expect = True + + # Validate that we have the required arguments. + if depfile is None: + raise RuntimeError('missing "depfile" file') + if have_expect is None: + raise RuntimeError('missing an "expect" argument') + + # Do the actual work. + try: + is_ok = validate_depfile(depfile, expect_input=expect_input) + except BaseException as e: + _report_error('exception: %s' % e) + + # Fail if errors are found. + if not is_ok: + sys.exit(1) diff --git a/gcc/testsuite/lib/modules.exp b/gcc/testsuite/lib/modules.exp index d466a73cbe1..e24ee7618d9 100644 --- a/gcc/testsuite/lib/modules.exp +++ b/gcc/testsuite/lib/modules.exp @@ -69,3 +69,32 @@ proc run-check-p1689-valid { depfile template } { clean-p1689 $testcase } + +proc run-check-module-dep { depfile flag expected } { + global srcdir subdir + # Extract the test file name from the arguments. + set testcase [file rootname [file tail $depfile]] + + verbose "Verifying dependencies for $testcase in $srcdir/$subdir" 2 + set testcase [remote_download host $testcase] + + set pytest_script "test-depfile.py" + if { ![check_effective_target_recent_python3] } { + unsupported "$pytest_script python3 is missing" + return + } + + verbose "running script test-depfile.py" 1 + spawn -noecho python3 $srcdir/$subdir/$pytest_script --all --depfile $depfile $flag $expected + + expect { + -re "ERROR: (\[^\r\n\]*)" { + fail $expect_out(0,string) + exp_continue + } + } +} + +proc run-check-module-dep-expect-input { depfile expected } { + run-check-module-dep $depfile "--expect-input" $expected +} From patchwork Sun Jul 2 16:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 115104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp48049vqx; Sun, 2 Jul 2023 09:39:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgN853LYK6BOSFUX6OhePU5Ln3pOm5hg34ju1p6LD/DgToIevrp3Eyj4+6/UwmzAw/8EEH X-Received: by 2002:a5d:668e:0:b0:313:ec05:3e30 with SMTP id l14-20020a5d668e000000b00313ec053e30mr6599886wru.45.1688315957880; Sun, 02 Jul 2023 09:39:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688315957; cv=none; d=google.com; s=arc-20160816; b=Dd9z2J3cHM/xcY1Ym2FdCITVwTWhzpt9jzjwaFbu4d6vbXhY4Y5y5I+lbCDXcINRkD 960CPwQRM7nu+8617vXTX/8fyLQ2953fc0IBSSqqatLYO7UyBVIDvZ3mHYQfL/L59K2q GGXU1pt9xEidA3T+cY4E8yqCc2B7e0CTQ2yrVnGqug0YeJe7PvEK0O+IQf1zeMWpLFTR E/XH9rCz+IS1+A0iFaVT3iAX/DEBzz/dSUnDBuNlj1TGMyE53q3tdNg7+4hPwvcSAOiG wyNF3yZQtMRtsTU/4yimiEob1tJdQSv2QOM8og5Y1M0bJb/opZAfZDsU/QoQ05wl+BJd jtRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=NgEU2HD9q9JtLPdHVPl0GIGGQyYGWzAvehAEMMI5mNg=; fh=WmOQlEQshjW1IyckmJV5Nh43dgdMAM2UcuXDxiXBGYo=; b=EVVm9Ei610O2sq2N+Ei7aFPy4v+wjtqo1kDBuc8eej+i/nnTUyMiStKx6EBvlOtPzF Zw5MJFzVyknq/D/SNeMyAwJ2SWfdqaAnnqtGjLYk4mJbxEbeg0BqJgufxQ3X6i1uoBPs Bdu3LKlf8YgiUjp7dtmcdNMn+dIiE0JT1fbC9Sj7Y9yZWd18CA75noyymSxhKpfMDEth a8qLz5nPB/6wLGzx4PZ3PDPgyVlolcA/+6yUVg5AHbKBirYE21c5iePfd8tpKW80qvSs l+Cprch/WlAsWF1jYDGiQ7dswUcvZPsh1Mz6s5q0shorqgbxMVPHEnVnogmRrrWRO0PR 3CNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="p/t3QNL6"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dy1-20020a05640231e100b0051dff4faa21si1932612edb.176.2023.07.02.09.39.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:39:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="p/t3QNL6"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2566A388B6B3 for ; Sun, 2 Jul 2023 16:35:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2566A388B6B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688315707; bh=NgEU2HD9q9JtLPdHVPl0GIGGQyYGWzAvehAEMMI5mNg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=p/t3QNL6GD3wtq8dZwyP47gO7w4r3pJfOxLOUjUnJ9rDwsHtD5d4HjPxDXiBZWW5s 2eWyZlo05OV74UHpPn1G4mikJDm3TcJdMb/MJy4KCi80qceOHDgASjkV5CHPlHLlAR NnNAsW2HE6YezMqXXElTTzePyvAcDbiJo+5U80Xg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id DF5403858425 for ; Sun, 2 Jul 2023 16:32:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF5403858425 Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-403392ce2b9so26415121cf.2 for ; Sun, 02 Jul 2023 09:32:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688315544; x=1690907544; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NgEU2HD9q9JtLPdHVPl0GIGGQyYGWzAvehAEMMI5mNg=; b=LRiRY/WQA005anh9/naLXstaJ3++FwvR7iZyhBxuNWHbJuyGlBIzSrGfyAgv8ssehk 5CmX8QgkzgUpBFHVePZj/RJLSlMCQW5I/akcLyyi2ypgHyK3BBigROondNnPv1sGcck1 X0WmqON2Q1Hfa5qKe9wokB+PSQU9kS9KFupJhFf5GENDQNfAuIbT/wPJNoU3zhBERDid ripdRp12BUM1ntqXIZcTYDEjZQC8aAYlaMr1AP4CmwR/eZjDH/WtwAiEoW66sSpRb7se nSbMPafK+dxhf2ytx1jnimWZtfo+bsdfc6mWA0qfKQc8HwGVE9LmWHprzJPOLdg0DGy3 W4QQ== X-Gm-Message-State: AC+VfDxYPhMZgiV2vN3cASml4975z6ff+a1AmQItNwHmiK3biODeZyx5 VHryI4EA1v0Yf/7ckUf7IMe3ltZr/7zMAmTPDA58fw== X-Received: by 2002:ac8:7d8f:0:b0:403:3ccc:39d3 with SMTP id c15-20020ac87d8f000000b004033ccc39d3mr9902458qtd.61.1688315544156; Sun, 02 Jul 2023 09:32:24 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id k25-20020ac84759000000b00402913ecba3sm6903348qtp.34.2023.07.02.09.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:32:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v7 4/4] c++modules: report module mapper files as a dependency Date: Sun, 2 Jul 2023 12:32:11 -0400 Message-Id: <20230702163211.3396210-5-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230702163211.3396210-1-ben.boeckel@kitware.com> References: <20230702163211.3396210-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770327594018133632?= X-GMAIL-MSGID: =?utf-8?q?1770327594018133632?= It affects the build, and if used as a static file, can reliably be tracked using the `-MF` mechanism. gcc/cp/: * mapper-client.cc, mapper-client.h (open_module_client): Accept dependency tracking and track module mapper files as dependencies. * module.cc (make_mapper, get_mapper): Pass the dependency tracking class down. gcc/testsuite/: * g++.dg/modules/depreport-2.modmap: New test. * g++.dg/modules/depreport-2_a.C: New test. * g++.dg/modules/depreport-2_b.C: New test. * g++.dg/modules/test-depfile.py: Support `:|` syntax output when generating modules. Signed-off-by: Ben Boeckel --- gcc/cp/mapper-client.cc | 5 +++++ gcc/cp/mapper-client.h | 1 + gcc/cp/module.cc | 18 ++++++++--------- .../g++.dg/modules/depreport-2.modmap | 2 ++ gcc/testsuite/g++.dg/modules/depreport-2_a.C | 15 ++++++++++++++ gcc/testsuite/g++.dg/modules/depreport-2_b.C | 14 +++++++++++++ gcc/testsuite/g++.dg/modules/test-depfile.py | 20 +++++++++++++++++++ 7 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2.modmap create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2_b.C diff --git a/gcc/cp/mapper-client.cc b/gcc/cp/mapper-client.cc index 39e80df2d25..92727195246 100644 --- a/gcc/cp/mapper-client.cc +++ b/gcc/cp/mapper-client.cc @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-core.h" #include "mapper-client.h" #include "intl.h" +#include "mkdeps.h" #include "../../c++tools/resolver.h" @@ -132,6 +133,7 @@ spawn_mapper_program (char const **errmsg, std::string &name, module_client * module_client::open_module_client (location_t loc, const char *o, + class mkdeps *deps, void (*set_repo) (const char *), char const *full_program_name) { @@ -285,6 +287,9 @@ module_client::open_module_client (location_t loc, const char *o, errmsg = "opening"; else { + /* Add the mapper file to the dependency tracking. */ + if (deps) + deps_add_dep (deps, name.c_str ()); if (int l = r->read_tuple_file (fd, ident, false)) { if (l > 0) diff --git a/gcc/cp/mapper-client.h b/gcc/cp/mapper-client.h index b32723ce296..a3b0b8adc51 100644 --- a/gcc/cp/mapper-client.h +++ b/gcc/cp/mapper-client.h @@ -55,6 +55,7 @@ public: public: static module_client *open_module_client (location_t loc, const char *option, + class mkdeps *, void (*set_repo) (const char *), char const *); static void close_module_client (location_t loc, module_client *); diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f3acc4e02fe..77c9edcbc04 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -3969,12 +3969,12 @@ static GTY(()) vec *partial_specializations; /* Our module mapper (created lazily). */ module_client *mapper; -static module_client *make_mapper (location_t loc); -inline module_client *get_mapper (location_t loc) +static module_client *make_mapper (location_t loc, class mkdeps *deps); +inline module_client *get_mapper (location_t loc, class mkdeps *deps) { auto *res = mapper; if (!res) - res = make_mapper (loc); + res = make_mapper (loc, deps); return res; } @@ -14033,7 +14033,7 @@ get_module (const char *ptr) /* Create a new mapper connecting to OPTION. */ module_client * -make_mapper (location_t loc) +make_mapper (location_t loc, class mkdeps *deps) { timevar_start (TV_MODULE_MAPPER); const char *option = module_mapper_name; @@ -14041,7 +14041,7 @@ make_mapper (location_t loc) option = getenv ("CXX_MODULE_MAPPER"); mapper = module_client::open_module_client - (loc, option, &set_cmi_repo, + (loc, option, deps, &set_cmi_repo, (save_decoded_options[0].opt_index == OPT_SPECIAL_program_name) && save_decoded_options[0].arg != progname ? save_decoded_options[0].arg : nullptr); @@ -19506,7 +19506,7 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc, dump.push (NULL); dump () && dump ("Checking include translation '%s'", path); - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); size_t len = strlen (path); path = canonicalize_header_name (NULL, loc, true, path, len); @@ -19622,7 +19622,7 @@ module_begin_main_file (cpp_reader *reader, line_maps *lmaps, static void name_pending_imports (cpp_reader *reader) { - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); if (!vec_safe_length (pending_imports)) /* Not doing anything. */ @@ -20092,7 +20092,7 @@ init_modules (cpp_reader *reader) if (!flag_module_lazy) /* Get the mapper now, if we're not being lazy. */ - get_mapper (cpp_main_loc (reader)); + get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); if (!flag_preprocess_only) { @@ -20302,7 +20302,7 @@ late_finish_module (cpp_reader *reader, module_processing_cookie *cookie, if (!errorcount) { - auto *mapper = get_mapper (cpp_main_loc (reader)); + auto *mapper = get_mapper (cpp_main_loc (reader), cpp_get_deps (reader)); mapper->ModuleCompiled (state->get_flatname ()); } else if (cookie->cmi_name) diff --git a/gcc/testsuite/g++.dg/modules/depreport-2.modmap b/gcc/testsuite/g++.dg/modules/depreport-2.modmap new file mode 100644 index 00000000000..ff271df883a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depreport-2.modmap @@ -0,0 +1,2 @@ +$root . +Foo Foo.gcm diff --git a/gcc/testsuite/g++.dg/modules/depreport-2_a.C b/gcc/testsuite/g++.dg/modules/depreport-2_a.C new file mode 100644 index 00000000000..6912de16333 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depreport-2_a.C @@ -0,0 +1,15 @@ +// { dg-do preprocess } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fmodule-mapper=[srcdir]/depreport-2.modmap } +// { dg-additional-options -MD } +// { dg-additional-options "-MF depreport-2_a.d" } + +export module Foo; + +export class Base +{ +public: + int m; +}; + +// { dg-final { run-check-module-dep-expect-input "depreport-2_a.d" "[srcdir]/depreport-2.modmap" } } diff --git a/gcc/testsuite/g++.dg/modules/depreport-2_b.C b/gcc/testsuite/g++.dg/modules/depreport-2_b.C new file mode 100644 index 00000000000..d94d6a297a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/depreport-2_b.C @@ -0,0 +1,14 @@ +// { dg-do preprocess } +// { dg-additional-options -fmodules-ts } +// { dg-additional-options -fmodule-mapper=[srcdir]/depreport-2.modmap } +// { dg-additional-options -MD } +// { dg-additional-options "-MF depreport-2_b.d" } + +import Foo; + +void foo () +{ + Base b; +} + +// { dg-final { run-check-module-dep-expect-input "depreport-2_b.d" "[srcdir]/depreport-2.modmap" } } diff --git a/gcc/testsuite/g++.dg/modules/test-depfile.py b/gcc/testsuite/g++.dg/modules/test-depfile.py index ea4edb61434..9693c058ece 100644 --- a/gcc/testsuite/g++.dg/modules/test-depfile.py +++ b/gcc/testsuite/g++.dg/modules/test-depfile.py @@ -28,6 +28,11 @@ class Input(Token): self.path = path +class OrderInput(Token): + def __init__(self, path): + self.path = path + + class Colon(Token): pass @@ -89,6 +94,10 @@ def validate_depfile(depfile, expect_input=None): if word.endswith(':'): tokenized.append(word[:-1]) word = word[-1] + # Detect `:` at the end of a word. + if word.endswith(':|'): + tokenized.append(word[:-2]) + word = word[-2] # Add word to the tokenized set. tokenized.append(word) @@ -104,6 +113,8 @@ def validate_depfile(depfile, expect_input=None): kind = 'dependency' elif token == '+=': kind = 'append' + elif token == ':|': + kind = 'order-only' if line == ['']: kind = 'empty' @@ -120,6 +131,15 @@ def validate_depfile(depfile, expect_input=None): line_parse.append(Input(token)) else: line_parse.append(Output(token)) + elif kind == 'order-only': + after_op = False + for token in line: + if token == ':|': + after_op = True + elif after_op: + line_parse.append(OrderInput(token)) + else: + line_parse.append(Output(token)) elif kind == 'append': after_op = False for token in line: