[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Triggering rebuild after changing a *.json file
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2014-11-23 9:39:02
Message-ID: CAExHGmSk2thx=mGudXxvzWw7G2uPtZbxxumzeH2qV3sM7f8D7w () mail ! gmail ! com
[Download RAW message or body]

Hi,

On Sun, Nov 23, 2014 at 4:36 AM, Milian Wolff <mail@milianw.de> wrote:

> Hey all,
>
> in my quest for better *.json support in KF5 based applications, I noticed
> that we currently do not rebuild properly on changes to the *.desktop or
> *.json files.
>
> For KDevelop, I'm thus playing around with something like this currently:
>
> ~~~~~~~~~~~~~~~+
> function(kdevplatform_add_plugin plugin)
>     set(options )
>     set(oneValueArgs JSON)
>     set(multiValueArgs SOURCES)
>     cmake_parse_arguments(KDEV_ADD_PLUGIN "${options}" "${oneValueArgs}"
> "${multiValueArgs}" ${ARGN})
>
>     string(REGEX REPLACE "\\.cmake$" "" json_out ${KDEV_ADD_PLUGIN_JSON})
>     configure_file(${KDEV_ADD_PLUGIN_JSON}
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
>
>     # ensure we recompile the corresponding object files when the json file
> changes
>     set(dependent_sources )
>     foreach(header ${KDEV_ADD_PLUGIN_SOURCES})
>         file(STRINGS "${header}" match REGEX "K_PLUGIN_FACTORY_WITH_JSON")
>         if(match)
>             list(APPEND dependent_sources "${header}")
>         endif()
>     endforeach()
>     if(NOT dependent_sources)
>         # fallback to all sources - better safe than sorry...
>         set(dependent_sources ${KDEV_ADD_PLUGIN_SOURCES})
>     endif()
>     set_property(SOURCE ${dependent_sources} APPEND PROPERTY OBJECT_DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
>
>     add_library(${plugin} MODULE ${KDEV_ADD_PLUGIN_SOURCES})
>     set_property(TARGET ${plugin} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
> endfunction()
> ~~~~~~~~~~~~~~~+
>
>
> To be used like this:
>
> kdevplatform_add_plugin(kdevgit JSON kdevgit.json.cmake SOURCES
> ${kdevgit_PART_SRCS})
>
> This does trigger a rebuild, but the strings are still not updated
> properly.
> I'm quite confused actually, does anyone know where the code comes from
> that
> is embedded into the *.o that uses Q_PLUGIN_METADATA? I suspect CMake
> AUTOGEN?
> But where does that put its generated binary JSON representation? How can I
> make sure that it gets updated properly when the source file changes?
>
> To reproduce this, you can just change any *.desktop file that is piped
> through desktop_to_json. The change will be picked up by CMake and a
> reconfigure is triggered, which is pretty slow as well. But nothing is
> rebuilt. With the macro above, I trigger the build but still, the *.o file
> that uses K_PLUGIN_FACTORY_WITH_JSON is still containing the "old"
> strings...
> I'm at loss - can someone help me please? <http://milianw.de>


Is there a particular reason why you run the to-json part during cmake
time? If you setup a simple cmake script you could easily switch the
generation to be a custom target and then have the plugin depend on that
custom target (or rather its json output file).

I also think you're misunderstanding the AUTOGEN_TARGET_DEPENDS property,
according to the documentation it is to be set on an auto-generator target
and not on a 'standard' one like the library. As far as I can see you know
the input and output files of the desktop-to-json conversion so a custom
target should be easily doable (unlike automoc).

Andreas

[Attachment #3 (text/html)]

<div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov \
23, 2014 at 4:36 AM, Milian Wolff <span dir="ltr">&lt;<a \
href="mailto:mail@milianw.de" target="_blank">mail@milianw.de</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">Hey all,<br> <br>
in my quest for better *.json support in KF5 based applications, I noticed<br>
that we currently do not rebuild properly on changes to the *.desktop or<br>
*.json files.<br>
<br>
For KDevelop, I&#39;m thus playing around with something like this currently:<br>
<br>
~~~~~~~~~~~~~~~+<br>
function(kdevplatform_add_plugin plugin)<br>
      set(options )<br>
      set(oneValueArgs JSON)<br>
      set(multiValueArgs SOURCES)<br>
      cmake_parse_arguments(KDEV_ADD_PLUGIN &quot;${options}&quot; \
&quot;${oneValueArgs}&quot;<br> &quot;${multiValueArgs}&quot; ${ARGN})<br>
<br>
      string(REGEX REPLACE &quot;\\.cmake$&quot; &quot;&quot; json_out \
${KDEV_ADD_PLUGIN_JSON})<br>  configure_file(${KDEV_ADD_PLUGIN_JSON}<br>
${CMAKE_CURRENT_BINARY_DIR}/${json_out})<br>
<br>
      # ensure we recompile the corresponding object files when the json file<br>
changes<br>
      set(dependent_sources )<br>
      foreach(header ${KDEV_ADD_PLUGIN_SOURCES})<br>
            file(STRINGS &quot;${header}&quot; match REGEX \
&quot;K_PLUGIN_FACTORY_WITH_JSON&quot;)<br>  if(match)<br>
                  list(APPEND dependent_sources &quot;${header}&quot;)<br>
            endif()<br>
      endforeach()<br>
      if(NOT dependent_sources)<br>
            # fallback to all sources - better safe than sorry...<br>
            set(dependent_sources ${KDEV_ADD_PLUGIN_SOURCES})<br>
      endif()<br>
      set_property(SOURCE ${dependent_sources} APPEND PROPERTY OBJECT_DEPENDS<br>
${CMAKE_CURRENT_BINARY_DIR}/${json_out})<br>
<br>
      add_library(${plugin} MODULE ${KDEV_ADD_PLUGIN_SOURCES})<br>
      set_property(TARGET ${plugin} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS<br>
${CMAKE_CURRENT_BINARY_DIR}/${json_out})<br>
endfunction()<br>
~~~~~~~~~~~~~~~+<br>
<br>
<br>
To be used like this:<br>
<br>
kdevplatform_add_plugin(kdevgit JSON kdevgit.json.cmake SOURCES<br>
${kdevgit_PART_SRCS})<br>
<br>
This does trigger a rebuild, but the strings are still not updated properly.<br>
I&#39;m quite confused actually, does anyone know where the code comes from that<br>
is embedded into the *.o that uses Q_PLUGIN_METADATA? I suspect CMake AUTOGEN?<br>
But where does that put its generated binary JSON representation? How can I<br>
make sure that it gets updated properly when the source file changes?<br>
<br>
To reproduce this, you can just change any *.desktop file that is piped<br>
through desktop_to_json. The change will be picked up by CMake and a<br>
reconfigure is triggered, which is pretty slow as well. But nothing is<br>
rebuilt. With the macro above, I trigger the build but still, the *.o file<br>
that uses K_PLUGIN_FACTORY_WITH_JSON is still containing the &quot;old&quot; \
strings...<br> I&#39;m at loss - can someone help me please?<span \
class="HOEnZb"><font color="#888888"><a href="http://milianw.de" \
target="_blank"></a></font></span></blockquote><div><br></div><div>Is there a \
particular reason why you run the to-json part during cmake time? If you setup a \
simple cmake script you could easily switch the generation to be a custom target and \
then have the plugin depend on that custom target (or rather its json output \
file).</div><div><br></div><div>I also think you&#39;re misunderstanding the \
AUTOGEN_TARGET_DEPENDS property, according to the documentation it is to be set on an \
auto-generator target and not on a &#39;standard&#39; one like the library. As far as \
I can see you know the input and output files of the desktop-to-json conversion so a \
custom target should be easily doable (unlike \
automoc).</div><div><br></div><div>Andreas</div></div><br></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic