From ab44003c26a5dc5c92145d491e51b7582d51a4f6 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Sun, 28 May 2023 09:44:39 -0400 Subject: Fix non-mod-rs files' external module loading paths gcc/rust/ChangeLog: * Make-lang.in: Add "rust-dir-owner.o". * ast/rust-ast.cc: Include "rust-dir-owner.h". (Module::process_file_path): Handle non-mod-rs external file modules properly. * parse/rust-parse-impl.h: Include "rust-dir-owner.h". (Parser::parse_module): Handle non-mod-rs external file modules properly. * util/rust-dir-owner.cc: New file. * util/rust-dir-owner.h: New file. gcc/testsuite/ChangeLog: * rust/compile/test_mod.rs: Moved to... * rust/compile/issue-1089/test_mod.rs: ...here. * rust/compile/mod_missing_middle.rs: Fix paths. * rust/compile/missing_middle/both_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/both_path.rs: ...here. * rust/compile/missing_middle/explicit.not.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/explicit.not.rs: ...here. * rust/compile/missing_middle/other.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/explicit.not/other.rs: ...here. * rust/compile/missing_middle/inner_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/inner_path.rs: ...here. * rust/compile/missing_middle/outer_path.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/outer_path.rs: ...here. * rust/compile/missing_middle/sub/mod.rs: Moved to... * rust/compile/mod_missing_middle/missing_middle/sub/mod.rs: ...here. * rust/compile/torture/modules/mod.rs: Moved to... * rust/compile/torture/extern_mod1/modules/mod.rs: ...here. * rust/execute/torture/modules/mod.rs: Moved to... * rust/execute/torture/extern_mod4/modules/mod.rs: ...here. Signed-off-by: Owen Avery --- gcc/rust/util/rust-dir-owner.cc | 42 +++++++++++++++++++++++++++++++++++++++++ gcc/rust/util/rust-dir-owner.h | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 gcc/rust/util/rust-dir-owner.cc create mode 100644 gcc/rust/util/rust-dir-owner.h (limited to 'gcc/rust/util') diff --git a/gcc/rust/util/rust-dir-owner.cc b/gcc/rust/util/rust-dir-owner.cc new file mode 100644 index 0000000..24bbe7b --- /dev/null +++ b/gcc/rust/util/rust-dir-owner.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC 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, or (at your option) any later +// version. + +// GCC 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 +// . + +// Handles non-mod-rs and mod-rs file differentiation + +#include "rust-system.h" +#include "rust-dir-owner.h" + +namespace Rust { + +// extracts the owned subdirectory name from a file name +bool +get_file_subdir (const std::string &filename, std::string &subdir) +{ + // directory owning filenames + if (filename == "mod.rs" || filename == "lib.rs" || filename == "main.rs") + return false; + + // files not ending in ".rs" are directory owners + if (filename.size () < 3 || filename.compare (filename.size () - 3, 3, ".rs")) + return false; + + subdir = filename.substr (0, filename.size () - 3); + return true; +} + +} // namespace Rust diff --git a/gcc/rust/util/rust-dir-owner.h b/gcc/rust/util/rust-dir-owner.h new file mode 100644 index 0000000..0134f54 --- /dev/null +++ b/gcc/rust/util/rust-dir-owner.h @@ -0,0 +1,34 @@ +// Copyright (C) 2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC 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, or (at your option) any later +// version. + +// GCC 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 +// . + +// Handles non-mod-rs and mod-rs file differentiation + +#ifndef RUST_DIR_OWNER +#define RUST_DIR_OWNER + +#include "rust-system.h" + +namespace Rust { + +// extracts the owned subdirectory name from a file name +bool +get_file_subdir (const std::string &filename, std::string &subdir); + +} // namespace Rust + +#endif // RUST_DIR_OWNER -- cgit v1.1