From 252b1551dca2ac8fa5d7d879636e0f60a0a10b2e Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 10 May 2019 23:43:57 +0200 Subject: [PATCH] Bugfix: strmrun issues - strmrun did not support x[rb] notation for file type - x.y.py was rejected because y.py was taken as the suffix - reason was extension() function for which there is an extension_last() now - but this function is no longer used as the lym::Macro object is used now --- src/buddies/src/bd/bd.pro | 6 +++--- src/buddies/src/bd/strmrun.cc | 14 ++++---------- src/tl/tl/tlFileUtils.cc | 10 ++++++++++ src/tl/tl/tlFileUtils.h | 5 +++++ src/tl/unit_tests/tlFileUtils.cc | 7 +++++++ 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/buddies/src/bd/bd.pro b/src/buddies/src/bd/bd.pro index 1b80e94f2..3ec14b734 100644 --- a/src/buddies/src/bd/bd.pro +++ b/src/buddies/src/bd/bd.pro @@ -31,9 +31,9 @@ HEADERS = \ RESOURCES = \ -INCLUDEPATH += $$TL_INC $$GSI_INC $$VERSION_INC $$DB_INC $$LIB_INC $$RDB_INC -DEPENDPATH += $$TL_INC $$GSI_INC $$VERSION_INC $$DB_INC $$LIB_INC $$RDB_INC -LIBS += -L$$DESTDIR -lklayout_tl -lklayout_db -lklayout_gsi -lklayout_lib -lklayout_rdb +INCLUDEPATH += $$TL_INC $$GSI_INC $$VERSION_INC $$DB_INC $$LIB_INC $$RDB_INC $$LYM_INC +DEPENDPATH += $$TL_INC $$GSI_INC $$VERSION_INC $$DB_INC $$LIB_INC $$RDB_INC $$LYM_INC +LIBS += -L$$DESTDIR -lklayout_tl -lklayout_db -lklayout_gsi -lklayout_lib -lklayout_rdb -lklayout_lym INCLUDEPATH += $$RBA_INC DEPENDPATH += $$RBA_INC diff --git a/src/buddies/src/bd/strmrun.cc b/src/buddies/src/bd/strmrun.cc index 9437162be..130c75c10 100644 --- a/src/buddies/src/bd/strmrun.cc +++ b/src/buddies/src/bd/strmrun.cc @@ -34,6 +34,7 @@ #include "gsiExpression.h" #include "libForceLink.h" #include "rdbForceLink.h" +#include "lymMacro.h" struct RunnerData { @@ -92,14 +93,7 @@ BD_PUBLIC int strmrun (int argc, char *argv[]) std::string script = tl::absolute_file_path (data.script); - std::string ext = tl::extension (data.script); - if (ext == "py") { - python.load_file (script); - } else if (ext == "rb") { - ruby.load_file (script); - } else { - throw tl::Exception (tl::to_string (tr ("Unknown suffix \"%s\" - must be either .rb or .py")), ext); - } - - return 0; + lym::Macro macro; + macro.load_from (script); + return macro.run (); } diff --git a/src/tl/tl/tlFileUtils.cc b/src/tl/tl/tlFileUtils.cc index 79adf0155..303b07b4f 100644 --- a/src/tl/tl/tlFileUtils.cc +++ b/src/tl/tl/tlFileUtils.cc @@ -308,6 +308,16 @@ std::string extension (const std::string &s) return tl::join (fnp, "."); } +std::string extension_last (const std::string &s) +{ + std::vector fnp = split_filename (filename (s)); + if (fnp.size () > 1) { + return fnp.back (); + } else { + return std::string (); + } +} + bool is_parent_path (const std::string &parent, const std::string &path) { diff --git a/src/tl/tl/tlFileUtils.h b/src/tl/tl/tlFileUtils.h index da2470591..766ffc819 100644 --- a/src/tl/tl/tlFileUtils.h +++ b/src/tl/tl/tlFileUtils.h @@ -90,6 +90,11 @@ std::string TL_PUBLIC basename (const std::string &s); */ std::string TL_PUBLIC extension (const std::string &s); +/** + * @brief Gets the last extension for a given file path + */ +std::string TL_PUBLIC extension_last (const std::string &s); + /** * @brief Returns true, if the given path exists * If the path is a directory, file_exists will return true, if the directory exists. diff --git a/src/tl/unit_tests/tlFileUtils.cc b/src/tl/unit_tests/tlFileUtils.cc index bf3f2ea9f..9b57c3176 100644 --- a/src/tl/unit_tests/tlFileUtils.cc +++ b/src/tl/unit_tests/tlFileUtils.cc @@ -391,6 +391,13 @@ TEST (10) EXPECT_EQ (tl::extension ("\\hello\\.world.gz"), "gz"); EXPECT_EQ (tl::extension ("/hello//world/"), ""); + EXPECT_EQ (tl::extension_last ("/hello/world"), ""); + EXPECT_EQ (tl::extension_last ("/hello/world.tar"), "tar"); + EXPECT_EQ (tl::extension_last ("/hello/world.tar.gz"), "gz"); + EXPECT_EQ (tl::extension_last ("\\hello\\.world"), ""); + EXPECT_EQ (tl::extension_last ("\\hello\\.world.gz"), "gz"); + EXPECT_EQ (tl::extension_last ("/hello//world/"), ""); + EXPECT_EQ (tl::is_absolute ("world"), false); EXPECT_EQ (tl::is_absolute ("world/"), false); EXPECT_EQ (tl::is_absolute ("hello//world/"), false);