Skip to content

Commit

Permalink
meson: add script to fix up sourcemap by adding sourceRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
takase1121 committed Nov 13, 2024
1 parent 7ab31fd commit ba9b0be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
26 changes: 26 additions & 0 deletions scripts/fix-sourcemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

import json
from argparse import ArgumentParser, FileType


def main():
parser = ArgumentParser()
parser.add_argument(
"sourcemap",
type=FileType("r+", encoding="utf-8"),
help="The sourcemap to modify",
)
parser.add_argument("base_url", help="The sourceRoot URL")
args = parser.parse_args()

content = json.load(args.sourcemap)
if content["version"] < 3:
raise ValueError("Sourcemap version 2 and lower is not supported")
content["sourceRoot"] = args.base_url
args.sourcemap.seek(0)
json.dump(content, args.sourcemap)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions scripts/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ if host_machine.system() == 'windows'
elif host_machine.system() == 'emscripten'
python_exe = find_program('python3', 'python')
wasm_bundler_exe = [python_exe, meson.current_source_dir() / 'generate-wasm-bundle.py']
sourcemap_fixer_exe = [python_exe, meson.current_source_dir() / 'fix-sourcemap.py']
endif

3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ lite_exe = executable('lite-xl',
)

if get_option('wasm_debug') == 'sourcemap'
python_exe = find_program('python3', 'python')
emstrip_exe = find_program('emstrip')
custom_target(
'lite-xl-stripped',
Expand All @@ -101,7 +102,7 @@ if get_option('wasm_debug') == 'sourcemap'

custom_target(
'lite-xl.wasm.map',
command: [emstrip_exe, '--version'],
command: [sourcemap_fixer_exe, '@OUTPUT0@', get_option('wasm_sourcemap_base')],
input: 'meson.build',
output: 'lite-xl.wasm.map',
depends: [lite_exe],
Expand Down

0 comments on commit ba9b0be

Please sign in to comment.