Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dependence on git for already checked out submodules #72

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

Kevin-Kellner
Copy link
Contributor

@Kevin-Kellner Kevin-Kellner commented Jan 8, 2025

Motivation

As the path provided to the if(NOT EXISTS) statement in the submodule section is not correct, the following statements will always be executed, as the files will never be found. This causes git to be used no matter what, even if the submodules are already checked out.

This PR fixes this issue by making the path dependent on ${CMAKE_CURRENT_SOURCE_DIR} and enclosing it in double quotes.

Proposed Changes

Use ${CMAKE_CURRENT_SOURCE_DIR} to specify the path to the relevant submodule CMakeLists.txt

Test Plan

Test that it still compiles. Notice that only on the first "cmake" call the submodules are fetched with this fix and the status message "-- fetching git submodule libsecutils" will not appear on subsequent calls.

@DDvO
Copy link
Member

DDvO commented Jan 9, 2025

Thank you for your PR.

Under which circumstances do you experience the problem you propose to solve here?
I cannot reproduce the issue (submodule being fetched twice), neither with repeated

cmake .

nor with, e.g.,

mkdir build
cd build
cmake -S .. -B .
cmake -S .. -B .

@Kevin-Kellner
Copy link
Contributor Author

Kevin-Kellner commented Jan 9, 2025

I experience the issue with a docker image I use for building gencmpclient. The docker image does not contain a git executable, and I clone the repo on the host, before using the docker image to build the project.

I just tried it again, here is my log, running cmake back to back with a clean repo. (On the host with MacOS, but it does not matter.)

➜  gencmpclient git:(master) mkdir build
➜  gencmpclient git:(master) cd build
➜  build git:(master) cmake -S .. -B .
-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- generic CMP client version 2.0
-- Found OpenSSL: /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib (found version "3.3.1") found components: Crypto SSL
-- using OpenSSL version 3.3.1
-- using OpenSSL inc dir /opt/homebrew/Cellar/openssl@3/3.3.1/include
-- using OpenSSL lib dir /opt/homebrew/Cellar/openssl@3/3.3.1/lib
-- using OpenSSL library /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib, /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libssl.dylib
-- build mode: Release
-- Found Git: /run/current-system/sw/bin/git (found version "2.46.0")
-- fetching git submodule libsecutils
Submodule 'libsecutils' (https://github.com/siemens/libsecutils.git) registered for path 'libsecutils'
Cloning into '/Users/z004b1ps/Repos/TestAzure/gencmpclient/libsecutils'...
remote: Enumerating objects: 132, done.
remote: Counting objects: 100% (132/132), done.
remote: Compressing objects: 100% (122/122), done.
remote: Total 132 (delta 3), reused 72 (delta 1), pack-reused 0 (from 0)
Receiving objects: 100% (132/132), 196.22 KiB | 1.90 MiB/s, done.
Resolving deltas: 100% (3/3), done.
Submodule path 'libsecutils': checked out '20c80f63dfb967a25cb0d1bcda5b179bb73b7129'
-- SecurityUtilities version 2.0.0
-- Build mode: Release
-- using OpenSSL version 3.3.1
-- using OpenSSL inc dir /opt/homebrew/Cellar/openssl@3/3.3.1/include
-- using OpenSSL lib dir /opt/homebrew/Cellar/openssl@3/3.3.1/lib
-- using OpenSSL library /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib, /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libssl.dylib
-- Configuring done (2.7s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/z004b1ps/Repos/TestAzure/gencmpclient/build


➜  build git:(master) cmake -S .. -B .
-- generic CMP client version 2.0
-- using OpenSSL version 3.3.1
-- using OpenSSL inc dir /opt/homebrew/Cellar/openssl@3/3.3.1/include
-- using OpenSSL lib dir /opt/homebrew/Cellar/openssl@3/3.3.1/lib
-- using OpenSSL library /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib, /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libssl.dylib
-- build mode: Release
-- fetching git submodule libsecutils
-- SecurityUtilities version 2.0.0
-- Build mode: Release
-- using OpenSSL version 3.3.1
-- using OpenSSL inc dir /opt/homebrew/Cellar/openssl@3/3.3.1/include
-- using OpenSSL lib dir /opt/homebrew/Cellar/openssl@3/3.3.1/lib
-- using OpenSSL library /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib, /opt/homebrew/Cellar/openssl@3/3.3.1/lib/libssl.dylib
-- Configuring done (0.3s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/z004b1ps/Repos/TestAzure/gencmpclient/build

Notice the line "-- fetching git submodule libsecutils" in the second cmake call. After the message() statement in the CMakeLists.txt executeProcess is invoked, which tries to run git. This fails in my docker image.

Edit: To clarify, it is the check "if(GIT_FOUND)" that fails and causes the issue. But it occurs because the check for the CMakeLists.txt is buggy.

@DDvO
Copy link
Member

DDvO commented Jan 9, 2025

Meanwhile I've been able to reproduce the issue and confirm the fix, both on Linux and MacOS -
I had make a mistake, sorry for the confusion.

@DDvO DDvO merged commit 2795d13 into siemens:master Jan 9, 2025
1 check failed
@DDvO
Copy link
Member

DDvO commented Jan 9, 2025

Interesting that you use a Docker image for building under MacOS - why don't you build natively unter MacOS?
I do so most of the time (and occasionally on a Linux virtual machine, using OrbStack).

I'm confused about what you wrote regarding git on Docker:
since your Docker image does not contain git, the variable GIT_FOUND should be false, and instead of "fetching git submodule libsecutils" you should have got an error message starting with ""git failed with exit code".

Update:

Edit: To clarify, it is the check "if(GIT_FOUND)" that fails and causes the issue. But it occurs because the check for the CMakeLists.txt is buggy.

What do you get on if(GIT_FOUND) failing?
I wonder why you do not get "Git not found; please install git."

@Kevin-Kellner
Copy link
Contributor Author

Interesting that you use a Docker image for building under MacOS - why don't you build natively unter MacOS?

I do built natively on MacOS for general development (which works fine). I use the linux docker image for my CI/CD pipeline which is where I noticed the error because I did not add git to the docker image.

What do you get on if(GIT_FOUND) failing?

I do get "Git not found; please install git." which cancels the cmake configure step. Sorry for being not clear about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants