| 644 | } |
| 645 | |
| 646 | void lgraph::SingleLanguagePluginManager::LoadAllPlugins(KvTransaction& txn) { |
| 647 | auto it = table_->GetIterator(txn); |
| 648 | for (it->GotoFirstKey(); it->IsValid(); it->Next()) { |
| 649 | if (!IsNameKey(it->GetKey().AsString())) continue; |
| 650 | std::string name = it->GetKey().AsString(); |
| 651 | try { |
| 652 | // load plugin info |
| 653 | std::unique_ptr<PluginInfoBase> pinfo(impl_->CreatePluginInfo()); |
| 654 | Value v = it->GetValue(); |
| 655 | fma_common::BinaryBuffer info(v.Data(), v.Size()); |
| 656 | fma_common::BinaryRead(info, *pinfo); |
| 657 | // write file |
| 658 | bool need_write_file = false; |
| 659 | { |
| 660 | // check if commit changes |
| 661 | if (!isHashUpTodate(txn, name)) need_write_file = true; |
| 662 | } |
| 663 | if (!need_write_file) { |
| 664 | // check if local file exist |
| 665 | std::string so_key = GetSoKey(name); |
| 666 | auto so_it = table_->GetIterator(txn, Value::ConstRef(so_key)); |
| 667 | FMA_DBG_ASSERT(so_it->IsValid()); |
| 668 | std::string path = impl_->GetPluginPath(name); |
| 669 | const std::string& so = so_it->GetValue().AsString(); |
| 670 | auto& fs = fma_common::FileSystem::GetFileSystem(path); |
| 671 | if (fs.FileExists(path)) { |
| 672 | std::string file_content = ReadWholeFile(path, "plugin binary file"); |
| 673 | if (file_content != so) need_write_file = true; |
| 674 | } else { |
| 675 | need_write_file = true; |
| 676 | } |
| 677 | } |
| 678 | // need_write_file might have changed |
| 679 | if (need_write_file) { |
| 680 | std::string zip_key = GetZipKey(name); |
| 681 | std::string cpp_key = GetCppKey(name); |
| 682 | std::string so_key = GetSoKey(name); |
| 683 | std::string cython_key = GetCythonKey(name); |
| 684 | if (table_->HasKey(txn, Value::ConstRef(zip_key))) { |
| 685 | auto zip_it = table_->GetIterator(txn, Value::ConstRef(zip_key)); |
| 686 | const std::string& zip = zip_it->GetValue().AsString(); |
| 687 | std::string exe = CompilePluginFromZip(name, zip); |
| 688 | WriteWholeFile(impl_->GetPluginPath(name), exe, ""); |
| 689 | UpdateSoToKvStore(txn, name, exe); |
| 690 | } else if (table_->HasKey(txn, Value::ConstRef(cpp_key))) { |
| 691 | auto file_it = table_->GetIterator(txn, Value::ConstRef(cpp_key)); |
| 692 | const std::string& file = file_it->GetValue().AsString(); |
| 693 | std::string exe = CompilePluginFromCpp(name, file); |
| 694 | WriteWholeFile(impl_->GetPluginPath(name), exe, ""); |
| 695 | UpdateSoToKvStore(txn, name, exe); |
| 696 | } else if (table_->HasKey(txn, Value::ConstRef(cython_key))) { |
| 697 | auto file_it = table_->GetIterator(txn, Value::ConstRef(cython_key)); |
| 698 | const std::string& file = file_it->GetValue().AsString(); |
| 699 | std::string exe = CompilePluginFromCython(name, file); |
| 700 | WriteWholeFile(impl_->GetPluginPath(name), exe, ""); |
| 701 | UpdateSoToKvStore(txn, name, exe); |
| 702 | } else if (table_->HasKey(txn, Value::ConstRef(so_key))) { |
| 703 | auto file_it = table_->GetIterator(txn, Value::ConstRef(so_key)); |
nothing calls this directly
no test coverage detected