File: 0008-Do-not-embed-build-directory-in-binaries.patch

package info (click to toggle)
opencv 4.10.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 282,280 kB
  • sloc: cpp: 1,178,077; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (134 lines) | stat: -rw-r--r-- 6,578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
From: Victor Westerhuis <victor@westerhu.is>
Date: Sat, 19 Nov 2022 21:45:39 +0100
Subject: Do not embed build directory in binaries

This makes the opencv core module build reproducibly.
---
 modules/core/CMakeLists.txt                   | 10 ------
 modules/core/include/opencv2/core/private.hpp |  4 +--
 modules/core/include/opencv2/core/utility.hpp |  4 +--
 modules/core/src/utils/datafile.cpp           | 48 +--------------------------
 4 files changed, 5 insertions(+), 61 deletions(-)

Index: opencv/modules/core/CMakeLists.txt
===================================================================
--- opencv.orig/modules/core/CMakeLists.txt	2024-12-11 01:59:53.187047726 +0000
+++ opencv/modules/core/CMakeLists.txt	2024-12-11 01:59:53.183047838 +0000
@@ -215,16 +215,6 @@
 ")
 endif()
 
-set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
-#define OPENCV_BUILD_DIR \"${CMAKE_BINARY_DIR}\"
-")
-
-file(RELATIVE_PATH SOURCE_DIR_RELATIVE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
-set(OPENCV_DATA_CONFIG_STR "${OPENCV_DATA_CONFIG_STR}
-#define OPENCV_DATA_BUILD_DIR_SEARCH_PATHS \\
-    \"${SOURCE_DIR_RELATIVE}/\"
-")
-
 if(WIN32)
   file(RELATIVE_PATH INSTALL_DATA_DIR_RELATIVE "${CMAKE_INSTALL_PREFIX}/${OPENCV_BIN_INSTALL_PATH}" "${CMAKE_INSTALL_PREFIX}/${OPENCV_OTHER_INSTALL_PATH}")
 else()
Index: opencv/modules/core/include/opencv2/core/private.hpp
===================================================================
--- opencv.orig/modules/core/include/opencv2/core/private.hpp	2024-12-11 01:59:53.187047726 +0000
+++ opencv/modules/core/include/opencv2/core/private.hpp	2024-12-11 01:59:53.183047838 +0000
@@ -825,10 +825,10 @@
 2. Check path specified by configuration parameter with "_HINT" suffix (name of environment variable).
 3. Check path specified by configuration parameter (name of environment variable).
    If parameter value is not empty and nothing is found then stop searching.
-4. Detects build/install path based on:
+4. Detects install path based on:
    a. current working directory (CWD)
    b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
-5. Scan `<source>/{,data}` directories if build directory is detected or the current directory is in source tree.
+5. Scan `<source>/{,data}` directories if the current directory is in source tree.
 6. Scan `<install>/share/OpenCV` directory if install directory is detected.
 
 @param relative_path Relative path to data file
Index: opencv/modules/core/include/opencv2/core/utility.hpp
===================================================================
--- opencv.orig/modules/core/include/opencv2/core/utility.hpp	2024-12-11 01:59:53.187047726 +0000
+++ opencv/modules/core/include/opencv2/core/utility.hpp	2024-12-11 01:59:53.183047838 +0000
@@ -1165,10 +1165,10 @@
 2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable
 3. OPENCV_SAMPLES_DATA_PATH environment variable
    If parameter value is not empty and nothing is found then stop searching.
-4. Detects build/install path based on:
+4. Detects install path based on:
    a. current working directory (CWD)
    b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
-5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree.
+5. Scan `<source>/{,data,samples/data}` directories if the current directory is in source tree.
 6. Scan `<install>/share/OpenCV` directory if install directory is detected.
 
 @see cv::utils::findDataFile
Index: opencv/modules/core/src/utils/datafile.cpp
===================================================================
--- opencv.orig/modules/core/src/utils/datafile.cpp	2024-12-11 01:59:53.187047726 +0000
+++ opencv/modules/core/src/utils/datafile.cpp	2024-12-11 01:59:53.183047838 +0000
@@ -280,32 +280,8 @@
 
 
     // Steps: 4, 5, 6
-    cv::String cwd = utils::fs::getcwd();
-    cv::String build_dir(OPENCV_BUILD_DIR);
-    bool has_tested_build_directory = false;
-    if (isSubDirectory(build_dir, cwd) || isSubDirectory(utils::fs::canonical(build_dir), utils::fs::canonical(cwd)))
-    {
-        CV_LOG_DEBUG(NULL, "utils::findDataFile(): the current directory is build sub-directory: " << cwd);
-        const char* build_subdirs[] = { OPENCV_DATA_BUILD_DIR_SEARCH_PATHS };
-        for (size_t k = 0; k < sizeof(build_subdirs)/sizeof(build_subdirs[0]); k++)
-        {
-            CV_LOG_DEBUG(NULL, "utils::findDataFile(): <build>/" << build_subdirs[k]);
-            cv::String datapath = utils::fs::join(build_dir, build_subdirs[k]);
-            if (utils::fs::isDirectory(datapath))
-            {
-                for(size_t i = search_subdir.size(); i > 0; i--)
-                {
-                    const cv::String& subdir = search_subdir[i - 1];
-                    cv::String prefix = utils::fs::join(datapath, subdir);
-                    TRY_FILE_WITH_PREFIX(prefix);
-                }
-            }
-        }
-        has_tested_build_directory = true;
-    }
-
     cv::String source_dir;
-    cv::String try_source_dir = cwd;
+    cv::String try_source_dir = utils::fs::getcwd();
     for (int levels = 0; levels < 3; ++levels)
     {
         if (utils::fs::exists(utils::fs::join(try_source_dir, "modules/core/include/opencv2/core/version.hpp")))
@@ -341,28 +317,6 @@
         CV_LOG_INFO(NULL, "Can't detect module binaries location");
     }
 
-    if (!has_tested_build_directory &&
-        (isSubDirectory(build_dir, module_path) || isSubDirectory(utils::fs::canonical(build_dir), utils::fs::canonical(module_path)))
-    )
-    {
-        CV_LOG_DEBUG(NULL, "utils::findDataFile(): the binary module directory is build sub-directory: " << module_path);
-        const char* build_subdirs[] = { OPENCV_DATA_BUILD_DIR_SEARCH_PATHS };
-        for (size_t k = 0; k < sizeof(build_subdirs)/sizeof(build_subdirs[0]); k++)
-        {
-            CV_LOG_DEBUG(NULL, "utils::findDataFile(): <build>/" << build_subdirs[k]);
-            cv::String datapath = utils::fs::join(build_dir, build_subdirs[k]);
-            if (utils::fs::isDirectory(datapath))
-            {
-                for(size_t i = search_subdir.size(); i > 0; i--)
-                {
-                    const cv::String& subdir = search_subdir[i - 1];
-                    cv::String prefix = utils::fs::join(datapath, subdir);
-                    TRY_FILE_WITH_PREFIX(prefix);
-                }
-            }
-        }
-    }
-
 #if defined OPENCV_INSTALL_DATA_DIR_RELATIVE
     if (!module_path.empty())  // require module path
     {