Teach flutter init how to depend on flutter using a relative path
This commit is contained in:
1
bin/cache/.gitignore
vendored
1
bin/cache/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
*.snapshot
|
||||
*.stamp
|
||||
artifacts
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}"))
|
||||
export FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}"))
|
||||
FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
|
||||
SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
|
||||
STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:path/path.dart' as path;
|
||||
|
||||
import 'build_configuration.dart';
|
||||
import 'os_utils.dart';
|
||||
import 'process.dart';
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.artifacts');
|
||||
|
||||
@@ -155,7 +156,10 @@ class ArtifactStore {
|
||||
return null;
|
||||
}
|
||||
|
||||
// These values are initialized by FlutterCommandRunner on startup.
|
||||
static String flutterRoot;
|
||||
static String packageRoot;
|
||||
|
||||
static String _engineRevision;
|
||||
|
||||
static String get engineRevision {
|
||||
@@ -190,7 +194,11 @@ class ArtifactStore {
|
||||
}
|
||||
|
||||
static Directory _getBaseCacheDir() {
|
||||
Directory cacheDir = new Directory(path.join(packageRoot, 'sky_tools', 'cache'));
|
||||
if (flutterRoot == null) {
|
||||
_logging.severe('FLUTTER_ROOT not specified. Cannot find artifact cache.');
|
||||
throw new ProcessExit(2);
|
||||
}
|
||||
Directory cacheDir = new Directory(path.join(flutterRoot, 'bin', 'cache', 'artifacts'));
|
||||
if (!cacheDir.existsSync())
|
||||
cacheDir.createSync(recursive: true);
|
||||
return cacheDir;
|
||||
@@ -198,8 +206,6 @@ class ArtifactStore {
|
||||
|
||||
static Directory _getCacheDirForArtifact(Artifact artifact) {
|
||||
Directory baseDir = _getBaseCacheDir();
|
||||
// For now, all downloaded artifacts are release mode host binaries so use
|
||||
// a path that mirrors a local release build.
|
||||
// TODO(jamesr): Add support for more configurations.
|
||||
String config = 'Release';
|
||||
Directory artifactSpecificDir = new Directory(path.join(
|
||||
|
||||
@@ -29,6 +29,8 @@ class FlutterCommandRunner extends CommandRunner {
|
||||
'shell commands executed.');
|
||||
argParser.addOption('package-root',
|
||||
help: 'Path to your packages directory.', defaultsTo: 'packages');
|
||||
argParser.addOption('flutter-root',
|
||||
help: 'The root directory of the Flutter repository.');
|
||||
argParser.addOption('android-device-id',
|
||||
help: 'Serial number of the target Android device.');
|
||||
|
||||
@@ -105,6 +107,7 @@ class FlutterCommandRunner extends CommandRunner {
|
||||
Logger.root.level = Level.FINE;
|
||||
|
||||
_globalResults = globalResults;
|
||||
ArtifactStore.flutterRoot = globalResults['flutter-root'] ?? Platform.environment['FLUTTER_ROOT'];
|
||||
ArtifactStore.packageRoot = globalResults['package-root'];
|
||||
|
||||
return super.runCommand(globalResults);
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:args/command_runner.dart';
|
||||
import 'package:mustache4dart/mustache4dart.dart' as mustache;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../artifacts.dart';
|
||||
import '../process.dart';
|
||||
|
||||
class InitCommand extends Command {
|
||||
@@ -30,17 +31,30 @@ class InitCommand extends Command {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (ArtifactStore.flutterRoot == null) {
|
||||
stderr.writeln('Neither the --flutter-root command line flag nor the FLUTTER_ROOT environment');
|
||||
stderr.writeln('variable was specified. Unable to find package:flutter.');
|
||||
return 2;
|
||||
}
|
||||
String flutterRoot = p.absolute(ArtifactStore.flutterRoot);
|
||||
|
||||
String flutterPackagePath = p.join(flutterRoot, 'packages', 'flutter');
|
||||
if (!FileSystemEntity.isFileSync(p.join(flutterPackagePath, 'pubspec.yaml'))) {
|
||||
print('Unable to find package:flutter in ${flutterPackagePath}');
|
||||
return 2;
|
||||
}
|
||||
|
||||
// TODO: Confirm overwrite of an existing directory with the user.
|
||||
Directory out = new Directory(argResults['out']);
|
||||
|
||||
new FlutterSimpleTemplate().generateInto(out);
|
||||
new FlutterSimpleTemplate().generateInto(out, flutterPackagePath);
|
||||
|
||||
print('');
|
||||
|
||||
String message = '''All done! To run your application:
|
||||
|
||||
\$ cd ${out.path}
|
||||
\$ flutter start --checked
|
||||
\$ flutter start
|
||||
''';
|
||||
|
||||
if (argResults['pub']) {
|
||||
@@ -66,14 +80,16 @@ abstract class Template {
|
||||
|
||||
Template(this.name, this.description);
|
||||
|
||||
void generateInto(Directory dir) {
|
||||
void generateInto(Directory dir, String flutterPackagePath) {
|
||||
String dirPath = p.normalize(dir.absolute.path);
|
||||
String projectName = _normalizeProjectName(p.basename(dirPath));
|
||||
print('Creating ${p.basename(projectName)}...');
|
||||
dir.createSync(recursive: true);
|
||||
|
||||
String relativeFlutterPackagePath = p.relative(flutterPackagePath, from: dirPath);
|
||||
|
||||
files.forEach((String path, String contents) {
|
||||
Map m = {'projectName': projectName, 'description': description};
|
||||
Map m = {'projectName': projectName, 'description': description, 'flutterPackagePath': relativeFlutterPackagePath};
|
||||
contents = mustache.render(contents, m);
|
||||
path = path.replaceAll('/', Platform.pathSeparator);
|
||||
File file = new File(p.join(dir.path, path));
|
||||
@@ -129,9 +145,8 @@ const String _pubspec = r'''
|
||||
name: {{projectName}}
|
||||
description: {{description}}
|
||||
dependencies:
|
||||
flutter: ">=0.0.2 <0.1.0"
|
||||
dev_dependencies:
|
||||
sky_tools: any
|
||||
flutter:
|
||||
path: {{flutterPackagePath}}
|
||||
''';
|
||||
|
||||
const String _flutterYaml = r'''
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:sky_tools/src/artifacts.dart';
|
||||
import 'package:sky_tools/src/commands/init.dart';
|
||||
import 'package:sky_tools/src/process.dart';
|
||||
import 'package:test/test.dart';
|
||||
@@ -29,6 +30,7 @@ defineTests() {
|
||||
if (!Platform.isWindows) {
|
||||
// Verify that we create a project that is well-formed.
|
||||
test('flutter-simple', () async {
|
||||
ArtifactStore.flutterRoot = '../..';
|
||||
InitCommand command = new InitCommand();
|
||||
CommandRunner runner = new CommandRunner('test_flutter', '')
|
||||
..addCommand(command);
|
||||
|
||||
Reference in New Issue
Block a user