Skip to content

Pass the version variable to script snapshots at build time #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.0-beta.2

* Fix a bug where the version variable wouldn't be set for certain executables.

# 1.0.0-beta.1

* Initial beta release.
7 changes: 2 additions & 5 deletions lib/src/chocolatey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,8 @@ Future<void> _build() async {

archive.addFile(fileFromString(
"tools/$name.bat",
renderTemplate("chocolatey/executable.bat", {
"name": _chocolateyName,
"version": version.toString(),
"executable": p.basename(path)
}),
renderTemplate("chocolatey/executable.bat",
{"name": _chocolateyName, "executable": p.basename(path)}),
executable: true));
});

Expand Down
13 changes: 6 additions & 7 deletions lib/src/standalone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ void _compileSnapshot() {
ensureBuild();

for (var entrypoint in entrypoints) {
Dart.run(entrypoint,
vmArgs: ['--snapshot=build/${p.basename(entrypoint)}.snapshot']);
Dart.run(entrypoint, vmArgs: [
'-Dversion=$version',
'--snapshot=build/${p.basename(entrypoint)}.snapshot'
]);
}
}

Expand Down Expand Up @@ -149,11 +151,8 @@ Future<void> _buildPackage(String os, {@required bool x64}) async {
archive.addFile(fileFromString(
"$standaloneName/$name${os == 'windows' ? '.bat' : ''}",
renderTemplate(
"standalone/executable.${os == 'windows' ? 'bat' : 'sh'}", {
"name": standaloneName,
"version": _useNative(os, x64: x64) ? null : version.toString(),
"executable": p.basename(path)
}),
"standalone/executable.${os == 'windows' ? 'bat' : 'sh'}",
{"name": standaloneName, "executable": p.basename(path)}),
executable: true));
});

Expand Down
2 changes: 1 addition & 1 deletion lib/src/templates/chocolatey/executable.bat.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ REM Dart executable and a snapshot of {{{name}}}.

set SCRIPTPATH=%~dp0
set arguments=%*
dart.exe {{#version}}"-Dversion={{{version}}}"{{/version}} "%SCRIPTPATH%\{{{executable}}}.snapshot" %arguments%
dart.exe "%SCRIPTPATH%\{{{executable}}}.snapshot" %arguments%
2 changes: 1 addition & 1 deletion lib/src/templates/standalone/executable.bat.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ REM Dart executable and a snapshot of {{{name}}}.

set SCRIPTPATH=%~dp0
set arguments=%*
"%SCRIPTPATH%\src\dart.exe" {{#version}}"-Dversion={{{version}}}"{{/version}} "%SCRIPTPATH%\src\{{{executable}}}.snapshot" %arguments%
"%SCRIPTPATH%\src\dart.exe" "%SCRIPTPATH%\src\{{{executable}}}.snapshot" %arguments%
2 changes: 1 addition & 1 deletion lib/src/templates/standalone/executable.sh.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ follow_links() {

# Unlike $0, $BASH_SOURCE points to the absolute path of this file.
path=`dirname "$(follow_links "$0")"`
exec "$path/src/dart" {{#version}}"-Dversion={{{version}}}"{{/version}} "$path/src/{{{executable}}}.snapshot" "$@"
exec "$path/src/dart" "$path/src/{{{executable}}}.snapshot" "$@"
2 changes: 1 addition & 1 deletion test/chocolatey_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void main() {

var executable = await TestProcess.start(d.path("out/tools/foo.bat"), [],
workingDirectory: d.sandbox);
expect(executable.stdout, emits("in foo"));
expect(executable.stdout, emits("in foo 1.2.3"));
await executable.shouldExit(0);
}, testOn: "windows");
});
Expand Down
7 changes: 6 additions & 1 deletion test/descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ DirectoryDescriptor package(Map<String, Object> pubspec, String grindDotDart,

dir("bin", [
for (var basename in executables)
file("$basename.dart", 'void main() => print("in $basename");')
file(
"$basename.dart",
// Include the version variable to ensure that executables we invoke
// have access to it.
'void main() => print("in $basename '
'\${const String.fromEnvironment("version")}");')
]),

dir("tool", [
Expand Down
6 changes: 3 additions & 3 deletions test/npm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ void main() {

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

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

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

Expand Down
10 changes: 5 additions & 5 deletions test/standalone_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,34 +177,34 @@ void main() {
var executable = await TestProcess.start(
d.path("out/my_app/foo$dotBat"), [],
workingDirectory: d.sandbox);
expect(executable.stdout, emits("in foo"));
expect(executable.stdout, emits("in foo 1.2.3"));
await executable.shouldExit(0);

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

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

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

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