Skip to content

Commit 7e29901

Browse files
author
xuwei06
committed
Avoid relink executables when cmake files are changed
In the original util.cmake. enable_virtualenv.c is always regenerated when cmake files are changed, which leads to the relinking of all the targets depends on paddle_utils.
1 parent a3e975d commit 7e29901

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

cmake/make_resource.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
import re
3+
import sys
4+
5+
res = sys.argv[1]
6+
out = sys.argv[2]
7+
var = re.sub(r'[ .-]', '_', os.path.basename(res))
8+
9+
open(out, "w").write("const unsigned char " + var + "[] = {" + ",".join([
10+
"0x%02x" % ord(c) for c in open(res).read()
11+
]) + ",0};\n" + "const unsigned " + var + "_size = sizeof(" + var + ");\n")

cmake/util.cmake

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,9 @@ macro(add_simple_unittest TARGET_NAME)
138138
endmacro()
139139

140140
# Creates C resources file from files in given resource file
141-
function(create_resources res_file output)
142-
# Create empty output file
143-
file(WRITE ${output} "")
144-
# Get short filename
145-
string(REGEX MATCH "([^/]+)$" filename ${res_file})
146-
# Replace filename spaces & extension separator for C compatibility
147-
string(REGEX REPLACE "\\.| |-" "_" filename ${filename})
148-
# Read hex data from file
149-
file(READ ${res_file} filedata HEX)
150-
# Convert hex data for C compatibility
151-
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
152-
# Append data to output file
153-
file(APPEND ${output} "const unsigned char ${filename}[] = {${filedata}0};\nconst unsigned ${filename}_size = sizeof(${filename});\n")
141+
function(create_resources res_file output_file)
142+
add_custom_command(
143+
OUTPUT ${output_file}
144+
COMMAND python ARGS ${PROJ_ROOT}/cmake/make_resource.py ${res_file} ${output_file}
145+
DEPENDS ${res_file} ${PROJ_ROOT}/cmake/make_resource.py)
154146
endfunction()

paddle/scripts/submit_local.sh.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if [ -z "${PADDLE_NO_STAT+x}" ]; then
5050
-c ${PADDLE_CONF_HOME}/paddle.cookie \
5151
http://api.paddlepaddle.org/version 2>/dev/null`
5252
if [ $? -eq 0 ] && [ "$(ver2num @PADDLE_VERSION@)" -lt $(ver2num $SERVER_VER) ]; then
53-
echo "Paddle release a new version ${SERVER_VER}, you can get the install package in http://www.paddlepaddle.org"
53+
echo "Paddle release a new version ${SERVER_VER}, you can get the install package in http://www.paddlepaddle.org"
5454
fi
5555
fi
5656

@@ -95,7 +95,7 @@ if [ $? -eq 1 ]; then # Older version installed, or not installed at all
9595
echo "First time run paddle, need to install some python dependencies."
9696
# setuptools normalizes package version, so we need to use normalized
9797
# package version for paddle python package
98-
PYTHON_PADDLE_VERSION=$(python -c 'import packaging
98+
PYTHON_PADDLE_VERSION=$(python -c 'import packaging.version
9999
import setuptools
100100
print str(packaging.version.Version("@PADDLE_VERSION@"))
101101
' 2>/dev/null)

paddle/utils/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# The utilities for paddle
22
file(GLOB UTIL_HEADERS . *.h)
33
file(GLOB UTIL_SOURCES . *.cpp)
4-
create_resources(enable_virtualenv.py enable_virtualenv.c)
5-
set(UTIL_RES enable_virtualenv.c)
4+
create_resources(${CMAKE_CURRENT_SOURCE_DIR}/enable_virtualenv.py
5+
${CMAKE_CURRENT_SOURCE_DIR}/enable_virtualenv.c)
6+
set(UTIL_RES ${CMAKE_CURRENT_SOURCE_DIR}/enable_virtualenv.c)
67

78
if(APPLE)
89
file(GLOB UTIL_ARCH_SOURCES . arch/osx/*.cpp)

0 commit comments

Comments
 (0)