!28849 Export the bprop mindir when the bprop directory is symbolic link

Merge pull request !28849 from YuJianfeng/r1.6
This commit is contained in:
i-robot 2022-01-11 10:40:56 +00:00 committed by Gitee
commit 0926d1ebec
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 6 additions and 1 deletions

View File

@ -285,9 +285,14 @@ std::string GetBpropFileHash(const py::function &fn) {
static auto bprop_hash_to_file = GetAllBpropFileHash();
// Get the file where the bprop function is defined.
auto filename = fn.attr("__code__").attr("co_filename").cast<std::string>();
auto realpath = FileUtils::GetRealPath(common::SafeCStr(filename));
if (!realpath.has_value()) {
MS_LOG(ERROR) << "Failed to get the realpath of file: " << filename;
return "";
}
// Get the hash of the file.
auto it = std::find_if(bprop_hash_to_file.begin(), bprop_hash_to_file.end(),
[&filename](const auto &item) { return item.second == filename; });
[&realpath](const auto &item) { return item.second == realpath.value(); });
if (it != bprop_hash_to_file.end()) {
return it->first;
}