diff --git a/test/translate.ts b/test/translate.ts index ecd15231..5e8934f4 100644 --- a/test/translate.ts +++ b/test/translate.ts @@ -18,6 +18,12 @@ tape('Version string to Semver translator', function (t) { st.equal(versionToSemver('0.4.20-nightly.2018.2.13+commit.27ef9794.Emscripten.clang'), '0.4.20-nightly.2018.2.13+commit.27ef9794.Emscripten.clang'); st.end(); }); + t.test('Broken nightly with leading zeroes', function (st) { + st.equal(versionToSemver('0.3.6-nightly.2016.08.27+commit.91d4fa47.Emscripten.clang'), '0.3.6-nightly.2016.8.27+commit.91d4fa47.Emscripten.clang'); + st.equal(versionToSemver('0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang'), '0.4.1-nightly.2016.9.9+commit.79867f49.Emscripten.clang'); + st.equal(versionToSemver('0.4.1-nightly.2016.12.06+commit.79867f49.Emscripten.clang'), '0.4.1-nightly.2016.12.6+commit.79867f49.Emscripten.clang'); + st.end(); + }); t.test('Old style 0.1.1', function (st) { st.equal(versionToSemver('0.1.1-6ff4cd6b/RelWithDebInfo-Emscripten/clang/int'), '0.1.1+commit.6ff4cd6b'); st.end(); @@ -37,6 +43,10 @@ tape('Version string to Semver translator', function (t) { ); st.end(); }); + t.test('Broken 0.3.4 nightly', function (st) { + st.equal(versionToSemver('0.3.4-0/Release-Emscripten/clang/Interpreter'), '0.3.4-nightly'); + st.end(); + }); t.test('Old style 0.3.5', function (st) { // The one in the solc-bin list st.equal(versionToSemver('0.3.5-371690f0/Release-Emscripten/clang/Interpreter'), '0.3.5+commit.371690f0'); diff --git a/translate.ts b/translate.ts index ca0c39f7..551817f2 100644 --- a/translate.ts +++ b/translate.ts @@ -1,15 +1,20 @@ import linker from './linker'; /// Translate old style version numbers to semver. -/// Old style: 0.3.6-3fc68da5/Release-Emscripten/clang +/// Old style: 0.4.1-nightly.2016.09.09+commit.79867f49.Emscripten.clang +/// 0.3.6-nightly.2016.08.27+commit.91d4fa47.Emscripten.clang +/// 0.3.6-3fc68da5/Release-Emscripten/clang /// 0.3.5-371690f0/Release-Emscripten/clang/Interpreter /// 0.3.5-0/Release-Emscripten/clang/Interpreter +/// 0.3.4-0/Release-Emscripten/clang/Interpreter /// 0.2.0-e7098958/.-Emscripten/clang/int linked to libethereum-1.1.1-bbb80ab0/.-Emscripten/clang/int /// 0.1.3-0/.-/clang/int linked to libethereum-0.9.92-0/.-/clang/int /// 0.1.2-5c3bfd4b*/.-/clang/int /// 0.1.1-6ff4cd6b/RelWithDebInfo-Emscripten/clang/int -/// New style: 0.4.5+commit.b318366e.Emscripten.clang +/// New style: 0.8.1-nightly.2021.1.7+commit.d11cf15d.js +/// 0.4.5+commit.b318366e.Emscripten.clang function versionToSemver (version) { + // This parses the old style with a commit hash. It ignores the details past the commit hash. // FIXME: parse more detail, but this is a good start const parsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-([0-9a-f]{8})[/*].*$/); if (parsed) { @@ -18,9 +23,18 @@ function versionToSemver (version) { if (version.indexOf('0.1.3-0') !== -1) { return '0.1.3'; } + if (version.indexOf('0.3.4-0') !== -1) { + return '0.3.4-nightly'; + } if (version.indexOf('0.3.5-0') !== -1) { return '0.3.5'; } + // This parses the obsolete nightly style where the date can have leading zeroes. + // It does not validate the dates, but only if the date format is correct (i.e. YYYY.[M]M.[D]D). + const nightlyParsed = version.match(/^([0-9]+\.[0-9]+\.[0-9]+)-nightly\.([0-9]+)\.0?([1-9]+)\.0?([1-9]+)(.*)$/); + if (nightlyParsed) { + return nightlyParsed[1] + '-nightly.' + nightlyParsed[2] + '.' + nightlyParsed[3] + '.' + nightlyParsed[4] + nightlyParsed[5]; + } // assume it is already semver compatible return version; }