Unverified Commit 4a110b62 authored by Janice Collins's avatar Janice Collins Committed by GitHub

Allow snippets tool to be run from arbitrary CWDs (#25243)

* Allow snippets tool to be run from arbitrary CWDs

* Drop use of absolute when using Platform.executable (path is not relative, might require PATH resolution)

* canonicalize paths

* Use path.fromUri consistently to resolve file URIs

* Force commit to try to kick Cirrus

* Force commit to kick Cirrus, again
parent e29b023a
...@@ -124,7 +124,7 @@ class SampleChecker { ...@@ -124,7 +124,7 @@ class SampleChecker {
/// Finds the location of the snippets script. /// Finds the location of the snippets script.
String get _snippetsExecutable { String get _snippetsExecutable {
final String platformScriptPath = path.dirname(Platform.script.toFilePath()); final String platformScriptPath = path.dirname(path.fromUri(Platform.script));
return path.canonicalize(path.join(platformScriptPath, '..', 'snippets', 'lib', 'main.dart')); return path.canonicalize(path.join(platformScriptPath, '..', 'snippets', 'lib', 'main.dart'));
} }
...@@ -206,18 +206,18 @@ class SampleChecker { ...@@ -206,18 +206,18 @@ class SampleChecker {
if (_snippetsSnapshotPath == null) { if (_snippetsSnapshotPath == null) {
_snippetsSnapshotPath = '$_snippetsExecutable.snapshot'; _snippetsSnapshotPath = '$_snippetsExecutable.snapshot';
return Process.runSync( return Process.runSync(
path.absolute(Platform.executable), path.canonicalize(Platform.executable),
<String>[ <String>[
'--snapshot=$_snippetsSnapshotPath', '--snapshot=$_snippetsSnapshotPath',
'--snapshot-kind=app-jit', '--snapshot-kind=app-jit',
path.absolute(_snippetsExecutable), path.canonicalize(_snippetsExecutable),
]..addAll(args), ]..addAll(args),
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
); );
} else { } else {
return Process.runSync( return Process.runSync(
path.absolute(Platform.executable), path.canonicalize(Platform.executable),
<String>[path.absolute(_snippetsSnapshotPath)]..addAll(args), <String>[path.canonicalize(_snippetsSnapshotPath)]..addAll(args),
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
); );
} }
......
...@@ -30,8 +30,8 @@ class _ComponentTuple { ...@@ -30,8 +30,8 @@ class _ComponentTuple {
class SnippetGenerator { class SnippetGenerator {
SnippetGenerator({Configuration configuration}) SnippetGenerator({Configuration configuration})
: configuration = configuration ?? : configuration = configuration ??
// This script must be run from dev/docs, so the root is up two levels. // Flutter's root is four directories up from this script.
Configuration(flutterRoot: Directory(path.canonicalize(path.join('..', '..')))) { Configuration(flutterRoot: Directory(Platform.environment['FLUTTER_ROOT'] ?? path.canonicalize(path.join(path.dirname(path.fromUri(Platform.script)), '..', '..', '..')))) {
this.configuration.createOutputDirectory(); this.configuration.createOutputDirectory();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment