diff --git a/CMakeLists.txt b/CMakeLists.txt index c3a8b99..e256554 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ # limitations under the License.! cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -file(STRINGS "VERSION" SPM_VERSION) +file(STRINGS "VERSION.txt" SPM_VERSION) message(STATUS "VERSION: ${SPM_VERSION}") project(sentencepiece VERSION ${SPM_VERSION} LANGUAGES C CXX) diff --git a/VERSION b/VERSION.txt similarity index 100% rename from VERSION rename to VERSION.txt diff --git a/python/VERSION b/python/VERSION.txt similarity index 100% rename from python/VERSION rename to python/VERSION.txt diff --git a/python/setup.py b/python/setup.py index 1e9bf07..9551ad9 100755 --- a/python/setup.py +++ b/python/setup.py @@ -33,7 +33,7 @@ def long_description(): def version(): - with codecs.open('VERSION', 'r', 'utf-8') as f: + with codecs.open('VERSION.txt', 'r', 'utf-8') as f: version = f.read().rstrip() return version diff --git a/src/common.h b/src/common.h index af0b1c2..7c6c43c 100644 --- a/src/common.h +++ b/src/common.h @@ -132,6 +132,9 @@ enum LogSeverity { LOG_SEVERITY_SIZE = 4, }; +int GetMinLogLevel(); +void SetMinLogLevel(int v); + inline const char *BaseName(const char *path) { #ifdef OS_WIN const char *p = strrchr(path, '\\'); @@ -144,10 +147,8 @@ inline const char *BaseName(const char *path) { } // namespace logging } // namespace sentencepiece -ABSL_DECLARE_FLAG(int32, minloglevel); - #define LOG(severity) \ - (absl::GetFlag(FLAGS_minloglevel) > \ + (::sentencepiece::logging::GetMinLogLevel() > \ ::sentencepiece::logging::LOG_##severity) \ ? 0 \ : ::sentencepiece::error::Die( \ diff --git a/src/init.cc b/src/init.cc index f1800c5..09de112 100644 --- a/src/init.cc +++ b/src/init.cc @@ -14,8 +14,11 @@ #include "init.h" +#include "common.h" #include "third_party/absl/flags/flag.h" +ABSL_DECLARE_FLAG(int32, minloglevel); + namespace sentencepiece { void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, @@ -28,5 +31,7 @@ void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, std::copy(unused_args.begin(), unused_args.end(), argv_val); *argc = static_cast(unused_args.size()); } + + logging::SetMinLogLevel(absl::GetFlag(FLAGS_minloglevel)); } } // namespace sentencepiece diff --git a/src/sentencepiece_trainer.cc b/src/sentencepiece_trainer.cc index bb4a9c7..429d0f4 100644 --- a/src/sentencepiece_trainer.cc +++ b/src/sentencepiece_trainer.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License.! +#include "sentencepiece_trainer.h" + #include #include @@ -20,9 +22,7 @@ #include "normalizer.h" #include "sentencepiece.pb.h" #include "sentencepiece_model.pb.h" -#include "sentencepiece_trainer.h" #include "spec_parser.h" -#include "third_party/absl/flags/flag.h" #include "third_party/absl/strings/numbers.h" #include "third_party/absl/strings/str_cat.h" #include "third_party/absl/strings/str_split.h" @@ -31,8 +31,6 @@ #include "trainer_factory.h" #include "util.h" -ABSL_DECLARE_FLAG(int, minloglevel); - namespace sentencepiece { namespace { static constexpr char kDefaultNormalizerName[] = "nmt_nfkc"; @@ -151,7 +149,7 @@ util::Status SentencePieceTrainer::MergeSpecsFromArgs( } else if (key == "minloglevel") { int v = 0; CHECK_OR_RETURN(absl::SimpleAtoi(value, &v)); - absl::SetFlag(&FLAGS_minloglevel, v); + logging::SetMinLogLevel(v); continue; } diff --git a/src/util.cc b/src/util.cc index 58225ae..9120673 100644 --- a/src/util.cc +++ b/src/util.cc @@ -20,6 +20,7 @@ namespace sentencepiece { namespace { constexpr unsigned int kDefaultSeed = static_cast(-1); static unsigned int g_seed = kDefaultSeed; +static int g_minloglevel = 0; } // namespace void SetRandomGeneratorSeed(unsigned int seed) { @@ -30,6 +31,11 @@ uint32 GetRandomGeneratorSeed() { return g_seed == kDefaultSeed ? std::random_device{}() : g_seed; } +namespace logging { +int GetMinLogLevel() { return g_minloglevel; } +void SetMinLogLevel(int v) { g_minloglevel = v; } +} // namespace logging + namespace string_util { // mblen sotres the number of bytes consumed after decoding.