Skip to content

Commit 565e907

Browse files
committed
[wasm-split] End module names with : in manifests
Suggested by by @sbc100 (emscripten-core/emscripten#25577 (comment)). Currently this supports both module names with a `:` and without it for backwards compatibility and also to pass the CI.
1 parent 3286b6e commit 565e907

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/support/istring.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ struct IString {
8888
return startsWith(std::string_view(str));
8989
}
9090

91+
bool endsWith(std::string_view suffix) const {
92+
// TODO: Use C++20 `ends_with`.
93+
if (suffix.size() > str.size()) {
94+
return false;
95+
}
96+
return str.substr(str.size() - suffix.size()) == suffix;
97+
}
98+
bool endsWith(IString str) const { return endsWith(str.str); }
99+
100+
// Disambiguate for string literals.
101+
template<int N> bool endsWith(const char (&str)[N]) const {
102+
return endsWith(std::string_view(str));
103+
}
104+
105+
IString substr(size_t pos, size_t len = std::string_view::npos) const {
106+
return IString(str.substr(pos, len));
107+
}
108+
91109
size_t size() const { return str.size(); }
92110
};
93111

src/tools/wasm-split/wasm-split.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ void multiSplitModule(const WasmSplitOptions& options) {
419419
}
420420
Name name = WasmBinaryReader::escape(line);
421421
if (newSection) {
422+
if (name.endsWith(":")) {
423+
name = name.substr(0, name.size() - 1);
424+
}
422425
if (moduleNameSet.count(name)) {
423426
Fatal() << "Module name " << name << " is listed more than once\n";
424427
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1
1+
1:
22
A
33

4-
2
4+
2:
55
B
66

7-
3
7+
3:
88
C

0 commit comments

Comments
 (0)