diff --git a/scripts/compile_resources.py b/scripts/compile_resources.py index ca38a630a..5480b0f7d 100755 --- a/scripts/compile_resources.py +++ b/scripts/compile_resources.py @@ -38,12 +38,21 @@ extern const std::string {identifier}; {namespaces_close}""" class Resource: - def __init__(self, base_dir, filename): + def __init__(self, base_dirs, filename): filename = filename.strip() self.filename = filename self.identifier = full_identifier(filename) - with open(os.path.join(base_dir, filename), 'rb') as f: - self.data = f.read() + found = False + for base_dir in base_dirs: + try: + with open(os.path.join(base_dir, filename), 'rb') as f: + self.data = f.read() + found = True + break + except FileNotFoundError: + continue + if not found: + raise Exception("Impossible to found {}".format(filename)) def dump_impl(self): nb_row = len(self.data)//16 + (1 if len(self.data) % 16 else 0) @@ -151,13 +160,17 @@ if __name__ == "__main__": help='The Cpp file name to generate') parser.add_argument('--hfile', help='The h file name to generate') + parser.add_argument('--source_dir', + help="Additional directory where to look for resources.", + action='append') parser.add_argument('resource_file', help='The list of resources to compile.') args = parser.parse_args() base_dir = os.path.dirname(os.path.realpath(args.resource_file)) with open(args.resource_file, 'r') as f: - resources = [Resource(base_dir, filename) for filename in f.readlines()] + resources = [Resource([base_dir]+args.source_dir, filename) + for filename in f.readlines()] h_identifier = to_identifier(os.path.basename(args.hfile)) with open(args.hfile, 'w') as f: diff --git a/scripts/ctpp2c.sh b/scripts/ctpp2c.sh new file mode 100755 index 000000000..746ecccf5 --- /dev/null +++ b/scripts/ctpp2c.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + + +ctpp2c=$1 +SOURCE=$(pwd)/$2 +DEST=$3 + +$ctpp2c $SOURCE $DEST diff --git a/scripts/meson.build b/scripts/meson.build index 4315d9212..c74cb8577 100644 --- a/scripts/meson.build +++ b/scripts/meson.build @@ -1,4 +1,5 @@ res_compiler = find_program('compile_resources.py') +intermediate_ctpp2c = find_program('ctpp2c.sh') install_data(res_compiler.path(), install_dir:get_option('bindir')) diff --git a/static/meson.build b/static/meson.build index b1ffffc7a..67e6fa834 100644 --- a/static/meson.build +++ b/static/meson.build @@ -1,7 +1,19 @@ +ctpp2c = find_program('ctpp2c') +search_result_template = custom_target('result_template', + input: 'results.tmpl', + output: 'results.ct2', + command: [intermediate_ctpp2c, ctpp2c, '@INPUT@', '@OUTPUT@'] +) + lib_resources = custom_target('resources', input: 'resources_list.txt', output: ['kiwixlib-resources.cpp', 'kiwixlib-resources.h'], - command:[res_compiler, '--cxxfile', '@OUTPUT0@', '--hfile', '@OUTPUT1@', '@INPUT@'] -) \ No newline at end of file + command:[res_compiler, + '--cxxfile', '@OUTPUT0@', + '--hfile', '@OUTPUT1@', + '--source_dir', '@OUTDIR@', + '@INPUT@'], + depends: [search_result_template] +) diff --git a/static/results.ct2 b/static/results.ct2 deleted file mode 100644 index 81e59ba10..000000000 Binary files a/static/results.ct2 and /dev/null differ diff --git a/static/results.tmpl b/static/results.tmpl new file mode 100644 index 000000000..1d95b8012 --- /dev/null +++ b/static/results.tmpl @@ -0,0 +1,127 @@ + + + + + + Search: <TMPL_var searchPattern> + + +
+ Results - of for No result were found for +
+ +
+ +
+ + + + + diff --git a/travis/install_deps.sh b/travis/install_deps.sh index ce1cd71de..c656e0b56 100755 --- a/travis/install_deps.sh +++ b/travis/install_deps.sh @@ -8,22 +8,22 @@ ARCHIVE_NAME=deps_${PLATFORM}_${REPO_NAME}.tar.gz # Packages. case ${PLATFORM} in "native_static") - PACKAGES="gcc cmake libbz2-dev ccache zlib1g-dev uuid-dev libctpp2-dev" + PACKAGES="gcc cmake libbz2-dev ccache zlib1g-dev uuid-dev libctpp2-dev ctpp2-utils" ;; "native_dyn") - PACKAGES="gcc cmake libbz2-dev ccache zlib1g-dev uuid-dev libctpp2-dev libmicrohttpd-dev" + PACKAGES="gcc cmake libbz2-dev ccache zlib1g-dev uuid-dev libctpp2-dev ctpp2-utils libmicrohttpd-dev" ;; "win32_static") - PACKAGES="g++-mingw-w64-i686 gcc-mingw-w64-i686 gcc-mingw-w64-base mingw-w64-tools ccache" + PACKAGES="g++-mingw-w64-i686 gcc-mingw-w64-i686 gcc-mingw-w64-base mingw-w64-tools ccache ctpp2-utils" ;; "win32_dyn") - PACKAGES="g++-mingw-w64-i686 gcc-mingw-w64-i686 gcc-mingw-w64-base mingw-w64-tools ccache" + PACKAGES="g++-mingw-w64-i686 gcc-mingw-w64-i686 gcc-mingw-w64-base mingw-w64-tools ccache ctpp2-utils" ;; "android_arm") - PACKAGES="gcc cmake ccache" + PACKAGES="gcc cmake ccache ctpp2-utils" ;; "android_arm64") - PACKAGES="gcc cmake ccache" + PACKAGES="gcc cmake ccache ctpp2-utils" ;; esac