Skip to content

Commit b7e63e5

Browse files
committed
Pass the version variable to script snapshots at build time
See dart-lang/sdk#36579 (comment)
1 parent 185bcba commit b7e63e5

10 files changed

+30
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.0-beta.2
2+
3+
* Fix a bug where the version variable wouldn't be set for certain executables.
4+
15
# 1.0.0-beta.1
26

37
* Initial beta release.

lib/src/chocolatey.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,8 @@ Future<void> _build() async {
222222

223223
archive.addFile(fileFromString(
224224
"tools/$name.bat",
225-
renderTemplate("chocolatey/executable.bat", {
226-
"name": _chocolateyName,
227-
"version": version.toString(),
228-
"executable": p.basename(path)
229-
}),
225+
renderTemplate("chocolatey/executable.bat",
226+
{"name": _chocolateyName, "executable": p.basename(path)}),
230227
executable: true));
231228
});
232229

lib/src/standalone.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ void _compileSnapshot() {
4141
ensureBuild();
4242

4343
for (var entrypoint in entrypoints) {
44-
Dart.run(entrypoint,
45-
vmArgs: ['--snapshot=build/${p.basename(entrypoint)}.snapshot']);
44+
Dart.run(entrypoint, vmArgs: [
45+
'-Dversion=$version',
46+
'--snapshot=build/${p.basename(entrypoint)}.snapshot'
47+
]);
4648
}
4749
}
4850

@@ -149,11 +151,8 @@ Future<void> _buildPackage(String os, {@required bool x64}) async {
149151
archive.addFile(fileFromString(
150152
"$standaloneName/$name${os == 'windows' ? '.bat' : ''}",
151153
renderTemplate(
152-
"standalone/executable.${os == 'windows' ? 'bat' : 'sh'}", {
153-
"name": standaloneName,
154-
"version": _useNative(os, x64: x64) ? null : version.toString(),
155-
"executable": p.basename(path)
156-
}),
154+
"standalone/executable.${os == 'windows' ? 'bat' : 'sh'}",
155+
{"name": standaloneName, "executable": p.basename(path)}),
157156
executable: true));
158157
});
159158

lib/src/templates/chocolatey/executable.bat.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ REM Dart executable and a snapshot of {{{name}}}.
44

55
set SCRIPTPATH=%~dp0
66
set arguments=%*
7-
dart.exe {{#version}}"-Dversion={{{version}}}"{{/version}} "%SCRIPTPATH%\{{{executable}}}.snapshot" %arguments%
7+
dart.exe "%SCRIPTPATH%\{{{executable}}}.snapshot" %arguments%

lib/src/templates/standalone/executable.bat.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ REM Dart executable and a snapshot of {{{name}}}.
44

55
set SCRIPTPATH=%~dp0
66
set arguments=%*
7-
"%SCRIPTPATH%\src\dart.exe" {{#version}}"-Dversion={{{version}}}"{{/version}} "%SCRIPTPATH%\src\{{{executable}}}.snapshot" %arguments%
7+
"%SCRIPTPATH%\src\dart.exe" "%SCRIPTPATH%\src\{{{executable}}}.snapshot" %arguments%

lib/src/templates/standalone/executable.sh.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ follow_links() {
1414

1515
# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
1616
path=`dirname "$(follow_links "$0")"`
17-
exec "$path/src/dart" {{#version}}"-Dversion={{{version}}}"{{/version}} "$path/src/{{{executable}}}.snapshot" "$@"
17+
exec "$path/src/dart" "$path/src/{{{executable}}}.snapshot" "$@"

test/chocolatey_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void main() {
357357

358358
var executable = await TestProcess.start(d.path("out/tools/foo.bat"), [],
359359
workingDirectory: d.sandbox);
360-
expect(executable.stdout, emits("in foo"));
360+
expect(executable.stdout, emits("in foo 1.2.3"));
361361
await executable.shouldExit(0);
362362
}, testOn: "windows");
363363
});

test/descriptor.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ DirectoryDescriptor package(Map<String, Object> pubspec, String grindDotDart,
6666

6767
dir("bin", [
6868
for (var basename in executables)
69-
file("$basename.dart", 'void main() => print("in $basename");')
69+
file(
70+
"$basename.dart",
71+
// Include the version variable to ensure that executables we invoke
72+
// have access to it.
73+
'void main() => print("in $basename '
74+
'\${const String.fromEnvironment("version")}");')
7075
]),
7176

7277
dir("tool", [

test/npm_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ void main() {
172172

173173
var process = await TestProcess.start(
174174
"node$dotExe", [d.path("my_app/build/npm/foo.js")]);
175-
expect(process.stdout, emitsInOrder(["in foo", emitsDone]));
175+
expect(process.stdout, emitsInOrder(["in foo 1.2.3", emitsDone]));
176176
await process.shouldExit(0);
177177

178178
process = await TestProcess.start(
179179
"node$dotExe", [d.path("my_app/build/npm/bar.js")]);
180-
expect(process.stdout, emitsInOrder(["in bar", emitsDone]));
180+
expect(process.stdout, emitsInOrder(["in bar 1.2.3", emitsDone]));
181181
await process.shouldExit(0);
182182

183183
process = await TestProcess.start(
184184
"node$dotExe", [d.path("my_app/build/npm/qux.js")]);
185-
expect(process.stdout, emitsInOrder(["in zang", emitsDone]));
185+
expect(process.stdout, emitsInOrder(["in zang 1.2.3", emitsDone]));
186186
await process.shouldExit(0);
187187
});
188188

test/standalone_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,34 @@ void main() {
177177
var executable = await TestProcess.start(
178178
d.path("out/my_app/foo$dotBat"), [],
179179
workingDirectory: d.sandbox);
180-
expect(executable.stdout, emits("in foo"));
180+
expect(executable.stdout, emits("in foo 1.2.3"));
181181
await executable.shouldExit(0);
182182

183183
// Through a redirect
184184
executable = await TestProcess.start(d.path("out/my_app/qux$dotBat"), [],
185185
workingDirectory: d.sandbox);
186-
expect(executable.stdout, emits("in bar"));
186+
expect(executable.stdout, emits("in bar 1.2.3"));
187187
await executable.shouldExit(0);
188188

189189
// Through a relative symlink
190190
Link(d.path("foo-relative")).createSync("out/my_app/foo$dotBat");
191191
executable = await TestProcess.start(d.path("foo-relative"), [],
192192
workingDirectory: d.sandbox);
193-
expect(executable.stdout, emits("in foo"));
193+
expect(executable.stdout, emits("in foo 1.2.3"));
194194
await executable.shouldExit(0);
195195

196196
// Through an absolute symlink
197197
Link(d.path("foo-absolute")).createSync(d.path("out/my_app/foo$dotBat"));
198198
executable = await TestProcess.start(d.path("foo-absolute"), [],
199199
workingDirectory: d.sandbox);
200-
expect(executable.stdout, emits("in foo"));
200+
expect(executable.stdout, emits("in foo 1.2.3"));
201201
await executable.shouldExit(0);
202202

203203
// Through a nested symlink
204204
Link(d.path("foo-nested")).createSync(d.path("foo-relative"));
205205
executable = await TestProcess.start(d.path("foo-nested"), [],
206206
workingDirectory: d.sandbox);
207-
expect(executable.stdout, emits("in foo"));
207+
expect(executable.stdout, emits("in foo 1.2.3"));
208208
await executable.shouldExit(0);
209209
}, onPlatform: {"windows": Skip("google/dart_cli_pkg#25")});
210210
}, onPlatform: {if (!useDart2Native) "windows": Skip("dart-lang/sdk#37897")});

0 commit comments

Comments
 (0)