public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-7813] gccrs: import: Add cli extern crate resolution
Date: Tue, 16 Jan 2024 18:00:45 +0000 (GMT)	[thread overview]
Message-ID: <20240116180045.E5F6838582A7@sourceware.org> (raw)

https://gcc.gnu.org/g:e3360d2ba200e334a320cb8d49257e084b4e5233

commit r14-7813-ge3360d2ba200e334a320cb8d49257e084b4e5233
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Jun 14 15:20:21 2023 +0200

    gccrs: import: Add cli extern crate resolution
    
    This commit add the ability to specify the path to an extern crate
    through the -frust-extern cli option. Path given as cli argument
    shall resolve to the exact extern crate location.
    
    gcc/rust/ChangeLog:
    
            * metadata/rust-imports.h: Make the function to load a given
            file public.
            * rust-session-manager.cc (Session::load_extern_crate): Change
            path resolution depending on extern crate declaration in cli
            arguments.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/metadata/rust-imports.h |  4 ++--
 gcc/rust/rust-session-manager.cc | 20 +++++++++++++++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/metadata/rust-imports.h b/gcc/rust/metadata/rust-imports.h
index 51cc4fc7613..c728adbbbd1 100644
--- a/gcc/rust/metadata/rust-imports.h
+++ b/gcc/rust/metadata/rust-imports.h
@@ -112,6 +112,8 @@ public:
   static Stream *open_package (const std::string &filename, Location location,
 			       const std::string &relative_import_path);
 
+  static Stream *try_package_in_directory (const std::string &, Location);
+
   // Constructor.
   Import (Stream *, Location);
 
@@ -153,8 +155,6 @@ public:
   void clear_stream () { this->stream_ = NULL; }
 
 private:
-  static Stream *try_package_in_directory (const std::string &, Location);
-
   static int try_suffixes (std::string *);
 
   static Stream *find_export_data (const std::string &filename, int fd,
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index af57d577412..cc3a2089c1e 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -973,12 +973,26 @@ Session::load_extern_crate (const std::string &crate_name, location_t locus)
     }
 
   std::string relative_import_path = "";
-  Import::Stream *s
-    = Import::open_package (crate_name, locus, relative_import_path);
+  std::string import_name = crate_name;
+
+  // The path to the extern crate might have been specified by the user using
+  // -frust-extern
+  auto cli_extern_crate = extern_crates.find (crate_name);
+
+  Import::Stream *s;
+  if (cli_extern_crate != extern_crates.end ())
+    {
+      auto path = cli_extern_crate->second;
+      s = Import::try_package_in_directory (path, locus);
+    }
+  else
+    {
+      s = Import::open_package (import_name, locus, relative_import_path);
+    }
   if (s == NULL)
     {
       rust_error_at (locus, "failed to locate crate %<%s%>",
-		     crate_name.c_str ());
+		     import_name.c_str ());
       return UNKNOWN_NODEID;
     }

                 reply	other threads:[~2024-01-16 18:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116180045.E5F6838582A7@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).