GoogleTest - how to override component task dependency tree


(Mark) #1

I have a gradle script with a native build component which compiles a static library ( NativeLibrarySpec ). I configure a googletest suite for this static library component.

Here’s the static library component. To explain a bit more, I’m compiling GoogleTest via gradle and then running gtest’s our test suite.:

components {
    gtest(NativeLibrarySpec) {
      sources {
	cpp {
	  source {
	    srcDir googletestDir + '/src'
	    include "gtest-all.cc"
	  }
	  exportedHeaders {
	    srcDir googletestDir + '/include'
	  }
	}
      }
    }
  }

Here’s the testsuite setup:

  testSuites { 
    gtestTest(GoogleTestTestSuiteSpec) {
      sources {
	cpp {
	  source {
	    srcDir googletestDir
	    include 'test/gtest_all_test.cc'
	    }
	}
      }
     
      testing $.components.gtest

    }
  }

To build the test suitsuite, I run:

gradlew gtestTestGoogleTestExe

The task list is:

Tasks to be executed: [task ‘:compileGtestTestGoogleTestExeGtestCpp’, task ‘:com
pileGtestTestGoogleTestExeGtestTestCpp’, task ‘:linkGtestTestGoogleTestExe’, tas
k ‘:gtestTestGoogleTestExe’]

But here’s the issue:

Question 1: compileGtestTestGoogleTestExeGtestCpp simply re-compiles my static library for googleTest so my build logic has to replicate my compiler settings for this case. Is there anyway to configure compileGtestTestGoogleTestExeGtestCpp so that it uses the gtest static library component rather than rebuild it. Is there anyway to prevent re-compiling the static library for use by the google test component in gradle?

Question 2: I see “apply plugin: google-test” in previous forum discussions regarding GoogleTest but the gradle code example is “apply plugin: google-test-test-suite”. Are there 2 plugins available ( I can’t find google-test ) or was this just an interface change?

Any guidance is greatly appreciated. Thanks.

best regards,

Mark