add support for SOURCE_MAP_BASE

This commit is contained in:
Volker Berlin 2019-12-31 13:04:52 +01:00
parent 77be20ed57
commit 8589dbae66
3 changed files with 30 additions and 1 deletions

View File

@ -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.
*/

View File

@ -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<TypeEntry> 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();
}

View File

@ -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<String, String> 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;
}
}