CPack External generator runs CPACK_EXTERNAL_PACKAGE_SCRIPT before creating JSON metadata

Hi.

I’m having some trouble understanding how the CPack external generator is supposed to work. I’m running CPack via the CMake “package” target. In CMake I’m setting CPACK_EXTERNAL_PACKAGE_SCRIPT to point to a CMake script that invokes an external tool using execute_process. I want the external process to read the metadata from the CPack generated JSON file and use it to package my library. However, when I run a clean build, the external script runs before the JSON metadata is created causing my packaging step to fail. Is there a way to instruct CPack to generate the JSON metadata before my external script is executed?

Thanks.

It looks like the package.json is written out before the script is executed. Could you get a trace of why the package.json is disappearing perhaps?

A long time has passed since the OP, but I’m seeing the same problem, when running the CPACK_EXTERNAL_PACKAGE_SCRIPT the JSON metadata file is present, but with partial contents. Running the same script later/manually works without problems i.e. after cpack has finished. I also tried just copying the JSON metadata file to another location at that point and it has partial content at that time.

Could there be some race condition/file flush issue making the script run before the JSON metadata file is fully completed and/or flushed to disk?

We see the same issue here. @ben.boeckel , it’s not that the file does not exist, it does but as @t1-nva mentions it is not complete, like it has not been fully flushed.

In our case it just ends like so:

   ⋮

    "tests" : 
    {
      "archiveFile" : "",
      "dependencies" : [],
      "description" : "",
      "displayName" : "Unit Tests",
      "group" : "Development",
      "installationTypes" : [],
      "isDisabledByDefault" : true,
      "isDownloaded" : false,
      "isHidden" : true,
      "isRequired" : false,
      "name" : "tests"
    }
  },
  "errorOnAbsoluteInstallDes

so it ends right in the middle of a word and is thus not even valid json.

Ah, that makes the problem a lot clearer, thanks for the extra details. Can you test this patch: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9669

1 Like

In CMake 3.30.2 this issue has been fixed and CMAKE_EXTERNAL_PACKAGE_SCRIPT is working as expected!

Thanks a lot!