public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, test/, utils/, src/builtins/
@ 2011-04-28  6:19 Petteri Räty
  0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-04-28  6:19 UTC (permalink / raw
  To: gentoo-commits

commit:     9d812d19cbcfe79cdbf5daa5b42cab1c2436902b
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 21 14:36:54 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Thu Apr 28 03:09:04 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=9d812d19

Builtin: implement inherit builtin

metadata_generator is improved to make use of the information added
by inherit builtin.

---
 Makefile.am                              |    3 +
 scripts/foo.eclass                       |    5 +
 scripts/sunpinyin-2.0.3-r1.ebuild        |    2 +
 scripts/sunpinyin-2.0.3-r1.ebuild.result |   10 +-
 src/builtins/inherit_builtin.cpp         |  130 ++++++++++++++++++++++++++++++
 src/builtins/inherit_builtin.h           |   55 +++++++++++++
 src/cppbash_builtin.cpp                  |    2 +
 test/ebuild_compiler.sh                  |    2 +-
 utils/metadata_generator.cpp             |   40 +++++++---
 9 files changed, 232 insertions(+), 17 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 5518599..a3890bb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -161,6 +161,8 @@ libcppbash_la_SOURCES = src/common.h \
 						src/builtins/boolean_builtins.h \
 						src/builtins/source_builtin.h \
 						src/builtins/source_builtin.cpp \
+						src/builtins/inherit_builtin.h \
+						src/builtins/inherit_builtin.cpp \
 						$(GENERATED_PARSER_C) \
 						$(GENERATED_PARSER_H) \
 						src/core/interpreter_exception.h \
@@ -188,6 +190,7 @@ EXTRA_DIST = bashast/bashast.g \
 			 scripts/source_false.sh \
 			 scripts/source_true.sh \
 			 utils/meta_gen.sh \
+			 scripts/foo.eclass \
 			 $(BASH_TESTS) \
 			 $(BASH_RESULT) \
 			 $(EBUILD_TESTS) \

diff --git a/scripts/foo.eclass b/scripts/foo.eclass
new file mode 100644
index 0000000..1e46230
--- /dev/null
+++ b/scripts/foo.eclass
@@ -0,0 +1,5 @@
+IUSE="abc def"
+REQUIRED_USE="abc"
+DEPEND="dev-util/pkgconfig"
+RDEPEND="foo/bar"
+PDEPEND="foo/bar"

diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild b/scripts/sunpinyin-2.0.3-r1.ebuild
index 686121c..319e5ee 100644
--- a/scripts/sunpinyin-2.0.3-r1.ebuild
+++ b/scripts/sunpinyin-2.0.3-r1.ebuild
@@ -1,5 +1,7 @@
 EAPI="1"
 
+inherit foo
+
 DESCRIPTION="SunPinyin is a SLM (Statistical Language Model) based IME"
 HOMEPAGE="http://sunpinyin.googlecode.com"
 SRC_URI="${HOMEPAGE}/files/${P}.tar.gz

diff --git a/scripts/sunpinyin-2.0.3-r1.ebuild.result b/scripts/sunpinyin-2.0.3-r1.ebuild.result
index 41f016e..7c8c13b 100644
--- a/scripts/sunpinyin-2.0.3-r1.ebuild.result
+++ b/scripts/sunpinyin-2.0.3-r1.ebuild.result
@@ -1,5 +1,5 @@
 dev-db/sqlite:3 dev-util/pkgconfig
-dev-db/sqlite:3
+dev-db/sqlite:3 foo/bar
 0
 http://sunpinyin.googlecode.com/files/.tar.gz http://open-gram.googlecode.com/files/dict.utf8.tar.bz2 http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2
 
@@ -7,10 +7,10 @@ http://sunpinyin.googlecode.com
 LGPL-2.1 CDDL
 SunPinyin is a SLM (Statistical Language Model) based IME
 ~amd64 ~x86
-
-
-
-
+foo
+abc def
+abc
+foo/bar
 
 1
 

diff --git a/src/builtins/inherit_builtin.cpp b/src/builtins/inherit_builtin.cpp
new file mode 100644
index 0000000..ac11cfc
--- /dev/null
+++ b/src/builtins/inherit_builtin.cpp
@@ -0,0 +1,130 @@
+/*
+   Please use git log for copyright holder and year information
+
+   This file is part of libbash.
+
+   libbash 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 2 of the License, or
+   (at your option) any later version.
+
+   libbash 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 libbash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file inherit_builtin.cpp
+/// \author Mu Qiao
+/// \brief class that implements the inherit builtin
+///
+
+#include "builtins/inherit_builtin.h"
+
+#include <cstdlib>
+
+#include <string>
+
+#include "core/interpreter.h"
+
+inline void inherit_builtin::append_global(const std::string& name)
+{
+    if(!_walker.is_unset_or_null(name, 0))
+      _walker.set_value("E_" + name, _walker.resolve<std::string>("E_"+name) + _walker.resolve<std::string>(name));
+}
+
+inline void inherit_builtin::restore_global(const std::string& name, const std::string& value)
+{
+  if(value != "")
+    _walker.set_value(name, value);
+  else
+    _walker.unset(name);
+}
+
+inline void inherit_builtin::backup_global(const std::string& name, std::string& value)
+{
+  value = _walker.resolve<std::string>(name);
+  _walker.unset(name);
+}
+
+inline bool inherit_builtin::hasq(const std::string& value, const std::string& name)
+{
+  const std::string& target = _walker.resolve<std::string>(name);
+  return target.find(value) != std::string::npos;
+}
+
+// We do not support any QA warning
+int inherit_builtin::exec(const std::vector<std::string>& bash_args)
+{
+  _walker.pre_incr("ECLASS_DEPTH", 0);
+
+  // find eclass directory
+  std::string eclassdir;
+  if(getenv("ECLASSDIR"))
+    eclassdir = getenv("ECLASSDIR") + std::string("/");
+  else
+    eclassdir = "/usr/portage/eclass/";
+
+  std::string location;
+  std::string export_funcs_var;
+  // These variables must be restored before returning
+  std::string PECLASS(_walker.resolve<std::string>("ECLASS"));
+  std::string prev_export_funcs_var(_walker.resolve<std::string>("__export_funcs_var"));
+
+  std::string B_IUSE;
+  std::string B_REQUIRED_USE;
+  std::string B_DEPEND;
+  std::string B_RDEPEND;
+  std::string B_PDEPEND;
+
+  for(auto iter = bash_args.begin(); iter != bash_args.end(); ++iter)
+  {
+    location = eclassdir + *iter + ".eclass";
+    _walker.set_value("ECLASS", *iter);
+    export_funcs_var = "__export_functions_" + _walker.resolve<std::string>("ECLASS_DEPTH");
+    _walker.unset(export_funcs_var);
+
+    // Portage implementation performs actions for overlays here but we don't do it for now
+
+    backup_global("IUSE", B_IUSE);
+    backup_global("REQUIRED_USE", B_REQUIRED_USE);
+    backup_global("DEPEND", B_DEPEND);
+    backup_global("RDEPEND", B_RDEPEND);
+    backup_global("PDEPEND", B_PDEPEND);
+
+    _walker.execute_builtin("source", {location});
+
+    append_global("IUSE");
+    append_global("REQUIRED_USE");
+    append_global("DEPEND");
+    append_global("RDEPEND");
+    append_global("PDEPEND");
+
+    restore_global("IUSE", B_IUSE);
+    restore_global("REQUIRED_USE", B_REQUIRED_USE);
+    restore_global("DEPEND", B_DEPEND);
+    restore_global("RDEPEND", B_RDEPEND);
+    restore_global("PDEPEND", B_PDEPEND);
+
+    // Portage implementation exports functions here but we don't do it for now
+
+    if(!hasq(*iter, "INHERITED"))
+      _walker.set_value("INHERITED", _walker.resolve<std::string>("INHERITED") + " " + *iter);
+  }
+
+  _walker.pre_decr("ECLASS_DEPTH", 0);
+  if(_walker.resolve<int>("ECLASS_DEPTH") > 0)
+  {
+    _walker.set_value("ECLASS", PECLASS);
+  }
+  else
+  {
+    _walker.unset("ECLASS");
+    _walker.unset("__export_funcs_var");
+  }
+
+  return 0;
+}

diff --git a/src/builtins/inherit_builtin.h b/src/builtins/inherit_builtin.h
new file mode 100644
index 0000000..6a2dc49
--- /dev/null
+++ b/src/builtins/inherit_builtin.h
@@ -0,0 +1,55 @@
+/*
+   Please use git log for copyright holder and year information
+
+   This file is part of libbash.
+
+   libbash 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 2 of the License, or
+   (at your option) any later version.
+
+   libbash 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 libbash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file inherit_builtin.h
+/// \author Mu Qiao
+/// \brief class that implements the inherit function from Portage
+///
+
+#ifndef LIBBASH_BUILTINS_INHERIT_BUILTIN_H_
+#define LIBBASH_BUILTINS_INHERIT_BUILTIN_H_
+
+#include "cppbash_builtin.h"
+
+///
+/// \class inherit
+/// \brief the inherit builtin for bash
+///
+class inherit_builtin: public virtual cppbash_builtin
+{
+  public:
+    BUILTIN_CONSTRUCTOR(inherit)
+
+    ///
+    /// \brief runs the inherit builtin on the supplied arguments
+    /// \param bash_args the arguments to the inherit builtin
+    /// \return exit status of inherit
+    ///
+    virtual int exec(const std::vector<std::string>& bash_args);
+  private:
+    void append_global(const std::string& name);
+
+    void backup_global(const std::string& name, std::string& value);
+
+    void restore_global(const std::string& name, const std::string& value);
+
+    bool hasq(const std::string& value, const std::string& name);
+};
+
+#endif

diff --git a/src/cppbash_builtin.cpp b/src/cppbash_builtin.cpp
index 0df9cbf..dc6ec3e 100644
--- a/src/cppbash_builtin.cpp
+++ b/src/cppbash_builtin.cpp
@@ -24,6 +24,7 @@
 
 #include "cppbash_builtin.h"
 #include "builtins/echo_builtin.h"
+#include "builtins/inherit_builtin.h"
 #include "builtins/boolean_builtins.h"
 #include "builtins/source_builtin.h"
 
@@ -35,6 +36,7 @@ cppbash_builtin::builtins_type& cppbash_builtin::builtins() {
   static boost::scoped_ptr<builtins_type> p(new builtins_type {
       {"echo", boost::factory<echo_builtin*>()},
       {"source", boost::factory<source_builtin*>()},
+      {"inherit", boost::factory<inherit_builtin*>()},
       {"true", boost::factory<true_builtin*>()},
       {"false", boost::factory<false_builtin*>()}
   });

diff --git a/test/ebuild_compiler.sh b/test/ebuild_compiler.sh
index 5930b62..7828476 100755
--- a/test/ebuild_compiler.sh
+++ b/test/ebuild_compiler.sh
@@ -4,7 +4,7 @@ declare -i error=0
 
 for ebuild in $@
 do
-    ./metadata_generator $ebuild | diff -u $ebuild.result -
+    ECLASSDIR=$srcdir/scripts ./metadata_generator $ebuild | diff -u $ebuild.result -
     error+=$?
 done
 

diff --git a/utils/metadata_generator.cpp b/utils/metadata_generator.cpp
index 859839c..52b4590 100644
--- a/utils/metadata_generator.cpp
+++ b/utils/metadata_generator.cpp
@@ -73,20 +73,40 @@ int main(int argc, char** argv)
   for(auto iter_name = metadata_names.begin(); iter_name != metadata_names.end(); ++iter_name)
   {
     auto iter_value = variables.find(*iter_name);
+    std::string value;
+
     if(iter_value != variables.end())
+      value = iter_value->second[0];
+
+    // Check if global is defined
+    auto iter_global = variables.find("E_" + *iter_name);
+    if(iter_global != variables.end())
     {
-      std::vector<std::string> formatted;
-      boost::trim_if(iter_value->second[0], boost::is_any_of(" \t\n"));
-      boost::split(formatted,
-                   iter_value->second[0],
+      boost::trim_if(iter_global->second[0], boost::is_any_of(" \t\n"));
+      std::vector<std::string> splitted_global;
+      boost::split(splitted_global,
+                   iter_global->second[0],
                    boost::is_any_of(" \t\n"),
                    boost::token_compress_on);
-      std::cout << format(string % ' ', formatted) << std::endl;
-    }
-    else
-    {
-      std::cout << std::endl;
+
+      // Append the global value to 'value' if it doesn't cause duplication
+      for(auto iter_splitted_global = splitted_global.begin();
+          iter_splitted_global != splitted_global.end();
+          ++iter_splitted_global)
+      {
+        if(value.find(*iter_splitted_global) == std::string::npos)
+          value += " " + *iter_splitted_global;
+      }
     }
+
+    boost::trim_if(value, boost::is_any_of(" \t\n"));
+
+    std::vector<std::string> splitted_value;
+    boost::split(splitted_value,
+                 value,
+                 boost::is_any_of(" \t\n"),
+                 boost::token_compress_on);
+    std::cout << format(string % ' ', splitted_value) << std::endl;
   }
 
   // Print defined phases
@@ -97,8 +117,6 @@ int main(int argc, char** argv)
     if(iter_phase != phases.end())
       sorted_phases.insert(iter_phase->second);
   }
-
-  using namespace boost::spirit::karma;
   std::cout << format(string % ' ', sorted_phases) << std::endl;
 
   // Print empty lines



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-28  6:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-28  6:19 [gentoo-commits] proj/libbash:master commit in: src/, scripts/, /, test/, utils/, src/builtins/ Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox