error executing script with cmake -P

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

error executing script with cmake -P

Edoardo Pasca
Dear all, 

I am using external project. I would like to patch a source file. I came out with a cmake script that does the string replacement I'm interested in.

I tested in a standalone project, with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.4)
project(patching_string)
file (STRINGS TestData.py testdata NEWLINE_CONSUME)
string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ${testdata})
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )

and as a matter of facts this does the string replacement I'm interested in.

Good, now I would like to use this to the project I'm really interested in which uses the ExternalProject_Add machinery. I added the patch step:

<code>

file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "
file (STRINGS ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata NEWLINE_CONSUME)
string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})
file( WRITE ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py \${patched} ) ")
ExternalProject_Add( 
...

PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake

... )

</code>

Notice that I write the patch_script.cmake before the ExternalProject_Add


Now, all of this WORKS. Or at least I get the patch_script.cmake file in the proper directoty, with the content I want. However, execution with cmake -P patch_script.cmake doesn't work as expected.

I get
CMake Error at build/patch_script.cmake:3 (string):
  string sub-command REPLACE requires at least four arguments.

Given that the patch_script.cmake has the same content of the standalone CMakeLists.txt above (without the first 2 lines), I don't know where things don't go well, except that I execute the script with cmake -P

cmake version 3.15.2

Thanks for any help.

Edo


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: error executing script with cmake -P

CMake mailing list
It looks like you aren't passing the $testdata variable down to the script. From your message it looks like you need to add the following to your PATCH_COMMAND:

-Dtestdata=${testdata}

You must explicitly pass $testdata (and any other variables defined in the calling script) to patch_script.cmake via -D parameters on the command line. Also note that the -Dvar=value args must precede the -P <script> argument for the arguments to be defined in the script.

Note: I'm not certain about the rules for ExternalProject_Add. The above is based on the behavior of execute_process(), but the error message you've sent leads me to believe that the problem here is the same: Variables from the calling CMake scope are not automatically passed along to the scope of child CMake instances.



On Mon, Oct 14, 2019 at 4:01 AM Edoardo Pasca <[hidden email]> wrote:
Dear all, 

I am using external project. I would like to patch a source file. I came out with a cmake script that does the string replacement I'm interested in.

I tested in a standalone project, with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.4)
project(patching_string)
file (STRINGS TestData.py testdata NEWLINE_CONSUME)
string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ${testdata})
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )

and as a matter of facts this does the string replacement I'm interested in.

Good, now I would like to use this to the project I'm really interested in which uses the ExternalProject_Add machinery. I added the patch step:

<code>

file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "
file (STRINGS ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata NEWLINE_CONSUME)
string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})
file( WRITE ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py \${patched} ) ")
ExternalProject_Add( 
...

PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake

... )

</code>

Notice that I write the patch_script.cmake before the ExternalProject_Add


Now, all of this WORKS. Or at least I get the patch_script.cmake file in the proper directoty, with the content I want. However, execution with cmake -P patch_script.cmake doesn't work as expected.

I get
CMake Error at build/patch_script.cmake:3 (string):
  string sub-command REPLACE requires at least four arguments.

Given that the patch_script.cmake has the same content of the standalone CMakeLists.txt above (without the first 2 lines), I don't know where things don't go well, except that I execute the script with cmake -P

cmake version 3.15.2

Thanks for any help.

Edo


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: error executing script with cmake -P

Alan W. Irwin-2
In reply to this post by Edoardo Pasca
On 2019-10-14 12:00+0100 Edoardo Pasca wrote:

> Dear all,
>
> I am using external project. I would like to patch a source file. I came
> out with a cmake script that does the string replacement I'm interested in.
>
> I tested in a standalone project, with the following CMakeLists.txt
>
> cmake_minimum_required(VERSION 3.4)
> project(patching_string)
> file (STRINGS TestData.py testdata NEWLINE_CONSUME)
> string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched
> ${testdata})
> file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )
>
> and as a matter of facts this does the string replacement I'm interested in.
>
> Good, now I would like to use this to the project I'm really interested in
> which uses the ExternalProject_Add machinery. I added the patch step:
>
> <code>
>
> file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "
> file (STRINGS
> ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata
> NEWLINE_CONSUME)
> string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\"
> patched \${testdata})
> file( WRITE
> ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py
> \${patched} ) ")
> ExternalProject_Add(
> ...
>
> PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake
>
> ... )
>
> </code>
>
> Notice that I write the patch_script.cmake before the ExternalProject_Add
>
>
> Now, all of this WORKS. Or at least I get the patch_script.cmake file in
> the proper directoty, with the content I want. However, execution with
> cmake -P patch_script.cmake doesn't work as expected.
>
> I get
> CMake Error at build/patch_script.cmake:3 (string):
>  string sub-command REPLACE requires at least four arguments.
>
> Given that the patch_script.cmake has the same content of the standalone
> CMakeLists.txt above (without the first 2 lines), I don't know where things
> don't go well, except that I execute the script with cmake -P
>
> cmake version 3.15.2
>
> Thanks for any help.

Hi Edo:

This help likely belongs to the "any" category.  :-)  That is, it is just a informed suggestion
that might help you but nothing definite.

It sounds to me from the research you reported above that you have an absolutely clear case where
standalone cmake operating on CMake logic contained in a file (with

cmake_minimum_required(VERSION 3.4)
project(patching_string)

prepended so standalone CMake works fine, but cmake -P operating on *that same file* does
not work.  I suggest you prepare a test tarball containing a file which contains
the CMake logic executed by cmake -P (i.e., all but the first two lines of the above
CMakeLists.txt file),
and the original TestData.py file that logic is supposed to work on.  That simple test
case should help others here (likely not me) replicate the issue you have found and
explain why it occurs for cmake -P but not for the standalone cmake case (with the two
lines prepended, separate build tree, etc., so standalone works).

N.B. Also note that even before that difference is confirmed and
explained, you have the option of either fixing the logic in the cmake
-P case (where the cmake options --debug-output and --trace-expand
might help you figure out exactly what the problem is) or else
adopting the current (prepended) logic for the standalone case and
executing that (rather clumsy, of course) standalone method in your
super-project.

Good luck, and I hope this overview of how I would deal with the
issue you have described is a help to you.

Alan
__________________________
Alan W. Irwin

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.org); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: error executing script with cmake -P

Edoardo Pasca
In reply to this post by CMake mailing list
Hi Tom,

I thought ${testdata} was going to be filled in by the actual patch_script.cmake at this line.

file (STRINGS TestData.py testdata NEWLINE_CONSUME) 

 So it appears that this command doesn't quite work.

I'll try also Alan's suggestion.

Thanks

Edo

On Tue, Oct 15, 2019 at 7:00 PM Tom Finegan <[hidden email]> wrote:
It looks like you aren't passing the $testdata variable down to the script. From your message it looks like you need to add the following to your PATCH_COMMAND:

-Dtestdata=${testdata}

You must explicitly pass $testdata (and any other variables defined in the calling script) to patch_script.cmake via -D parameters on the command line. Also note that the -Dvar=value args must precede the -P <script> argument for the arguments to be defined in the script.

Note: I'm not certain about the rules for ExternalProject_Add. The above is based on the behavior of execute_process(), but the error message you've sent leads me to believe that the problem here is the same: Variables from the calling CMake scope are not automatically passed along to the scope of child CMake instances.



On Mon, Oct 14, 2019 at 4:01 AM Edoardo Pasca <[hidden email]> wrote:
Dear all, 

I am using external project. I would like to patch a source file. I came out with a cmake script that does the string replacement I'm interested in.

I tested in a standalone project, with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.4)
project(patching_string)
file (STRINGS TestData.py testdata NEWLINE_CONSUME)
string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ${testdata})
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )

and as a matter of facts this does the string replacement I'm interested in.

Good, now I would like to use this to the project I'm really interested in which uses the ExternalProject_Add machinery. I added the patch step:

<code>

file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "
file (STRINGS ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata NEWLINE_CONSUME)
string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})
file( WRITE ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py \${patched} ) ")
ExternalProject_Add( 
...

PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake

... )

</code>

Notice that I write the patch_script.cmake before the ExternalProject_Add


Now, all of this WORKS. Or at least I get the patch_script.cmake file in the proper directoty, with the content I want. However, execution with cmake -P patch_script.cmake doesn't work as expected.

I get
CMake Error at build/patch_script.cmake:3 (string):
  string sub-command REPLACE requires at least four arguments.

Given that the patch_script.cmake has the same content of the standalone CMakeLists.txt above (without the first 2 lines), I don't know where things don't go well, except that I execute the script with cmake -P

cmake version 3.15.2

Thanks for any help.

Edo


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: error executing script with cmake -P

CMake mailing list


On Thu, Oct 17, 2019 at 2:14 AM Edoardo Pasca <[hidden email]> wrote:
Hi Tom,

I thought ${testdata} was going to be filled in by the actual patch_script.cmake at this line.

file (STRINGS TestData.py testdata NEWLINE_CONSUME) 

Sorry, some nasty formatting in my email client had me misreading your script. My advice is mainly based on this error:

  CMake Error at build/patch_script.cmake:3 (string):
    string sub-command REPLACE requires at least four arguments 

Looking at this line:
string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})

The most likely possible reason for that error being reported by CMake is that ${testdata} is not defined when that line of script is executed. What does line 3 of patch_script.cmake look like immediately after the error message is output? My guess is that it looks something like this:

  string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ) 

As you'll notice REPLACE is only receiving 3 args in the above version.

Also note: I don't think you need to escape the single quotes in the os.environ argument (unless they must be escaped in the final output). Basic toy scripts here show it as unnecessary unless they must be escaped in the patched file.
 

 So it appears that this command doesn't quite work.

I'll try also Alan's suggestion.

Thanks

Edo

On Tue, Oct 15, 2019 at 7:00 PM Tom Finegan <[hidden email]> wrote:
It looks like you aren't passing the $testdata variable down to the script. From your message it looks like you need to add the following to your PATCH_COMMAND:

-Dtestdata=${testdata}

You must explicitly pass $testdata (and any other variables defined in the calling script) to patch_script.cmake via -D parameters on the command line. Also note that the -Dvar=value args must precede the -P <script> argument for the arguments to be defined in the script.

Note: I'm not certain about the rules for ExternalProject_Add. The above is based on the behavior of execute_process(), but the error message you've sent leads me to believe that the problem here is the same: Variables from the calling CMake scope are not automatically passed along to the scope of child CMake instances.



On Mon, Oct 14, 2019 at 4:01 AM Edoardo Pasca <[hidden email]> wrote:
Dear all, 

I am using external project. I would like to patch a source file. I came out with a cmake script that does the string replacement I'm interested in.

I tested in a standalone project, with the following CMakeLists.txt

cmake_minimum_required(VERSION 3.4)
project(patching_string)
file (STRINGS TestData.py testdata NEWLINE_CONSUME)
string(REPLACE "sys.prefix" "os.environ[\'SIRF_INSTALL_PATH\']" patched ${testdata})
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/TestData.py ${patched} )

and as a matter of facts this does the string replacement I'm interested in.

Good, now I would like to use this to the project I'm really interested in which uses the ExternalProject_Add machinery. I added the patch step:

<code>

file (WRITE ${CMAKE_BINARY_DIR}/patch_script.cmake "
file (STRINGS ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py testdata NEWLINE_CONSUME)
string(REPLACE \"sys.prefix\" \"os.environ[\\\'SIRF_INSTALL_PATH\\\']\" patched \${testdata})
file( WRITE ${${proj}_SOURCE_DIR}/Wrappers/Python/ccpi/framework/TestData.py \${patched} ) ")
ExternalProject_Add( 
...

PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/patch_script.cmake

... )

</code>

Notice that I write the patch_script.cmake before the ExternalProject_Add


Now, all of this WORKS. Or at least I get the patch_script.cmake file in the proper directoty, with the content I want. However, execution with cmake -P patch_script.cmake doesn't work as expected.

I get
CMake Error at build/patch_script.cmake:3 (string):
  string sub-command REPLACE requires at least four arguments.

Given that the patch_script.cmake has the same content of the standalone CMakeLists.txt above (without the first 2 lines), I don't know where things don't go well, except that I execute the script with cmake -P

cmake version 3.15.2

Thanks for any help.

Edo


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


--
Edo
I know you think you understand what you thought I said, but I'm not sure you realize that what you heard is not what I meant (prob. Alan Greenspan)
:wq

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake