[Libreoffice-commits] core.git: 4 commits - compilerplugins/clang compilerplugins/README solenv/gbuild starmath/qa

Luboš Luňák l.lunak at suse.cz
Sat Feb 9 09:48:53 PST 2013


 compilerplugins/README                          |    9 +
 compilerplugins/clang/pluginhandler.cxx         |  109 ++++++++++++++++++------
 compilerplugins/clang/pluginhandler.hxx         |    3 
 solenv/gbuild/LinkTarget.mk                     |   15 +--
 solenv/gbuild/platform/com_GCC_defs.mk          |    3 
 starmath/qa/cppunit/test_nodetotextvisitors.cxx |    8 -
 starmath/qa/cppunit/test_starmath.cxx           |    3 
 7 files changed, 110 insertions(+), 40 deletions(-)

New commits:
commit 857a39265452c23d4769e6d729ae4c30e44b2973
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Sat Feb 9 18:47:55 2013 +0100

    make it possible to limit what files will be modified by a compiler plugin
    
    Change-Id: I4e3e8f5ca5e5b5b59b1bd067281f90940dd893b1

diff --git a/compilerplugins/README b/compilerplugins/README
index 52e34b9..a9881c7 100644
--- a/compilerplugins/README
+++ b/compilerplugins/README
@@ -35,8 +35,15 @@ All warnings and errors are marked '[loplugin]' in the message.
 
 Rewriters analyse and possibly modify given source files.
 Usage: make COMPILER_PLUGIN_TOOL=<rewriter_name>
-It is possible to also pass FORCE_COMPILE_ALL=1 to make to trigger rebuild of all source files,
-even those that are up to date.
+Additional optional make arguments:
+- it is possible to also pass FORCE_COMPILE_ALL=1 to make to trigger rebuild of all source files,
+    even those that are up to date.
+- UPDATE_FILES=<scope> - limits which modified files will be actually written back with the changes
+    - mainfile - only the main .cxx file will be modifed (default)
+    - all - all source files involved will be modified (possibly even header files from other LO modules),
+        3rd party header files are however never modified
+    - <module> - only files in the given LO module (toplevel directory) will be modified (including headers)
+
 Modifications will be written directly to the source files.
 
 
diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index 468587e..0d27ff67 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -13,6 +13,7 @@
 #include <clang/Frontend/CompilerInstance.h>
 #include <clang/Frontend/FrontendPluginRegistry.h>
 #include <stdio.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 /*
@@ -38,29 +39,24 @@ static bool pluginObjectsCreated = false;
 PluginHandler::PluginHandler( ASTContext& context, const vector< string >& args )
     : context( context )
     , rewriter( context.getSourceManager(), context.getLangOpts())
+    , scope( "mainfile" )
     {
-    bool wasCreated = false;
-    for( int i = 0;
-         i < pluginCount;
-         ++i )
+    bool wasPlugin = false;
+    for( vector< string >::const_iterator it = args.begin();
+         it != args.end();
+         ++it )
         {
-        bool create = false;
-        if( args.empty()) // no args -> create non-writer plugins
-            create = !plugins[ i ].isRewriter;
-        else // create only the given plugin(s)
-            {
-            if( find( args.begin(), args.end(), plugins[ i ].optionName ) != args.end())
-                create = true;
-            }
-        if( create )
+        if( it->size() >= 2 && (*it)[ 0 ] == '-' && (*it)[ 1 ] == '-' )
+            handleOption( it->substr( 2 ));
+        else
             {
-            plugins[ i ].object = plugins[ i ].create( context, rewriter );
-            wasCreated = true;
+            createPlugin( *it );
+            wasPlugin = true;
             }
         }
+    if( !wasPlugin )
+        createPlugin( "" ); // = all non-rewriters
     pluginObjectsCreated = true;
-    if( !args.empty() && !wasCreated )
-        report( DiagnosticsEngine::Fatal, "unknown plugin tool %0" ) << args.front();
     }
 
 PluginHandler::~PluginHandler()
@@ -72,6 +68,45 @@ PluginHandler::~PluginHandler()
             delete plugins[ i ].object;
     }
 
+void PluginHandler::handleOption( const string& option )
+    {
+    if( option.substr( 0, 6 ) == "scope=" )
+        {
+        scope = option.substr( 6 );
+        if( scope == "mainfile" || scope == "all" )
+            ; // ok
+        else
+            {
+            struct stat st;
+            if( stat(( SRCDIR "/" + scope ).c_str(), &st ) != 0 || !S_ISDIR( st.st_mode ))
+                report( DiagnosticsEngine::Fatal, "unknown scope %0 (no such module directory)" ) << scope;
+            }
+        }
+    else
+        report( DiagnosticsEngine::Fatal, "unknown option %0" ) << option;
+    }
+
+void PluginHandler::createPlugin( const string& name )
+    {
+    for( int i = 0;
+         i < pluginCount;
+         ++i )
+        {
+        if( name.empty())  // no plugin given -> create non-writer plugins
+            {
+            if( !plugins[ i ].isRewriter )
+                plugins[ i ].object = plugins[ i ].create( context, rewriter );
+            }
+        else if( plugins[ i ].optionName == name )
+            {
+            plugins[ i ].object = plugins[ i ].create( context, rewriter );
+            return;
+            }
+        }
+    if( !name.empty())
+        report( DiagnosticsEngine::Fatal, "unknown plugin tool %0" ) << name;
+    }
+
 void PluginHandler::registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ), const char* optionName, bool isRewriter )
     {
     assert( !pluginObjectsCreated );
@@ -109,6 +144,8 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
            The order here is important, as OUTDIR and WORKDIR are often in SRCDIR/BUILDDIR,
            and BUILDDIR is sometimes in SRCDIR. */
         string modifyFile;
+        const char* pathWarning = NULL;
+        bool skip = false;
         if( strncmp( e->getName(), OUTDIR "/", strlen( OUTDIR "/" )) == 0 )
             {
             /* Try to find a matching file for a file in solver/ (include files
@@ -125,22 +162,40 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
                     }
                 }
             if( modifyFile.empty())
-                report( DiagnosticsEngine::Warning, "modified source in solver/ : %0" ) << e->getName();
+                pathWarning = "modified source in solver/ : %0";
             }
         else if( strncmp( e->getName(), WORKDIR "/", strlen( WORKDIR "/" )) == 0 )
-            report( DiagnosticsEngine::Warning, "modified source in workdir/ : %0" ) << e->getName();
+            pathWarning = "modified source in workdir/ : %0";
         else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR "/", strlen( BUILDDIR "/" )) == 0 )
-            report( DiagnosticsEngine::Warning, "modified source in build dir : %0" ) << e->getName();
+            pathWarning = "modified source in build dir : %0";
         else if( strncmp( e->getName(), SRCDIR "/", strlen( SRCDIR "/" )) == 0 )
             ; // ok
         else
             {
-            report( DiagnosticsEngine::Warning, "modified source in unknown location, not modifying : %0" )
-                 << e->getName();
-            continue; // --->
+            pathWarning = "modified source in unknown location, not modifying : %0";
+            skip = true;
             }
         if( modifyFile.empty())
             modifyFile = e->getName();
+        // Check whether the modified file is in the wanted scope (done after path checking above), so
+        // that files mapped from OUTDIR to SRCDIR are included.
+        if( scope == "mainfile" )
+            {
+            if( it->first != context.getSourceManager().getMainFileID())
+                continue;
+            }
+        else if( scope == "all" )
+            ; // ok
+        else // scope is module
+            {
+            if( strncmp( modifyFile.c_str(), ( SRCDIR "/" + scope + "/" ).c_str(), ( SRCDIR "/" + scope + "/" ).size()) != 0 )
+                continue;
+            }
+        // Warn only now, so that files not in scope do not cause warnings.
+        if( pathWarning != NULL )
+            report( DiagnosticsEngine::Warning, pathWarning ) << e->getName();
+        if( skip )
+            continue;
         char* filename = new char[ modifyFile.length() + 100 ];
         sprintf( filename, "%s.new.%d", modifyFile.c_str(), getpid());
         string error;
diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx
index 23ca217..0a3251e 100644
--- a/compilerplugins/clang/pluginhandler.hxx
+++ b/compilerplugins/clang/pluginhandler.hxx
@@ -31,9 +31,12 @@ class PluginHandler
         virtual void HandleTranslationUnit( ASTContext& context );
         static void registerPlugin( Plugin* (*create)( ASTContext&, Rewriter& ), const char* optionName, bool isRewriter );
     private:
+        void handleOption( const string& option );
+        void createPlugin( const string& name );
         DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
         ASTContext& context;
         Rewriter rewriter;
+        string scope;
     };
 
 /**
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk
index 76a63e0..4f64bff 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -167,6 +167,9 @@ ifeq ($(COMPILER_PLUGIN_TOOL),)
 gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/obj/plugin.so -Xclang -add-plugin -Xclang loplugin
 else
 gb_COMPILER_PLUGINS := -Xclang -load -Xclang $(BUILDDIR)/compilerplugins/obj/plugin.so -Xclang -plugin -Xclang loplugin -Xclang -plugin-arg-loplugin -Xclang $(COMPILER_PLUGIN_TOOL)
+ifneq ($(UPDATE_FILES),)
+gb_COMPILER_PLUGINS += -Xclang -plugin-arg-loplugin -Xclang --scope=$(UPDATE_FILES)
+endif
 endif
 # extra EF variable to make the command line shorter (just like is done with $(SRCDIR) etc.)
 gb_COMPILER_PLUGINS_SETUP := EF=$(SRCDIR)/sal/inc/sal/log-areas.dox && ICECC_EXTRAFILES=$$EF CCACHE_EXTRAFILES=$$EF
commit 8f1a01ad001d2288c4aa43420bb56bab1094aa20
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Sat Feb 9 18:31:38 2013 +0100

    fix check whether a file is in a directory
    
    Make sure / is appended, otherwise /foo might match /foobar/file .
    
    Change-Id: I36469916b72b407c8f0c9c255099ee671039cf17

diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx
index eeda78a..468587e 100644
--- a/compilerplugins/clang/pluginhandler.cxx
+++ b/compilerplugins/clang/pluginhandler.cxx
@@ -109,7 +109,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
            The order here is important, as OUTDIR and WORKDIR are often in SRCDIR/BUILDDIR,
            and BUILDDIR is sometimes in SRCDIR. */
         string modifyFile;
-        if( strncmp( e->getName(), OUTDIR, strlen( OUTDIR )) == 0 )
+        if( strncmp( e->getName(), OUTDIR "/", strlen( OUTDIR "/" )) == 0 )
             {
             /* Try to find a matching file for a file in solver/ (include files
                are usually included from there rather than from the source dir) if possible. */
@@ -127,11 +127,11 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
             if( modifyFile.empty())
                 report( DiagnosticsEngine::Warning, "modified source in solver/ : %0" ) << e->getName();
             }
-        else if( strncmp( e->getName(), WORKDIR, strlen( WORKDIR )) == 0 )
+        else if( strncmp( e->getName(), WORKDIR "/", strlen( WORKDIR "/" )) == 0 )
             report( DiagnosticsEngine::Warning, "modified source in workdir/ : %0" ) << e->getName();
-        else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR, strlen( BUILDDIR )) == 0 )
+        else if( strcmp( SRCDIR, BUILDDIR ) != 0 && strncmp( e->getName(), BUILDDIR "/", strlen( BUILDDIR "/" )) == 0 )
             report( DiagnosticsEngine::Warning, "modified source in build dir : %0" ) << e->getName();
-        else if( strncmp( e->getName(), SRCDIR, strlen( SRCDIR )) == 0 )
+        else if( strncmp( e->getName(), SRCDIR "/", strlen( SRCDIR "/" )) == 0 )
             ; // ok
         else
             {
commit 1b535267dfa18ad802229851fdbb88b656e8b7df
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Sat Feb 9 16:00:50 2013 +0100

    treat all source files as not up to date only with FORCE_COMPILE_ALL
    
    So running the compiler plugin can be done either with FORCE_COMPILE_ALL=1
    for simplicity, running the plugin on all source files for the target,
    or it's possible to use make's -W option (or touch files manually) to
    run it only for selected files.
    
    Change-Id: Ifa82bbe91dc1e179af9db8fbf99271bcf03a1d47

diff --git a/compilerplugins/README b/compilerplugins/README
index a5441c9..52e34b9 100644
--- a/compilerplugins/README
+++ b/compilerplugins/README
@@ -35,6 +35,8 @@ All warnings and errors are marked '[loplugin]' in the message.
 
 Rewriters analyse and possibly modify given source files.
 Usage: make COMPILER_PLUGIN_TOOL=<rewriter_name>
+It is possible to also pass FORCE_COMPILE_ALL=1 to make to trigger rebuild of all source files,
+even those that are up to date.
 Modifications will be written directly to the source files.
 
 
diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk
index 0ec033f..986dcae 100644
--- a/solenv/gbuild/LinkTarget.mk
+++ b/solenv/gbuild/LinkTarget.mk
@@ -122,9 +122,12 @@ gb_Object__command_dep = \
  $(call gb_Output_error,gb_Object__command_dep is only for gb_FULLDEPS)
 endif
 
+ifneq ($(FORCE_COMPILE_ALL),)
 # This one only exists to force .c/.cxx "rebuilds" when running a compiler tool.
-.PHONY: force_compiler_tool_run
-force_compiler_tool_run:
+.PHONY: force_compile_all_target
+force_compile_all_target:
+gb_FORCE_COMPILE_ALL_TARGET := force_compile_all_target
+endif
 
 # CObject class
 
@@ -133,7 +136,7 @@ gb_CObject_get_source = $(1)/$(2).c
 #  gb_CObject__command
 
 ifneq ($(COMPILER_PLUGIN_TOOL),)
-$(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) force_compiler_tool_run
+$(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%) $(gb_FORCE_COMPILE_ALL_TARGET)
 	$(call gb_CObject__tool_command,$*,$<)
 else
 $(call gb_CObject_get_target,%) : $(call gb_CObject_get_source,$(SRCDIR),%)
@@ -183,7 +186,7 @@ endif
 endef
 
 ifneq ($(COMPILER_PLUGIN_TOOL),)
-$(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%) force_compiler_tool_run
+$(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%) $(gb_FORCE_COMPILE_ALL_TARGET)
 	$(call gb_CxxObject__tool_command,$*,$<)
 else
 $(call gb_CxxObject_get_target,%) : $(call gb_CxxObject_get_source,$(SRCDIR),%)
@@ -306,7 +309,7 @@ gb_ObjCxxObject_get_source = $(1)/$(2).mm
 #  gb_ObjCxxObject__command
 
 ifneq ($(COMPILER_PLUGIN_TOOL),)
-$(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDIR),%) force_compiler_tool_run
+$(call gb_ObjCxxObject_get_target,%) : $(call gb_ObjCxxObject_get_source,$(SRCDIR),%) $(gb_FORCE_COMPILE_ALL_TARGET)
 	$(call gb_ObjCxxObject__tool_command,$*,$<)
 else
 
@@ -330,7 +333,7 @@ gb_ObjCObject_get_source = $(1)/$(2).m
 #  gb_ObjCObject__command
 
 ifneq ($(COMPILER_PLUGIN_TOOL),)
-$(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%) force_compiler_tool_run
+$(call gb_ObjCObject_get_target,%) : $(call gb_ObjCObject_get_source,$(SRCDIR),%) $(gb_FORCE_COMPILE_ALL_TARGET)
 	$(call gb_ObjCObject__tool_command,$*,$<)
 else
 
commit 531391239bbd9d9dfc8df4d5f413fd0ab1758b09
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Sat Feb 9 09:30:01 2013 +0100

    remove unused variables
    
    Change-Id: I7383100f5965578160098f11cdb99bb4e4ce57fa

diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index 8f44185..b64a584 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -511,7 +511,7 @@ void Test::ParseAndCheck(const char *formula, const char * expected, const char
 
 void Test::testBinomInBinHor()
 {
-    String sInput, sExpected, sOutput;
+    String sInput, sExpected;
     SmNode* pTree;
 
     // set up a binom (table) node
@@ -539,7 +539,7 @@ void Test::testBinomInBinHor()
 
 void Test::testBinVerInUnary()
 {
-    String sInput, sExpected, sOutput;
+    String sInput, sExpected;
     SmNode* pTree;
 
     // set up a unary operator with operand
@@ -570,7 +570,7 @@ void Test::testBinVerInUnary()
 
 void Test::testBinHorInSubSup()
 {
-    String sInput, sExpected, sOutput;
+    String sInput, sExpected;
     SmNode* pTree;
 
     // set up a blank formula
@@ -601,7 +601,7 @@ void Test::testBinHorInSubSup()
 
 void Test::testUnaryInMixedNumberAsNumerator()
 {
-    String sInput, sExpected, sOutput;
+    String sInput, sExpected;
     SmNode* pTree;
 
     // set up a unary operator
diff --git a/starmath/qa/cppunit/test_starmath.cxx b/starmath/qa/cppunit/test_starmath.cxx
index e73536f..f493354 100644
--- a/starmath/qa/cppunit/test_starmath.cxx
+++ b/starmath/qa/cppunit/test_starmath.cxx
@@ -209,7 +209,6 @@ void Test::editUndoRedo()
 
     {
         m_xDocShRef->Execute(aUndo);
-        rtl::OUString sFoo = rEditEngine.GetText();
         m_xDocShRef->UpdateText();
         rtl::OUString sFinalText = m_xDocShRef->GetText();
         CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);
@@ -217,7 +216,6 @@ void Test::editUndoRedo()
 
     {
         m_xDocShRef->Execute(aUndo);
-        rtl::OUString sFoo = rEditEngine.GetText();
         m_xDocShRef->UpdateText();
         rtl::OUString sFinalText = m_xDocShRef->GetText();
         CPPUNIT_ASSERT_MESSAGE("Must now be empty", !sFinalText.getLength());
@@ -226,7 +224,6 @@ void Test::editUndoRedo()
     SfxRequest aRedo(SID_REDO, SFX_CALLMODE_SYNCHRON, m_xDocShRef->GetPool());
     {
         m_xDocShRef->Execute(aRedo);
-        rtl::OUString sFoo = rEditEngine.GetText();
         m_xDocShRef->UpdateText();
         rtl::OUString sFinalText = m_xDocShRef->GetText();
         CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);


More information about the Libreoffice-commits mailing list