From: Joel Rosdahl Date: Thu, 7 May 2020 17:44:26 +0000 (+0200) Subject: Remove legacy args API X-Git-Tag: v4.0~477 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad5a36e9c3e0b4e2a57745f197f4ef29cc37a67d;p=thirdparty%2Fccache.git Remove legacy args API --- diff --git a/Makefile.in b/Makefile.in index 2ac06c80e..a5094f035 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,7 +97,6 @@ test_suites += unittest/test_argument_processing.cpp test_suites += unittest/test_compopt.cpp test_suites += unittest/test_hash.cpp test_suites += unittest/test_hashutil.cpp -test_suites += unittest/test_legacy_args.cpp test_suites += unittest/test_legacy_util.cpp test_sources += unittest/catch2_tests.cpp diff --git a/src/Args.cpp b/src/Args.cpp index 00a1e3234..9eff36be4 100644 --- a/src/Args.cpp +++ b/src/Args.cpp @@ -20,16 +20,7 @@ #include "Util.hpp" -Args::Args() : argv(m_args) -{ -} - -Args::Args(const Args& other) : m_args(other.m_args), argv(m_args) -{ -} - -Args::Args(Args&& other) noexcept - : m_args(std::move(other.m_args)), argv(m_args) +Args::Args(Args&& other) noexcept : m_args(std::move(other.m_args)) { } @@ -126,22 +117,11 @@ Args::from_gcc_atfile(const std::string& filename) } } -Args& -Args::operator=(const Args& other) -{ - if (&other != this) { - m_args = other.m_args; - argv.m_args = &m_args; - } - return *this; -} - Args& Args::operator=(Args&& other) noexcept { if (&other != this) { m_args = std::move(other.m_args); - argv.m_args = &m_args; } return *this; } @@ -232,94 +212,3 @@ Args::replace(size_t index, const Args& args) insert(index, args); } } - -Args::ArgvAccessWrapper::ArgvAccessWrapper(const std::deque& args) - : m_args(&args) -{ -} - -// clang-format off -const char* -Args::ArgvAccessWrapper::operator[](size_t i) const -// clang-format on -{ - return i == m_args->size() ? nullptr : m_args->at(i).c_str(); -} - -// === Wrapper functions for the legacy API: === - -void -args_add(Args& args, const std::string& arg) -{ - args.push_back(arg); -} - -void -args_add_prefix(Args& args, const std::string& arg) -{ - args.push_front(arg); -} - -Args -args_copy(const Args& args) -{ - return args; -} - -void -args_extend(Args& args, const Args& to_append) -{ - args.push_back(to_append); -} - -Args -args_init(int argc, const char* const* argv) -{ - return Args::from_argv(argc, argv); -} - -nonstd::optional -args_init_from_gcc_atfile(const std::string& filename) -{ - return Args::from_gcc_atfile(filename); -} - -Args -args_init_from_string(const std::string& s) -{ - return Args::from_string(s); -} - -void -args_insert(Args& args, size_t index, const Args& to_insert, bool replace) -{ - if (replace) { - args.replace(index, to_insert); - } else { - args.insert(index, to_insert); - } -} - -void -args_pop(Args& args, size_t count) -{ - args.pop_back(count); -} - -void -args_remove_first(Args& args) -{ - args.pop_front(1); -} - -void -args_set(Args& args, size_t index, const std::string& value) -{ - args[index] = value; -} - -void -args_strip(Args& args, nonstd::string_view prefix) -{ - args.erase_with_prefix(prefix); -} diff --git a/src/Args.hpp b/src/Args.hpp index cd2a2849f..be917ec75 100644 --- a/src/Args.hpp +++ b/src/Args.hpp @@ -32,15 +32,15 @@ class Args { public: - Args(); - Args(const Args& other); + Args() = default; + Args(const Args& other) = default; Args(Args&& other) noexcept; static Args from_argv(int argc, const char* const* argv); static Args from_string(const std::string& command); static nonstd::optional from_gcc_atfile(const std::string& filename); - Args& operator=(const Args& other); + Args& operator=(const Args& other) = default; Args& operator=(Args&& other) noexcept; bool operator==(const Args& other) const; @@ -51,10 +51,6 @@ public: const std::string& operator[](size_t i) const; std::string& operator[](size_t i); - // Accessor functions for the legacy API: - Args& operator*(); - const Args* operator->() const; - // Return the argument list as a vector of raw string pointers. Callers can // use `const_cast(args.to_argv().data())` to get an array // suitable to pass to e.g. execv(2). @@ -90,23 +86,6 @@ public: private: std::deque m_args; - -public: - // Wrapper for legacy API: - class ArgvAccessWrapper - { - public: - friend Args; - - ArgvAccessWrapper(const std::deque& args); - - const char* operator[](size_t i) const; - - private: - const std::deque* m_args; - }; - - ArgvAccessWrapper argv; }; inline bool @@ -148,33 +127,3 @@ Args::operator[](size_t i) { return m_args[i]; } - -// clang-format off -inline Args& -Args::operator*() -// clang-format on -{ - return *this; -} - -// clang-format off -inline const Args* -Args::operator->() const -// clang-format on -{ - return this; -} - -// Wrapper functions for the legacy API: -void args_add(Args& args, const std::string& arg); -void args_add_prefix(Args& args, const std::string& arg); -Args args_copy(const Args& args); -void args_extend(Args& args, const Args& to_append); -Args args_init(int argc, const char* const* argv); -nonstd::optional args_init_from_gcc_atfile(const std::string& filename); -Args args_init_from_string(const std::string& s); -void args_insert(Args& args, size_t index, const Args& to_insert, bool replace); -void args_pop(Args& args, size_t count); -void args_remove_first(Args& args); -void args_set(Args& args, size_t index, const std::string& value); -void args_strip(Args& args, nonstd::string_view prefix); diff --git a/unittest/main.cpp b/unittest/main.cpp index d6ddb2d65..2b46a43f3 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -21,7 +21,6 @@ #include "catch2_tests.hpp" #include "framework.hpp" -unsigned suite_args(unsigned); unsigned suite_argument_processing(unsigned); unsigned suite_compopt(unsigned); unsigned suite_conf(unsigned); @@ -30,7 +29,6 @@ unsigned suite_hashutil(unsigned); unsigned suite_legacy_util(unsigned); const suite_fn k_legacy_suites[] = { - &suite_args, &suite_argument_processing, &suite_compopt, &suite_hash, diff --git a/unittest/test_legacy_args.cpp b/unittest/test_legacy_args.cpp deleted file mode 100644 index 20102e7af..000000000 --- a/unittest/test_legacy_args.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (C) 2010-2020 Joel Rosdahl and other contributors -// -// See doc/AUTHORS.adoc for a complete list of contributors. -// -// This program 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 of the License, or (at your option) -// any later version. -// -// This program 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 -// this program; if not, write to the Free Software Foundation, Inc., 51 -// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -// This file contains tests for the functions operating on struct args. - -#include "../src/Args.hpp" -#include "framework.hpp" -#include "util.hpp" - -TEST_SUITE(args) - -TEST(args_init_empty) -{ - Args args; - CHECK_INT_EQ(0, args.size()); - CHECK(!args->argv[0]); -} - -TEST(args_init_populated) -{ - const char* argv[] = {"first", "second", nullptr}; - Args args = Args::from_argv(2, argv); - CHECK_INT_EQ(2, args.size()); - CHECK_STR_EQ("first", args->argv[0]); - CHECK_STR_EQ("second", args->argv[1]); - CHECK(!args->argv[2]); -} - -TEST(args_init_from_string) -{ - Args args = args_init_from_string("first second\tthird\nfourth"); - CHECK_INT_EQ(4, args.size()); - CHECK_STR_EQ("first", args->argv[0]); - CHECK_STR_EQ("second", args->argv[1]); - CHECK_STR_EQ("third", args->argv[2]); - CHECK_STR_EQ("fourth", args->argv[3]); - CHECK(!args->argv[4]); -} - -TEST(args_init_from_gcc_atfile) -{ - const char* argtext = - "first\rsec\\\tond\tthi\\\\rd\nfourth \tfif\\ th \"si'x\\\" th\"" - " 'seve\nth'\\"; - - create_file("gcc_atfile", argtext); - - Args args = *args_init_from_gcc_atfile("gcc_atfile"); - CHECK_INT_EQ(7, args->size()); - CHECK_STR_EQ("first", args->argv[0]); - CHECK_STR_EQ("sec\tond", args->argv[1]); - CHECK_STR_EQ("thi\\rd", args->argv[2]); - CHECK_STR_EQ("fourth", args->argv[3]); - CHECK_STR_EQ("fif th", args->argv[4]); - CHECK_STR_EQ("si'x\" th", args->argv[5]); - CHECK_STR_EQ("seve\nth", args->argv[6]); - CHECK(!args->argv[7]); -} - -TEST(args_copy) -{ - Args args1 = args_init_from_string("foo"); - Args args2 = args1; - CHECK_ARGS_EQ_FREE12(args1, args2); -} - -TEST(args_add) -{ - Args args = args_init_from_string("first"); - CHECK_INT_EQ(1, args.size()); - args_add(args, "second"); - CHECK_INT_EQ(2, args.size()); - CHECK_STR_EQ("second", args->argv[1]); - CHECK(!args->argv[2]); -} - -TEST(args_extend) -{ - Args args1 = args_init_from_string("first"); - Args args2 = args_init_from_string("second third"); - CHECK_INT_EQ(1, args1.size()); - args_extend(args1, args2); - CHECK_INT_EQ(3, args1.size()); - CHECK_STR_EQ("second", args1->argv[1]); - CHECK_STR_EQ("third", args1->argv[2]); - CHECK(!args1->argv[3]); -} - -TEST(args_pop) -{ - Args args = args_init_from_string("first second third"); - args_pop(args, 2); - CHECK_INT_EQ(1, args.size()); - CHECK_STR_EQ("first", args->argv[0]); - CHECK(!args->argv[1]); -} - -TEST(args_set) -{ - Args args = args_init_from_string("first second third"); - args_set(args, 1, "2nd"); - CHECK_INT_EQ(3, args.size()); - CHECK_STR_EQ("first", args->argv[0]); - CHECK_STR_EQ("2nd", args->argv[1]); - CHECK_STR_EQ("third", args->argv[2]); - CHECK(!args->argv[3]); -} - -TEST(args_remove_first) -{ - Args args1 = args_init_from_string("first second third"); - Args args2 = args_init_from_string("second third"); - args_remove_first(args1); - CHECK_ARGS_EQ_FREE12(args1, args2); -} - -TEST(args_add_prefix) -{ - Args args1 = args_init_from_string("second third"); - Args args2 = args_init_from_string("first second third"); - args_add_prefix(args1, "first"); - CHECK_ARGS_EQ_FREE12(args1, args2); -} - -TEST(args_strip) -{ - Args args1 = args_init_from_string("first xsecond third xfourth"); - Args args2 = args_init_from_string("first third"); - args_strip(args1, "x"); - CHECK_ARGS_EQ_FREE12(args1, args2); -} - -TEST(args_to_string) -{ - Args args = args_init_from_string("first second"); - CHECK_STR_EQ("first second", args.to_string().c_str()); -} - -TEST(args_insert) -{ - Args args = args_init_from_string("first second third fourth fifth"); - - Args src1 = args_init_from_string("alpha beta gamma"); - Args src2 = args_init_from_string("one"); - Args src3 = args_init_from_string(""); - Args src4 = args_init_from_string("alpha beta gamma"); - Args src5 = args_init_from_string("one"); - Args src6 = args_init_from_string(""); - - args_insert(args, 2, src1, true); - CHECK_STR_EQ("first second alpha beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(7, args.size()); - args_insert(args, 2, src2, true); - CHECK_STR_EQ("first second one beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(7, args.size()); - args_insert(args, 2, src3, true); - CHECK_STR_EQ("first second beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(6, args.size()); - - args_insert(args, 1, src4, false); - CHECK_STR_EQ("first alpha beta gamma second beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(9, args.size()); - args_insert(args, 1, src5, false); - CHECK_STR_EQ("first one alpha beta gamma second beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(10, args.size()); - args_insert(args, 1, src6, false); - CHECK_STR_EQ("first one alpha beta gamma second beta gamma fourth fifth", - args.to_string().c_str()); - CHECK_INT_EQ(10, args.size()); -} - -TEST_SUITE_END