Skip to content

[harfbuzz] Remove PARENT_SCOPE in harfbuzzConfig.cmake.in#23709

Closed
LilyWangLL wants to merge 11 commits intomicrosoft:masterfrom
LilyWangLL:dev/LilyWang/issue23694
Closed

[harfbuzz] Remove PARENT_SCOPE in harfbuzzConfig.cmake.in#23709
LilyWangLL wants to merge 11 commits intomicrosoft:masterfrom
LilyWangLL:dev/LilyWang/issue23694

Conversation

@LilyWangLL
Copy link
Copy Markdown
Contributor

Fixes #23694
Remove PARENT_SCOPE in harfbuzzConfig.cmake.in, because it will make the variables of HARFBUZZ_LIBRARY and so on can not set in CMake project. Like the following error:

Cannot set "HARFBUZZ_LIBRARY": current scope has no parent.
Cannot set "HARFBUZZ_LIBRARIES": current scope has no parent.
Cannot set "HARFBUZZ_INCLUDE_DIR": current scope has no parent.
Cannot set "HARFBUZZ_INCLUDE_DIRS": current scope has no parent.
Cannot set "HARFBUZZ_FOUND": current scope has no parent.

@LilyWangLL LilyWangLL added category:port-bug The issue is with a library, which is something the port should already support info:internal labels Mar 22, 2022
@LilyWangLL
Copy link
Copy Markdown
Contributor Author

cc @cenit @dg0yt

@dalboris
Copy link
Copy Markdown

Thanks a lot @LilyWangLL / @JackBoosY , these changes look good to me (bug reporter). I just hope removing PARENT_SCOPE isn't going to break someone else's workflow, I'm most likely not familiar with all possible use cases.

@Neumann-A
Copy link
Copy Markdown
Contributor

I just hope removing PARENT_SCOPE isn't going to break someone else's workflow, I'm most likely not familiar with all possible use cases.

removing PARENT_SCOPE is correct. find_package is like a glorified include statement. If it breaks someone the person who is getting broke is simply wrong.

@dalboris
Copy link
Copy Markdown

@Neumann-A Thanks for the clarification.

@LilyWangLL
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@Neumann-A
Copy link
Copy Markdown
Contributor

@LilyWangLL merge with master again?

get_filename_component(_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)
target_include_directories(harfbuzz INTERFACE "${_INSTALL_DIR}/include/harfbuzz")

set(HARFBUZZ_LIBRARY harfbuzz::harfbuzz)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PARENT_SCOPE will pass the variable to the upstream, and this port cannot use this variable, so add a variable to this port for itself.

@Neumann-A
Copy link
Copy Markdown
Contributor

You should revert cf01dcf

PARENT_SCOPE in the wrapper is wrong!

@LilyWangLL
Copy link
Copy Markdown
Contributor Author

You should revert cf01dcf

PARENT_SCOPE in the wrapper is wrong!

But if doesn't use PARENT_SCOPE, other ports will be affected. Like openmvs opencv4.
cc @cenit @dg0yt
PARENT_SCOPE and these codes added by commit 4015784.

set(HARFBUZZ_LIBRARY harfbuzz::harfbuzz PARENT_SCOPE)
set(HARFBUZZ_LIBRARIES harfbuzz::harfbuzz PARENT_SCOPE)
set(HARFBUZZ_INCLUDE_DIR "${_INSTALL_DIR}/include/harfbuzz" PARENT_SCOPE)
set(HARFBUZZ_INCLUDE_DIRS "${_INSTALL_DIR}/include/harfbuzz" PARENT_SCOPE)

if(HARFBUZZ_LIBRARY_RELEASE)
  set(HARFBUZZ_FOUND TRUE PARENT_SCOPE)
else()
  set(HARFBUZZ_FOUND FALSE PARENT_SCOPE)
endif()

@Neumann-A
Copy link
Copy Markdown
Contributor

But if doesn't use PARENT_SCOPE, other ports will be affected. Like openmvs opencv4.

Then those ports are doing it wrong and need fixing

@JackBoosY
Copy link
Copy Markdown
Contributor

But if doesn't use PARENT_SCOPE, other ports will be affected. Like openmvs opencv4.

Then those ports are doing it wrong and need fixing

If the config file only provides targets, we should probably add these macros to the wrapper in order to adapt to the MODULE mode.
Clearly, however, the hierarchy creates a problem here.

@Neumann-A
Copy link
Copy Markdown
Contributor

If the config file only provides targets, we should probably add these macros to the wrapper in order to adapt to the MODULE mode.

Wait are some of those variables CACHE variables in MODULE mode ? If yes set them as CACHE variables !

@dalboris
Copy link
Copy Markdown

dalboris commented Apr 8, 2022

Thanks everyone for working on this!

I'd just like to remind that this PR is supposed to fix the following bug: #23694

The bug is that calling find_package(harfbuzz) in any CMakeLists produces the following warnings:

Cannot set "HARFBUZZ_LIBRARY": current scope has no parent.
Cannot set "HARFBUZZ_LIBRARIES": current scope has no parent.
Cannot set "HARFBUZZ_INCLUDE_DIR": current scope has no parent.
Cannot set "HARFBUZZ_INCLUDE_DIRS": current scope has no parent.
Cannot set "HARFBUZZ_FOUND": current scope has no parent.

because of all the lines in harfbuzzConfig.cmake.in which set a variable using PARENT_SCOPE, where in fact there is no parent scope. As of now, the PR isn't modifying these lines. It is just adding other lines, so the warning will remain and the bug will not be fixed.

I see a couple of options:

  1. Remove all PARENT_SCOPE in harfbuzzConfig.cmake.in (original commit of this PR), and fix opencv and other clients so that they do not need the variables to be set at parent scope. This seems like the ideal fix but maybe not easy, I don't know.
  2. As a workaround, in harfbuzzConfig.cmake.in, test whether there is a parent scope, and use PARENT_SCOPE or not accordingly. This seems fragile... what of use cases where there do exist a parent scope, but the client still expects the variables to be set at current scope? A possibility might be that when there is a parent scope, then the variables are set both as parent scope and current scope. And when there is no parent scope, there are set at current scope only.
  3. As a workaround, in harfbuzzConfig.cmake.in, set the variables as cache variables instead of normal variables. This seems like the easiest solution to implement, but perhaps a bit too invasive and not ideal.

Thanks!

@dg0yt
Copy link
Copy Markdown
Contributor

dg0yt commented Apr 8, 2022

If the config file only provides targets, we should probably add these macros to the wrapper in order to adapt to the MODULE mode. Clearly, however, the hierarchy creates a problem here.

There is no official Find module for Harfbuzz, so there cannot be a wrapper.

And going one step further, if there is no official Find module and upstream doesn't provide these variables in exported config, then the variables shouldn't be patched in by vcpkg IMHO. This is the wrong direction of dependencies, and it is inviting user dependencies on non-standard variables.
Instead, set variables as needed in consuming ports.
And if you need an ABC_FOUND for abc config, there find_package(ABC NAMES abc).

@dalboris
Copy link
Copy Markdown

Since implementing the "most correct" solution (fixing ports depending on Harfbuzz) seems to not get any traction, I would suggest in the meantime to implement the following workaround: testing if the current scope has a parent and applying PARENT_SCOPE or not accordingly. It would look like this:

# Set Harbuzz variables, either at the current scope or parent scope depending on the existence of
# a parent scope. Ideally, we should never set the variable at parent scope, but it is a workaround
# for some ports that expect this behavior. See https://github.com/microsoft/vcpkg/issues/23694
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
    set(HARFBUZZ_LIBRARIES harfbuzz::harfbuzz PARENT_SCOPE)
    set(HARFBUZZ_INCLUDE_DIR "${_INSTALL_DIR}/include/harfbuzz" PARENT_SCOPE)
    set(HARFBUZZ_INCLUDE_DIRS "${_INSTALL_DIR}/include/harfbuzz" PARENT_SCOPE)
    if(HARFBUZZ_LIBRARY_RELEASE)
        set(HARFBUZZ_FOUND TRUE PARENT_SCOPE)
    else()
        set(HARFBUZZ_FOUND FALSE PARENT_SCOPE)
    endif()
else()
    set(HARFBUZZ_LIBRARIES harfbuzz::harfbuzz)
    set(HARFBUZZ_INCLUDE_DIR "${_INSTALL_DIR}/include/harfbuzz")
    set(HARFBUZZ_INCLUDE_DIRS "${_INSTALL_DIR}/include/harfbuzz")
    if(HARFBUZZ_LIBRARY_RELEASE)
        set(HARFBUZZ_FOUND TRUE)
    else()
        set(HARFBUZZ_FOUND FALSE)
    endif()
endif()

Should I make a PR with such change? Or maybe @LilyWangLL you could integrate this change to this PR so we can see if the checks pass with this approach?

Thanks!

@dalboris
Copy link
Copy Markdown

dalboris commented Jun 1, 2022

Any updates on this?

@LilyWangLL
Copy link
Copy Markdown
Contributor Author

Any updates on this?

Sorry I missed the previous comment, I will test this soon. Thanks very much for your suggestion~

@dalboris
Copy link
Copy Markdown

dalboris commented Jun 2, 2022

@LilyWangLL Perfect, thanks a lot!

Lily Wang added 3 commits June 2, 2022 01:36
…LilyWang/issue23694

# Conflicts:
#	ports/harfbuzz/vcpkg.json
#	versions/baseline.json
#	versions/h-/harfbuzz.json
…LL/vcpkg into dev/LilyWang/issue23694

# Conflicts:
#	versions/h-/harfbuzz.json
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new experimental fast check for PR issues. Please let us know if this bot is helpful!

After committing all other changes, the version database must be updated
git add -u && git commit
git checkout a2d8a7cbb15cac91d6c59cd967ef9d85105832c3 -- versions
./vcpkg x-add-version --all
Diff
diff --git a/versions/baseline.json b/versions/baseline.json
index 78c0722..13c3396 100644
--- a/versions/baseline.json
+++ b/versions/baseline.json
@@ -2738,7 +2738,7 @@
     },
     "harfbuzz": {
       "baseline": "4.2.0",
-      "port-version": 0
+      "port-version": 1
     },
     "hash-library": {
       "baseline": "8",
diff --git a/versions/h-/harfbuzz.json b/versions/h-/harfbuzz.json
index 32ecc78..dd67748 100644
--- a/versions/h-/harfbuzz.json
+++ b/versions/h-/harfbuzz.json
@@ -1,5 +1,10 @@
 {
   "versions": [
+    {
+      "git-tree": "668c7b8a674e336506ce31422bce05fce79345b9",
+      "version": "4.2.0",
+      "port-version": 1
+    },
     {
       "git-tree": "02ad2865be7815604bb2c0e6cbc368f3d23d93d6",
       "version": "4.2.0",

@LilyWangLL LilyWangLL marked this pull request as ready for review June 6, 2022 08:18
@LilyWangLL LilyWangLL requested a review from JackBoosY June 6, 2022 08:19
@JackBoosY JackBoosY added the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Jun 6, 2022
@LilyWangLL
Copy link
Copy Markdown
Contributor Author

Closed as duplicate to #25092

@LilyWangLL LilyWangLL closed this Jun 9, 2022
@LilyWangLL LilyWangLL deleted the dev/LilyWang/issue23694 branch June 9, 2022 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:port-bug The issue is with a library, which is something the port should already support requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[harfbuzz] Regression: Cannot set "HARFBUZZ_LIBRARY": current scope has no parent

5 participants