diff --git a/src/de/inetsoftware/jwebassembly/JWebAssembly.java b/src/de/inetsoftware/jwebassembly/JWebAssembly.java index a2bdede..fa2ec21 100644 --- a/src/de/inetsoftware/jwebassembly/JWebAssembly.java +++ b/src/de/inetsoftware/jwebassembly/JWebAssembly.java @@ -62,6 +62,12 @@ public class JWebAssembly { */ public static final String DEBUG_NAMES = "DebugNames"; + /** + * Property for relative path between the final wasm file location and the source files location for the source map. + * If not empty it should end with a slash like "../../src/main/java/". + */ + public static final String SOURCE_MAP_BASE = "SourceMapBase"; + /** * The name of the annotation for import functions. */ diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index 24d42c7..bba690d 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -63,6 +63,8 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod private final boolean createSourceMap; + private final String javaSourceMapBase; + private WasmOutputStream codeStream = new WasmOutputStream(); private List functionTypes = new ArrayList<>(); @@ -102,6 +104,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod this.target = target; // for now we build the source map together with debug names createSourceMap = options.debugNames(); + javaSourceMapBase = options.getSourceMapBase(); } /** @@ -560,7 +563,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod protected void writeMethodStart( FunctionName name, String sourceFile ) throws IOException { if( createSourceMap ) { int idx = name.className.lastIndexOf( '/' ); - this.javaSourceFile = name.className.substring( 0, idx + 1 ) + sourceFile; + this.javaSourceFile = javaSourceMapBase + name.className.substring( 0, idx + 1 ) + sourceFile; } codeStream.reset(); } diff --git a/src/de/inetsoftware/jwebassembly/wasm/WasmOptions.java b/src/de/inetsoftware/jwebassembly/wasm/WasmOptions.java index d3e5b3e..52bb0ce 100644 --- a/src/de/inetsoftware/jwebassembly/wasm/WasmOptions.java +++ b/src/de/inetsoftware/jwebassembly/wasm/WasmOptions.java @@ -17,6 +17,8 @@ package de.inetsoftware.jwebassembly.wasm; import java.util.HashMap; +import javax.annotation.Nonnull; + import de.inetsoftware.jwebassembly.JWebAssembly; import de.inetsoftware.jwebassembly.module.FunctionName; @@ -31,6 +33,9 @@ public class WasmOptions { private final boolean useGC; + @Nonnull + private final String sourceMapBase; + /** * NonGC function for ref_eq polyfill. */ @@ -45,6 +50,11 @@ public class WasmOptions { public WasmOptions( HashMap properties ) { debugNames = Boolean.parseBoolean( properties.get( JWebAssembly.DEBUG_NAMES ) ); useGC = Boolean.parseBoolean( properties.getOrDefault( JWebAssembly.WASM_USE_GC, "false" ) ); + String base = properties.getOrDefault( JWebAssembly.SOURCE_MAP_BASE, "" ); + if( !base.isEmpty() && !base.endsWith( "/" ) ) { + base += "/"; + } + sourceMapBase = base; } /** @@ -64,4 +74,14 @@ public class WasmOptions { public boolean useGC() { return useGC; } + + /** + * Get the relative path between the final wasm file location and the source files location. + * If not empty it should end with a slash like "../../src/main/java/". + * @return the path + */ + @Nonnull + public String getSourceMapBase() { + return sourceMapBase; + } }