From fd9f2fc4783cc606734e61116185c032a63d54a0 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 16 Feb 2022 22:01:38 +0100 Subject: fix out-of-source builds --- test/script_loader.py | 72 --------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 test/script_loader.py (limited to 'test/script_loader.py') diff --git a/test/script_loader.py b/test/script_loader.py deleted file mode 100644 index cc73d4c..0000000 --- a/test/script_loader.py +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-or-later - -""" -Loading of parts of Haketilo source for testing in browser -""" - -# This file is part of Haketilo. -# -# Copyright (C) 2021 Wojtek Kosior -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# I, Wojtek Kosior, thereby promise not to sue for violation of this file's -# license. Although I request that you do not make use of this code in a -# proprietary program, I am not going to enforce this in court. - -from pathlib import Path -import subprocess, re - -from .misc_constants import * - -def make_relative_path(path): - path = Path(path) - - if path.is_absolute(): - path = path.relative_to(script_root) - - return path - -script_cache = {} - -def load_script(path, code_to_add=None): - """ - `path` is a .js file path in Haketilo sources. It may be absolute or - specified relative to Haketilo's project directory. `code_to_add` is - optional code to be appended to the end of the main file being imported. - it can contain directives like `#IMPORT`. - - Return a string containing script from `path` together with all other - scripts it depends on. Dependencies are wrapped in the same way Haketilo's - build system wraps them, with imports properly satisfied. The main script - being loaded is wrapped partially - it also has its imports satisfied, but - its code is executed in global scope instead of within an anonymous function - and imported variables are defined with `let` instead of `const` to allow - a dependency to be substituted by a mocked value. - """ - path = make_relative_path(path) - key = (str(path), code_to_add) - if key in script_cache: - return script_cache[key] - - append_flags = () if code_to_add is None else ('-A', ':'.join(key)) - - awk = subprocess.run(['awk', '-f', awk_script_name, '--', - *unit_test_defines, *append_flags, - '--output=amalgamate-js:' + str(path)], - stdout=subprocess.PIPE, cwd=script_root, check=True) - script = awk.stdout.decode() - script_cache[key] = script - - return script -- cgit v1.2.3