Use Urho3D custom HTML shell for Emscripten build.

Simplify the custom command for share data generation since we are not going to "fix" the UUID issue of the file_packager.py anymore. Although this would mean the slightest change in the output JS file caused by UUID change could force a long relink process in our build.
For Travis CI - upload Emscripten HTML5 samples to Urho3D main website.
[ci package]
This commit is contained in:
Yao Wei Tjong 姚伟忠 2015-03-05 16:23:59 +08:00
parent 6f68c07486
commit 6c3d32d64a
2 changed files with 67 additions and 27 deletions

View File

@ -900,18 +900,9 @@ macro (setup_main_executable)
get_filename_component (NAME ${DIR} NAME)
set (RESOURCE_${DIR}_PATHNAME ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}.pak)
list (APPEND RESOURCE_PAKS ${RESOURCE_${DIR}_PATHNAME})
if (EMSCRIPTEN)
if (EMSCRIPTEN_SHARE_DATA)
# Set the custom EMCC_OPTION property to peload the generated shared data
if (NOT SHARED_RESOURCE_JS) # Only need once
set (SHARED_RESOURCE_JS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_PROJECT_NAME}.js)
list (APPEND SOURCE_FILES ${SHARED_RESOURCE_JS})
set_source_files_properties (${SHARED_RESOURCE_JS} PROPERTIES GENERATED TRUE EMCC_OPTION pre-js)
endif ()
else ()
# Set the custom EMCC_OPTION property to preload the *.pak individually
set_source_files_properties (${RESOURCE_${DIR}_PATHNAME} PROPERTIES EMCC_OPTION preload-file EMCC_FILE_ALIAS @/${NAME}.pak)
endif ()
if (EMSCRIPTEN AND NOT EMSCRIPTEN_SHARE_DATA)
# Set the custom EMCC_OPTION property to preload the *.pak individually
set_source_files_properties (${RESOURCE_${DIR}_PATHNAME} PROPERTIES EMCC_OPTION preload-file EMCC_FILE_ALIAS "@/${NAME}.pak --use-preload-cache")
endif ()
endforeach ()
# Urho3D project builds the PackageTool as required; external project uses PackageTool found in the Urho3D build tree or Urho3D SDK
@ -922,8 +913,29 @@ macro (setup_main_executable)
set (PACKAGING_DEP DEPENDS PackageTool)
endif ()
set (PACKAGING_COMMENT " and packaging")
# The *.pak will be generated during build time, suppress error during CMake configuration/generation time
set_property (SOURCE ${RESOURCE_PAKS} PROPERTY GENERATED TRUE)
if (EMSCRIPTEN)
# Check if shell-file is already added in source files list
foreach (FILE ${SOURCE_FILES})
get_property (EMCC_OPTION SOURCE ${FILE} PROPERTY EMCC_OPTION)
if (EMCC_OPTION STREQUAL shell-file)
set (SHELL_HTML_FOUND TRUE)
break ()
endif ()
endforeach ()
if (NOT SHELL_HTML_FOUND)
# Use custom Urho3D shell.html
set (SHELL_HTML ${CMAKE_BINARY_DIR}/Source/shell.html)
list (APPEND SOURCE_FILES ${SHELL_HTML})
set_source_files_properties (${SHELL_HTML} PROPERTIES EMCC_OPTION shell-file)
endif ()
# Set the custom EMCC_OPTION property to peload the generated shared data file
if (EMSCRIPTEN_SHARE_DATA)
set (SHARED_RESOURCE_JS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_PROJECT_NAME}.js)
list (APPEND SOURCE_FILES ${SHARED_RESOURCE_JS} ${SHARED_RESOURCE_JS}.data)
set_source_files_properties (${SHARED_RESOURCE_JS} PROPERTIES GENERATED TRUE EMCC_OPTION pre-js)
endif ()
endif ()
endif ()
if (XCODE)
if (NOT RESOURCE_FILES)
@ -1050,18 +1062,18 @@ macro (setup_main_executable)
add_dependencies (${TARGET_NAME} ${RESOURCE_CHECK_${MD5ALL}})
endif ()
# Define a custom command for generating a shared data files (if enabled)
# Define a custom command for generating a shared data file (if enabled)
if (EMSCRIPTEN_SHARE_DATA AND RESOURCE_PAKS)
# When sharing a single data file, all main targets are assumed to use a same set of resource paks
foreach (FILE ${RESOURCE_PAKS})
get_filename_component (NAME ${FILE} NAME)
list (APPEND PAK_NAMES ${NAME})
endforeach ()
add_custom_command (OUTPUT ${SHARED_RESOURCE_JS}
COMMAND ${EMPACKAGER} ${SHARED_RESOURCE_JS}.data --preload ${PAK_NAMES} --js-output=${SHARED_RESOURCE_JS}.new --use-preload-cache && ${CMAKE_COMMAND} -E copy_if_different ${SHARED_RESOURCE_JS}.new ${SHARED_RESOURCE_JS} && ${CMAKE_COMMAND} -E remove ${SHARED_RESOURCE_JS}.new
add_custom_command (OUTPUT ${SHARED_RESOURCE_JS}.data
COMMAND ${EMPACKAGER} ${SHARED_RESOURCE_JS}.data --preload ${PAK_NAMES} --js-output=${SHARED_RESOURCE_JS} --use-preload-cache
DEPENDS RESOURCE_CHECK ${RESOURCE_PAKS}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Creating shared data files")
COMMENT "Generating shared data file")
endif ()
endmacro ()
@ -1334,7 +1346,7 @@ macro (install_header_files)
endif ()
endmacro ()
# Set common project structure for Android platform
# Set common project structure for some platforms
if (ANDROID)
# Enable Android ndk-gdb
if (ANDROID_NDK_GDB)
@ -1366,6 +1378,14 @@ if (ANDROID)
create_symlink (${CMAKE_SOURCE_DIR}/Android/${I} ${CMAKE_BINARY_DIR}/${I} FALLBACK_TO_COPY)
endif ()
endforeach ()
elseif (EMSCRIPTEN)
# Create Urho3D custom HTML shell that also embeds our own project logo
if (NOT EXISTS ${CMAKE_BINARY_DIR}/Source/shell.html)
file (READ ${EMSCRIPTEN_ROOT_PATH}/src/shell.html SHELL_HTML)
string (REPLACE "<!doctype html>" "<!-- This is a generated file. DO NOT EDIT!-->\n\n<!doctype html>" SHELL_HTML "${SHELL_HTML}") # Stringify to preserve semicolons
string (REPLACE "<body>" "<body>\n\n<a href=\"http://urho3d.github.io\" title=\"Urho3D Homepage\"><img src=\"http://urho3d.github.io/assets/images/logo.png\" alt=\"link to http://urho3d.github.io\" height=\"80\" width=\"320\" /></a>\n" SHELL_HTML "${SHELL_HTML}")
file (WRITE ${CMAKE_BINARY_DIR}/Source/shell.html "${SHELL_HTML}")
endif ()
endif ()
# Post-CMake fixes

View File

@ -195,7 +195,7 @@ task :ci_site_update do
unless release == 'HEAD'
system "mkdir -p ../doc-Build/documentation/#{release}" or abort 'Failed to create directory for new document version'
system "ruby -i -pe 'gsub(/HEAD/, %q{#{release}})' ../Build/Docs/minimal-header.html" or abort 'Failed to update document version in YAML Front Matter block'
append_new_release release, '../doc-Build/_data/urho3d.json' or abort 'Failed to add new release to document data file'
append_new_release release or abort 'Failed to add new release to document data file'
end
# Generate and sync doxygen pages
system "cd ../Build && make -j$NUMJOBS doc >/dev/null 2>&1 && ruby -i -pe 'gsub(/(<\\/?h)3([^>]*?>)/, %q{\\14\\2}); gsub(/(<\\/?h)2([^>]*?>)/, %q{\\13\\2}); gsub(/(<\\/?h)1([^>]*?>)/, %q{\\12\\2})' Docs/html/_*.html && rsync -a --delete Docs/html/ ../doc-Build/documentation/#{release}" or abort 'Failed to generate/rsync doxygen pages'
@ -218,6 +218,19 @@ task :ci_site_update do
end
end
# Usage: NOT intended to be used manually (if you insist then try: GIT_NAME=... GIT_EMAIL=... GH_TOKEN=... rake ci_emscripten_samples_update)
desc 'Update Emscripten HTML5 samples to GitHub Pages'
task :ci_emscripten_samples_update do
# Pull or clone
system 'cd ../doc-Build 2>/dev/null && git pull -q -r || git clone --depth 1 -q https://github.com/urho3d/urho3d.github.io.git ../doc-Build' or abort 'Failed to pull/clone'
# Update Emscripten json data file
update_emscripten_data or abort 'Failed to update Emscripten json data file'
# Sync Emscripten samples
system "rsync -a --delete --exclude tool ../Build/bin/ ../doc-Build/samples" or abort 'Failed to rsync Emscripten samples'
# Supply GIT credentials and push the changes to urho3d/urho3d.github.io.git
system "cd ../doc-Build && git config user.name $GIT_NAME && git config user.email $GIT_EMAIL && git remote set-url --push origin https://$GH_TOKEN@github.com/urho3d/urho3d.github.io.git && git add -A . && ( git commit -q -m \"Travis CI: Emscripten samples update at #{Time.now.utc}.\n\nCommit: https://github.com/$TRAVIS_REPO_SLUG/commit/$TRAVIS_COMMIT\n\nMessage: $COMMIT_MESSAGE\" || true) && git push -q >/dev/null 2>&1" or abort 'Failed to update Emscripten samples'
end
# Usage: NOT intended to be used manually (if you insist then try: GIT_NAME=... GIT_EMAIL=... GH_TOKEN=... TRAVIS_BRANCH=... rake ci_rebase)
desc 'Rebase all CI mirror branches'
task :ci_rebase do
@ -542,7 +555,7 @@ def xcode_ci
xcode_build(ENV['IOS'], '../Build/generated/UsingSDK/Scaffolding.xcodeproj') or abort 'Failed to build/test temporary project using Urho3D as external library'
end
def xcode_build(ios, project, target = 'ALL_BUILD', extras = '')
def xcode_build ios, project, target = 'ALL_BUILD', extras = ''
sdk = ios.to_i == 1 ? '-sdk iphonesimulator' : ''
# Use xcpretty to filter output from xcodebuild when building
system "xcodebuild -project #{project} -target #{target} -configuration #{$configuration} #{sdk} |xcpretty -c #{extras} && exit ${PIPESTATUS[0]}" or return nil
@ -553,15 +566,24 @@ def xcode_build(ios, project, target = 'ALL_BUILD', extras = '')
return 0
end
def append_new_release release, filename
def append_new_release release, filename = '../doc-Build/_data/urho3d.json'
begin
urho3d_hash = JSON.parse File.read filename
unless urho3d_hash['releases'].last == release
urho3d_hash['releases'] << release
end
File.open filename, 'w' do |file|
file.puts urho3d_hash.to_json
end
File.open(filename, 'w') { |file| file.puts urho3d_hash.to_json }
return 0
rescue
nil
end
end
def update_emscripten_data dir = '../doc-Build/samples', filename = '../doc-Build/_data/emscripten.json'
begin
emscripten_hash = JSON.parse File.read filename
Dir.chdir(dir) { emscripten_hash['samples'] = Dir['*.html'].sort }
File.open(filename, 'w') { |file| file.puts emscripten_hash.to_json }
return 0
rescue
nil
@ -572,9 +594,7 @@ def bump_soversion filename
begin
version = File.read(filename).split '.'
bump_version version, 2
File.open filename, 'w' do |file|
file.puts version.join '.'
end
File.open(filename, 'w') { |file| file.puts version.join '.' }
return 0
rescue
nil