]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Remove legacy args API
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 7 May 2020 17:44:26 +0000 (19:44 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 7 May 2020 17:44:26 +0000 (19:44 +0200)
Makefile.in
src/Args.cpp
src/Args.hpp
unittest/main.cpp
unittest/test_legacy_args.cpp [deleted file]

index 2ac06c80ebcdcbecf163f96d83d3c95607b4b749..a5094f0353226c9d8809a099d0b6d9edb702feec 100644 (file)
@@ -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
index 00a1e3234f26539b8e33ca4b86052e5a4f2b77de..9eff36be4f450571b9bfd21715fb2ba15926b672 100644 (file)
 
 #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<std::string>& 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>
-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);
-}
index cd2a2849f820cce833adde393bf1804672f8ed9a..be917ec75dd4dc735d51455ff23dbaa1400550aa 100644 (file)
 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<Args> 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<char* const*>(args.to_argv().data())` to get an array
   // suitable to pass to e.g. execv(2).
@@ -90,23 +86,6 @@ public:
 
 private:
   std::deque<std::string> m_args;
-
-public:
-  // Wrapper for legacy API:
-  class ArgvAccessWrapper
-  {
-  public:
-    friend Args;
-
-    ArgvAccessWrapper(const std::deque<std::string>& args);
-
-    const char* operator[](size_t i) const;
-
-  private:
-    const std::deque<std::string>* 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> 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);
index d6ddb2d652cf59348c9f5ca5f6ead60fb492085f..2b46a43f3f077a278fad4e91e56a0c3be2aaffb9 100644 (file)
@@ -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 (file)
index 20102e7..0000000
+++ /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