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 issues with resource.dat generation on Windows. #740

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions Sources/Plasma/Apps/plClient/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,39 @@ set(external_SOURCES
Voice_Chat.svg
)

if(PLASMA_EXTERNAL_RELEASE)
set(Make_Resource_Command
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/makeres.py --optimize --render --package -i ${CMAKE_CURRENT_SOURCE_DIR} -w ${CMAKE_CURRENT_BINARY_DIR} -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else(PLASMA_EXTERNAL_RELEASE)
set(Make_Resource_Command
${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/makeres.py --render --package -i ${CMAKE_CURRENT_SOURCE_DIR} -w ${CMAKE_CURRENT_BINARY_DIR} -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif(PLASMA_EXTERNAL_RELEASE)
find_program(
PNGCRUSH_EXECUTABLE pngcrush
DOC "Path to pngcrush"
)

include(CMakeDependentOption)
cmake_dependent_option(RESOURCE_OPTIMIZE "Optimize the images in resource.dat" ON PNGCRUSH_EXECUTABLE OFF)
cmake_dependent_option(RESOURCE_BRUTE "Allow pngcrush brute-force optimization" OFF PNGCRUSH_EXECUTABLE OFF)

if(RESOURCE_OPTIMIZE)
string(APPEND OPTIMIZE_ARGUMENT "--pngcrush \"${PNGCRUSH_EXECUTABLE}\" ")
endif()
if(RESOURCE_BRUTE)
string(APPEND OPTIMIZE_ARGUMENT "--brute ")
endif()

set(Make_Resource_Command
${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/makeres.py"
${OPTIMIZE_ARGUMENT}
--render --package
-i "${CMAKE_CURRENT_SOURCE_DIR}"
-w "${CMAKE_CURRENT_BINARY_DIR}"
-o "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)

add_custom_command(
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource.dat
OUTPUT resource.dat
COMMAND ${Make_Resource_Command}
DEPENDS ${external_SOURCES} ${external_SCRIPTS}
)
add_custom_target(externalResources
SOURCES ${external_SOURCES} ${external_SCRIPTS}
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resource.dat
DEPENDS resource.dat
)

source_group("Source Files" FILES ${external_SOURCES})
Expand Down
13 changes: 8 additions & 5 deletions Sources/Plasma/Apps/plClient/external/makeres.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="Don't print status messages")
parser.add_option("-r", "--render", dest="render", default=False, action="store_true", help="Perform SVG Render to images")
parser.add_option("-p", "--package", dest="package", default=False, action="store_true", help="Perform packaging into resource container")
parser.add_option("-z", "--optimize", dest="optimize", default=False, action="store_true", help="Perform PNGCrush optimization on PNG resources")
parser.add_option("-z", "--pngcrush", dest="pngcrush", type="string", help="Perform PNGCrush optimization on PNG resources")
parser.add_option("-b", "--brute", dest="brute", default=False, action="store_true", help="Allow brute-force optimization")
parser.add_option("-w", "--workpath", dest="workpath", default=".", help="Sets working output path for image renders")
parser.add_option("-o", "--outpath", dest="outpath", default=".", help="Sets output path for resource container")
parser.add_option("-i", "--inpath", dest="inpath", default=".", help="Sets input path for files to add to resource file")
Expand All @@ -72,16 +73,18 @@

## Do the work!
if options.render:
ret = subprocess.call(["python", os.path.join(inpath, "render_svg.py"), "-i", inpath, "-o", os.path.join(workpath, "render")], stdout=sys.stdout, stderr=sys.stderr)
ret = subprocess.call([sys.executable, os.path.join(inpath, "render_svg.py"), "-i", inpath, "-o", os.path.join(workpath, "render")], stdout=sys.stdout, stderr=sys.stderr)
Hoikas marked this conversation as resolved.
Show resolved Hide resolved
if ret != 0:
print("An error has occurred. Aborting.")
exit(1)

if options.optimize:
if options.pngcrush:
print("Optimizing PNGs with pngcrush...")
crush_args = [options.pngcrush, "-q", "-l", "9"]
if options.brute:
crush_args.append("-brute")
for png in glob.glob(os.path.join(workpath, "render", "*.png")):
#print("pngcrushing - {0}".format(png))
ret = subprocess.call(["pngcrush", "-q", "-l", "9", "-brute", png, "temp.png"], stdout=sys.stdout, stderr=sys.stderr)
ret = subprocess.call(crush_args + [png, "temp.png"], stdout=sys.stdout, stderr=sys.stderr)
if ret != 0:
print("An error has occurred. Aborting.")
exit(1)
Expand Down
6 changes: 4 additions & 2 deletions Sources/Plasma/Apps/plClient/external/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
wheel
https://download.lfd.uci.edu/pythonlibs/s2jqpv5t/cp27/pycairo-1.18.2-cp27-cp27m-win32.whl; sys_platform == "win32" and python_version ~= "2.7"
cairosvg==1.0.22 ; python_version ~= "2.7"
cairosvg; python_version >= "3.7"
pycairo; sys_platform == "win32" and python_version >= "3.8"
pycairo; sys_platform != "win32"
cairosvg==1.0.22
pillow