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

Overhaul of the Assets #3269

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ vtest/Pictures
.vs
dependencies

# Downloaded files during build process
# Files generated or downloaded during build process
MS_General.sf3
MS_General-License.md
MS_General-changelog.txt
Expand All @@ -49,3 +49,5 @@ MuseScore_General-changelog.txt
VERSION
/mscore/data/mscore.aps
/msvc.*
/mscore/data/splash.svg
/mscore/data/icons/mscore.svg
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ matrix:
- libpulse-dev
- libgtk2.0-bin
- expect
# assets build
- imagemagick
- pngcrush
- libxml2-utils # xmllint
- icnsutils # png2icns
- fonts-roboto
cache:
directories:
- $HOME/.ccache
Expand Down Expand Up @@ -128,6 +134,7 @@ matrix:
install:
- source ./build/travis/job_macos_lupdate/install.sh
script:
- "./build/travis/job_macos_lupdate/build-assets.sh"
- "./build/travis/job_macos_lupdate/script.sh"

notifications:
Expand Down
61 changes: 61 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ option(COVERAGE "Build with instrumentation to record code coverage." OFF)
option(BUILD_64 "Build 64 bit version of editor" ON)
option(BUILD_AUTOUPDATE "Build with autoupdate support" OFF)

# set options for assets build (overrides defaults set in assets/CMakeLists.txt)
option(DOWNLOAD_ASSETS "Download pre-built assets (icons and images) rather than attempting to build from source SVGs." ON)
option(ONLY_BUILD_ASSETS "Only build the assets (icons and images), don't compile MuseScore." OFF)
if(MSCORE_UNSTABLE)
option(OPTIMIZE_PNGS_BRUTE "Use maximum PNG compression for assets (takes time)" OFF)
else(MSCORE_UNSTABLE)
option(OPTIMIZE_PNGS_BRUTE "Use maximum PNG compression for assets (takes time)" ON)
endif(MSCORE_UNSTABLE)

if (APPLE)
set (CMAKE_CXX_COMPILER clang++)
set (CMAKE_CXX_COMPILER_ID "Clang")
Expand Down Expand Up @@ -264,6 +273,58 @@ SET(MUSESCORE_NAME_VERSION "${MUSESCORE_NAME} ${MUSESCORE_VERSION_MAJOR}")
#
SET(MUSESCORE_VERSION_FULL "${MUSESCORE_VERSION}.${MUSESCORE_VERSION_PATCH}")

set(ASSETS_BINARY_DIR "${PROJECT_BINARY_DIR}/assets") # assets generated here
set(ASSETS_ARCHIVE_NAME "${MUSESCORE_NAME}-assets-${MUSESCORE_VERSION_FULL}.zip")
# NOTE: Different branches may share assets or have different assets depending
# on whether the branches have the same value for ${ASSETS_ARCHIVE_NAME}.
if (DOWNLOAD_ASSETS)
# Download assets instead of building from source
set(ASSETS_REMOTE "https://transfer.sh/QCx9R/${ASSETS_ARCHIVE_NAME}") # TODO: fetch from MuseScore server
set(ASSETS_LOCAL "${ASSETS_BINARY_DIR}/${ASSETS_ARCHIVE_NAME}")
set(ASSETS_PREVIOUS "${ASSETS_BINARY_DIR}/last_extracted") # file contains name of the last archive extracted
set(EXTRACT_ASSETS TRUE) # whether to extract the archive
if(EXISTS "${ASSETS_LOCAL}")
message("Using existing assets archive: ${ASSETS_LOCAL}")
# Although we can reuse the archive, we still need to extract it if an
# archive from a branch with different assets has been extracted
if(EXISTS "${ASSETS_PREVIOUS}")
file(STRINGS "${ASSETS_PREVIOUS}" PREVIOUS_ARCHIVE)
string(COMPARE NOTEQUAL "${ASSETS_ARCHIVE_NAME}" "${PREVIOUS_ARCHIVE}" EXTRACT_ASSETS)
endif(EXISTS "${ASSETS_PREVIOUS}")
else(EXISTS "${ASSETS_PREVIOUS}")
message("Downloading assets...")
file(DOWNLOAD "${ASSETS_REMOTE}" "${ASSETS_LOCAL}" SHOW_PROGRESS STATUS DL_STATUS)
list(GET DL_STATUS 0 RET_VAL)
if (NOT RET_VAL EQUAL 0)
list(GET DL_STATUS 1 STATUS_TEXT)
message(FATAL_ERROR "Unable to download assets. Error ${RET_VAL}: ${STATUS_TEXT}")
endif(NOT RET_VAL EQUAL 0)
endif(EXISTS "${ASSETS_LOCAL}")
if(EXTRACT_ASSETS)
message("Extracting assets...")
# Extract with CMake's built-in tar to avoid depending on system tar
execute_process(
COMMAND "${CMAKE_COMMAND}" -E tar "xfv" "${ASSETS_ARCHIVE_NAME}"
WORKING_DIRECTORY "${ASSETS_BINARY_DIR}"
RESULT_VARIABLE RET_VAL
)
if(NOT RET_VAL STREQUAL "0") # compare strings as RET_VAL not always a number
message(FATAL_ERROR "Unable to extract assets archive. Error ${RET_VAL}")
endif(NOT RET_VAL STREQUAL "0")
file(WRITE "${ASSETS_PREVIOUS}" "${ASSETS_ARCHIVE_NAME}")
endif(EXTRACT_ASSETS)
else (DOWNLOAD_ASSETS)
# build icons and resources from source files
add_subdirectory(assets)
# NOTE: downloaded assets are available immediately whereas built assets will
# not be available until the build takes place. This affects which CMake
# commands can be used to interact with them. See assets/README.md.
endif (DOWNLOAD_ASSETS)

if (ONLY_BUILD_ASSETS)
return() # exit here
endif (ONLY_BUILD_ASSETS)

if (BUILD_WEBENGINE)
if (MINGW)
SET (USE_WEBENGINE 0)
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BUILD_WEBENGINE="ON" # Override with "OFF" to disable.
USE_SYSTEM_FREETYPE="OFF" # Override with "ON" to enable. Requires freetype >= 2.5.2.
COVERAGE="OFF" # Override with "ON" to enable.
DOWNLOAD_SOUNDFONT="ON" # Override with "OFF" to disable latest soundfont download.
DOWNLOAD_ASSETS="ON" # Override with "OFF" to ensure build fails if assets cannot be built from source.

UPDATE_CACHE="TRUE"# Override if building a DEB or RPM, or when installing to a non-standard location.
NO_RPATH="FALSE"# Package maintainers may want to override this (e.g. Debian)
Expand All @@ -63,6 +64,7 @@ release:
-DBUILD_WEBENGINE="${BUILD_WEBENGINE}" \
-DUSE_SYSTEM_FREETYPE="${USE_SYSTEM_FREETYPE}" \
-DDOWNLOAD_SOUNDFONT="${DOWNLOAD_SOUNDFONT}" \
-DDOWNLOAD_ASSETS="${DOWNLOAD_ASSETS}" \
-DCMAKE_SKIP_RPATH="${NO_RPATH}" ..; \
make lrelease; \
make -j ${CPUS}; \
Expand Down Expand Up @@ -92,6 +94,7 @@ debug:
-DUSE_SYSTEM_FREETYPE="${USE_SYSTEM_FREETYPE}" \
-DCOVERAGE="${COVERAGE}" \
-DDOWNLOAD_SOUNDFONT="${DOWNLOAD_SOUNDFONT}" \
-DDOWNLOAD_ASSETS="${DOWNLOAD_ASSETS}" \
-DCMAKE_SKIP_RPATH="${NO_RPATH}" ..; \
make lrelease; \
make -j ${CPUS}; \
Expand Down
1 change: 1 addition & 0 deletions all.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@

#include <QSvgRenderer>
#include <QSvgGenerator>
#include <QSvgWidget> // use in preference to QPixmap and QLabel where possible

#include <QNetworkAccessManager>
#include <QNetworkReply>
Expand Down
19 changes: 19 additions & 0 deletions assets/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: https://EditorConfig.org

# Text editors and IDEs that support the EditorConfig standard will format and
# indent text files according to the rules in this file. You can use `eclint`
# <https://github.com/jedmao/eclint> to check code files against these rules
# and flag any violations: simply run `eclint check` from this directory. You
# could set up a pre-commit hook to run the check each time you commit.

# top-most EditorConfig file (treat assets as independent project)
root = true

# Formatting rules for all text files
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
117 changes: 117 additions & 0 deletions assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Create a new CMake project for the assets to allow them to be generated
# independently of MuseScore's build.
project("MuseScore assets"
DESCRIPTION "Build MuseScore's icons and resources from SVG source files"
LANGUAGES NONE
)

cmake_minimum_required(VERSION 3.0)

if(WIN32)
set(WIN_NOT_AVAIL "Not available on Windows")
option(BUILD_MACOS_ICONS "${WIN_NOT_AVAIL}" OFF)
endif(WIN32)

# The following options are enabled/disabled as appropriate for somebody
# building the assets alone. If MuseScore requires different settings then
# these should be made in MuseScore's top-level CMakeLists.txt. Options with
# the same name in MuseScore's CMakeLists.txt will override the ones here.
option(TESTS "Run code validation and other checks during the build process" ON)
option(STRICT_FONTS "Fail build if required fonts are not installed (disable to allow build to proceed using a fallback font)" ON)
option(STRICT_VARIABLES "Fail build if required variables are not defined (disable to allow build to proceed using default values)" ON)
option(BUILD_WINDOWS_ICONS "Build ICO icon files for Windows" ON)
option(BUILD_MACOS_ICONS "Build ICNS icon files for macOS" ON)
option(BUILD_FREEDESKTOP_ICONS "Build PNG icons for Linux and other systems that follow the FreeDesktop.org specifications" ON)
option(OPTIMIZE_SVGS "Optimize SVG file size using SVGO" ON)
option(OPTIMIZE_PNGS "Optimize PNG file size using PNGCRUSH" ON)
option(OPTIMIZE_PNGS_BRUTE "Try all PNG compression methods to ensure smallest possible size (takes time)" OFF)

# Load CMake functions defined in other files - modular programming (sort of)
include("basic-functions.cmake")
include("image-functions.cmake")
if(STRICT_FONTS)
include("font-dependencies.cmake")
else(STRICT_FONTS)
message(STATUS "Not checking system fonts (STRICT_FONTS is OFF)")
endif(STRICT_FONTS)

# Some assets depend on variables defined in MuseScore's CMakeLists.txt
# set default values here to allow independent building of the assets.
required_variable(MUSESCORE_NAME "MuseScore")
required_variable(MUSESCORE_VERSION_FULL "X.Y.Z")

# Optionally pack assets into a ZIP file for easy distribution.
set(ASSETS_ARCHIVE_NAME "${MUSESCORE_NAME}-assets-${MUSESCORE_VERSION_FULL}.zip")

# Store a list of all assets generated as part of the build.
set(ASSETS_MANIFEST "assets-manifest.txt") # used for archiving and CI tests.
# As a basic CI test, a reference copy of this file is checked into the repo
# and compared to the one generated during the build to ensure they match.
# This will catch simple errors, but assets must still be compared visually.

# create empty manifest file to append to
file(WRITE "${PROJECT_BINARY_DIR}/${ASSETS_MANIFEST}" "# DO NOT EDIT!!! This file is generated during the build.\n")

function(add_to_manifest # add assets to the manifest file
ASSET # name of asset file to be added to manifest
# ARGN optionally specify more asset files as additional arguments
)
foreach(FILE "${ASSET}" ${ARGN})
# expand path to asset file to make it relative to the build directory
file(RELATIVE_PATH PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${FILE}")
file(APPEND "${PROJECT_BINARY_DIR}/${ASSETS_MANIFEST}" "${PATH}\n")
endforeach(FILE)
endfunction(add_to_manifest)

add_subdirectory(resources) # resources first (everything depends on them)

add_custom_target("assets" ALL) # main target to build all other assets

add_subdirectory(brand)
add_subdirectory(platform)
add_subdirectory(splash)

# Read in the manifest we just created (ignore lines that begin with '#')
file(STRINGS "${PROJECT_BINARY_DIR}/${ASSETS_MANIFEST}" ASSET_FILES REGEX "^[^#]")
set(ASSET_FILES_ABS "")
foreach(ASSET ${ASSET_FILES})
list(APPEND ASSET_FILES_ABS "${PROJECT_BINARY_DIR}/${ASSET}")
endforeach(ASSET)

# optional target to create a compressed ZIP archive containing all assets
add_custom_target("assets_archive" DEPENDS "${ASSETS_ARCHIVE_NAME}")
add_dependencies("assets_archive" "assets") # assets must be built first
add_custom_command(
OUTPUT "${ASSETS_ARCHIVE_NAME}"
DEPENDS ${ASSET_FILES_ABS} # rebuild if any of these files have changed (absolute paths required)
COMMAND "${CMAKE_COMMAND}" -E tar "cfv" "${ASSETS_ARCHIVE_NAME}" --format=zip ${ASSET_FILES}
VERBATIM
)

if(TESTS)
# POST CONFIGURE CHECKS - these are run by CMake just before it exits.
# NOTE: CMake only runs on the first build or when the CMake or configured
# files change. All other files must be checked at build time.
required_program(GIT "Distributed VCS - https://git-scm.com/" "git")
execute_process(
COMMAND "${GIT}" diff --color --no-index "${PROJECT_SOURCE_DIR}/${ASSETS_MANIFEST}" "${ASSETS_MANIFEST}"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}"
RESULT_VARIABLE RET_VAL
)
if(RET_VAL STREQUAL "1") # compare strings as RET_VAL not always a number
message(FATAL_ERROR "Generated manifest doesn't match the repository version.")
elseif(NOT RET_VAL STREQUAL "0")
message(FATAL_ERROR "Diff command exited with '${RET_VAL}' indicating an error occured.")
endif(RET_VAL STREQUAL "1")

# PRE BUILD CHECKS - Run by the native build tool as soon as it starts.
# NOTE: The build tool runs on every build, so these checks do too.
required_program(ECLINT "Tool for checking code formatting and indentation - https://github.com/jedmao/eclint" "eclint")
add_custom_target("assets_sanitycheck" ALL
COMMAND "${ECLINT}" check # ignores all files in .gitignore
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM USES_TERMINAL
)
# now ensure check runs before everything else
add_dependencies("assets_resources" "assets_sanitycheck")
endif(TESTS)
Loading