first commit

This commit is contained in:
Hidenori Matsubayashi
2021-07-16 13:03:30 +09:00
commit d10fcb6127
42 changed files with 4287 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/commands/analyze.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../elinux_plugins.dart';
class ELinuxAnalyzeCommand extends AnalyzeCommand with ELinuxExtension {
ELinuxAnalyzeCommand({bool verboseHelp = false})
: super(
verboseHelp: verboseHelp,
fileSystem: globals.fs,
platform: globals.platform,
processManager: globals.processManager,
logger: globals.logger,
terminal: globals.terminal,
artifacts: globals.artifacts,
);
}
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/commands/attach.dart';
import '../elinux_plugins.dart';
class ELinuxAttachCommand extends AttachCommand with ELinuxExtension {
ELinuxAttachCommand({bool verboseHelp = false})
: super(verboseHelp: verboseHelp);
}
+99
View File
@@ -0,0 +1,99 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/android/build_validation.dart' as android;
import 'package:flutter_tools/src/base/analyze_size.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_apk.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import '../elinux_builder.dart';
import '../elinux_cache.dart';
import '../elinux_plugins.dart';
class ELinuxBuildCommand extends BuildCommand {
ELinuxBuildCommand({bool verboseHelp = false})
: super(verboseHelp: verboseHelp) {
addSubcommand(BuildPackageCommand(verboseHelp: verboseHelp));
}
}
class BuildPackageCommand extends BuildSubCommand with ELinuxExtension {
/// See: [BuildApkCommand] in `build_apk.dart`
BuildPackageCommand({bool verboseHelp = false}) {
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
usesBuildNameOption();
argParser.addOption(
'target-arch',
defaultsTo: _getCurrentHostPlatformArchName(),
allowed: <String>['x64', 'arm64'],
help: 'Target architecture for which the the app is compiled',
);
argParser.addOption(
'target-backend-type',
defaultsTo: 'wayland',
allowed: <String>['wayland', 'gbm', 'eglstream', 'x11'],
help: 'Target backend type that the app will run on devices.',
);
}
@override
final String name = 'elinux';
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
<DevelopmentArtifact>{
DevelopmentArtifact.androidGenSnapshot,
ELinuxDevelopmentArtifact.elinux,
};
@override
final String description = 'Build an eLinux package from your app.';
/// See: [android.validateBuild] in `build_validation.dart`
void validateBuild(ELinuxBuildInfo eLinuxBuildInfo) {
if (eLinuxBuildInfo.buildInfo.mode.isPrecompiled &&
eLinuxBuildInfo.targetArch == 'x86') {
throwToolExit('x86 ABI does not support AOT compilation.');
}
}
/// See: [BuildApkCommand.runCommand] in `build_apk.dart`
@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = await getBuildInfo();
final ELinuxBuildInfo eLinuxBuildInfo = ELinuxBuildInfo(
buildInfo,
targetArch: stringArg('target-arch'),
targetBackendType: stringArg('target-backend-type'),
);
validateBuild(eLinuxBuildInfo);
displayNullSafetyMode(buildInfo);
await ELinuxBuilder.buildBundle(
project: FlutterProject.current(),
targetFile: targetFile,
eLinuxBuildInfo: eLinuxBuildInfo,
sizeAnalyzer: SizeAnalyzer(
fileSystem: globals.fs,
logger: globals.logger,
flutterUsage: globals.flutterUsage,
),
);
return FlutterCommandResult.success();
}
String _getCurrentHostPlatformArchName() {
final HostPlatform hostPlatform = getCurrentHostPlatform();
return getNameForHostPlatformArch(hostPlatform);
}
}
+54
View File
@@ -0,0 +1,54 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/commands/clean.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:path/path.dart';
import '../elinux_cmake_project.dart';
class ELinuxCleanCommand extends CleanCommand {
ELinuxCleanCommand({bool verbose = false}) : super(verbose: verbose);
/// See: [CleanCommand.runCommand] in `clean.dart`
@override
Future<FlutterCommandResult> runCommand() async {
final FlutterProject flutterProject = FlutterProject.current();
_cleanELinuxProject(ELinuxProject.fromFlutter(flutterProject));
return super.runCommand();
}
void _cleanELinuxProject(ELinuxProject project) {
if (!project.existsSync()) {
return;
}
_deleteFile(project.ephemeralDirectory);
}
/// Source: [CleanCommand.deleteFile] in `clean.dart` (simplified)
void _deleteFile(FileSystemEntity file) {
if (!file.existsSync()) {
return;
}
final String path = relative(file.path);
final Status status = globals.logger.startProgress(
'Deleting $path...',
);
try {
file.deleteSync(recursive: true);
} on FileSystemException catch (error) {
globals.printError('Failed to remove $path: $error');
} finally {
status?.stop();
}
}
}
+163
View File
@@ -0,0 +1,163 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/flutter_project_metadata.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/template.dart';
import '../elinux_plugins.dart';
class ELinuxCreateCommand extends CreateCommand {
ELinuxCreateCommand({bool verboseHelp = false})
: super(verboseHelp: verboseHelp) {
argParser.addOption(
'target-backend-type',
defaultsTo: 'wayland',
allowed: <String>['wayland', 'gbm', 'eglstream', 'x11'],
help: 'Target backend type that the app will run on devices.',
);
}
@override
void printUsage() {
super.printUsage();
// TODO(swift-kim): I couldn't find a proper way to override the --platforms
// option without copying the entire class. This message is a workaround.
print(
'You don\'t have to specify "elinux" as a target platform with '
'"--platforms" option. It is automatically added by default.',
);
}
/// See:
/// - [CreateCommand.runCommand] in `create.dart`
/// - [CreateCommand._getProjectType] in `create.dart` (generatePlugin)
Future<FlutterCommandResult> runInternal() async {
final FlutterCommandResult result = await super.runCommand();
if (result != FlutterCommandResult.success() || argResults.rest.isEmpty) {
return result;
}
final bool generatePlugin = argResults['template'] != null
? stringArg('template') ==
flutterProjectTypeToString(FlutterProjectType.plugin)
: determineTemplateType() == FlutterProjectType.plugin;
if (generatePlugin) {
// Assume that pubspec.yaml uses the multi-platforms plugin format if the
// file already exists.
// TODO(swift-kim): Skip this message if elinux already exists in pubspec.
globals.printStatus(
'The `pubspec.yaml` under the project directory must be updated to support ELinux.\n'
'Add below lines to under the `platforms:` key.',
emphasis: true,
color: TerminalColor.yellow,
);
final Map<String, dynamic> templateContext = createTemplateContext(
organization: '',
projectName: projectName,
flutterRoot: '',
);
globals.printStatus(
'\nelinux:\n'
' pluginClass: ${templateContext['pluginClass'] as String}\n'
' fileName: ${projectName}_plugin.h',
emphasis: true,
color: TerminalColor.blue,
);
globals.printStatus('');
}
if (boolArg('pub')) {
final FlutterProject project = FlutterProject.fromDirectory(projectDir);
await ensureReadyForELinuxTooling(project);
if (project.hasExampleApp) {
await ensureReadyForELinuxTooling(project.example);
}
}
return result;
}
/// See: [Template.render] in `template.dart`
@override
Future<FlutterCommandResult> runCommand() async {
// The template directory that the flutter tools search for available
// templates cannot be overriden because the implementation is private.
// So we have to copy eLinux templates into the directory manually.
final Directory eLinuxTemplates = globals.fs
.directory(Cache.flutterRoot)
.parent
.childDirectory('templates');
if (!eLinuxTemplates.existsSync()) {
throwToolExit('Could not locate eLinux templates.');
}
final File eLinuxTemplateManifest =
eLinuxTemplates.childFile('template_manifest.json');
final Directory templates = globals.fs
.directory(Cache.flutterRoot)
.childDirectory('packages')
.childDirectory('flutter_tools')
.childDirectory('templates');
final File templateManifest = templates.childFile('template_manifest.json');
// This is required due to: https://github.com/flutter/flutter/pull/59706
// TODO(swift-kim): Find any better workaround. One option is to override
// renderTemplate() but it may result in additional complexity.
eLinuxTemplateManifest.copySync(templateManifest.path);
final String backend = stringArg('target-backend-type');
final List<Directory> created = <Directory>[];
try {
for (final Directory projectType
in eLinuxTemplates.listSync().whereType<Directory>()) {
final Directory sourceRunnerCommon =
projectType.childDirectory('runner');
if (!sourceRunnerCommon.existsSync()) {
continue;
}
final Directory sourceFlutter = projectType.childDirectory('flutter');
if (!sourceFlutter.existsSync()) {
continue;
}
final Directory dest = templates
.childDirectory(projectType.basename)
.childDirectory('elinux.tmpl');
if (dest.existsSync()) {
dest.deleteSync(recursive: true);
}
copyDirectory(projectType, dest);
copyDirectory(sourceFlutter, dest.childDirectory('flutter'));
copyDirectory(sourceRunnerCommon, dest.childDirectory('runner'));
if (projectType.basename == 'app') {
final Directory sourceVariation =
projectType.childDirectory('runner_$backend');
if (!sourceVariation.existsSync()) {
continue;
}
copyDirectory(sourceVariation, dest.childDirectory('runner'));
}
created.add(dest);
}
return await runInternal();
} finally {
for (final Directory template in created) {
template.deleteSync(recursive: true);
}
}
}
}
+21
View File
@@ -0,0 +1,21 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/commands/drive.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../elinux_plugins.dart';
class ELinuxDriveCommand extends DriveCommand with ELinuxExtension {
ELinuxDriveCommand({bool verboseHelp = false})
: super(
verboseHelp: verboseHelp,
fileSystem: globals.fs,
logger: globals.logger,
platform: globals.platform,
);
}
+106
View File
@@ -0,0 +1,106 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/commands/packages.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import '../elinux_plugins.dart';
/// This class was copied from [PackagesCommand] to substitute its
/// [PackagesGetCommand] and [PackagesInteractiveGetCommand] subcommands with
/// their ELinux equivalents. We may find a better workaround in the future.
///
/// Source: [PackagesCommand] in `packages.dart`
class ELinuxPackagesCommand extends FlutterCommand {
ELinuxPackagesCommand() {
addSubcommand(ELinuxPackagesGetCommand('get', false));
addSubcommand(ELinuxPackagesInteractiveGetCommand('upgrade',
'Upgrade the current package\'s dependencies to latest versions.'));
addSubcommand(ELinuxPackagesInteractiveGetCommand(
'add', 'Add a dependency to pubspec.yaml.'));
addSubcommand(ELinuxPackagesInteractiveGetCommand(
'remove', 'Removes a dependency from the current package.'));
addSubcommand(PackagesTestCommand());
addSubcommand(PackagesForwardCommand(
'publish', 'Publish the current package to pub.dartlang.org',
requiresPubspec: true));
addSubcommand(PackagesForwardCommand(
'downgrade', 'Downgrade packages in a Flutter project',
requiresPubspec: true));
addSubcommand(PackagesForwardCommand('deps', 'Print package dependencies',
requiresPubspec: true));
addSubcommand(PackagesForwardCommand(
'run', 'Run an executable from a package',
requiresPubspec: true));
addSubcommand(
PackagesForwardCommand('cache', 'Work with the Pub system cache'));
addSubcommand(PackagesForwardCommand('version', 'Print Pub version'));
addSubcommand(PackagesForwardCommand(
'uploader', 'Manage uploaders for a package on pub.dev'));
addSubcommand(PackagesForwardCommand('login', 'Log into pub.dev.'));
addSubcommand(PackagesForwardCommand('logout', 'Log out of pub.dev.'));
addSubcommand(
PackagesForwardCommand('global', 'Work with Pub global packages'));
addSubcommand(PackagesForwardCommand(
'outdated', 'Analyze dependencies to find which ones can be upgraded',
requiresPubspec: true));
addSubcommand(PackagesPassthroughCommand());
}
@override
final String name = 'pub';
@override
List<String> get aliases => const <String>['packages'];
@override
final String description = 'Commands for managing Flutter packages.';
@override
Future<FlutterCommandResult> runCommand() async => null;
}
class ELinuxPackagesGetCommand extends PackagesGetCommand
with _PostRunPluginInjection {
ELinuxPackagesGetCommand(String name, bool upgrade) : super(name, upgrade);
}
class ELinuxPackagesInteractiveGetCommand extends PackagesInteractiveGetCommand
with _PostRunPluginInjection {
ELinuxPackagesInteractiveGetCommand(String commandName, String description)
: super(commandName, description);
}
mixin _PostRunPluginInjection on FlutterCommand {
/// See: [PackagesGetCommand.runCommand] in `packages.dart`
@override
Future<FlutterCommandResult> runCommand() async {
final FlutterCommandResult result = await super.runCommand();
if (result == FlutterCommandResult.success()) {
final String workingDirectory =
argResults.rest.isNotEmpty ? argResults.rest[0] : null;
final String target = findProjectRoot(globals.fs, workingDirectory);
if (target == null) {
return result;
}
final FlutterProject rootProject =
FlutterProject.fromDirectory(globals.fs.directory(target));
await ensureReadyForELinuxTooling(rootProject);
if (rootProject.hasExampleApp &&
rootProject.example.pubspecFile.existsSync()) {
await ensureReadyForELinuxTooling(rootProject.example);
}
}
return result;
}
}
+86
View File
@@ -0,0 +1,86 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/precache.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:meta/meta.dart';
import '../elinux_cache.dart';
class ELinuxPrecacheCommand extends PrecacheCommand {
ELinuxPrecacheCommand({
bool verboseHelp = false,
@required Cache cache,
@required Platform platform,
@required Logger logger,
@required FeatureFlags featureFlags,
}) : _cache = cache,
_platform = platform,
super(
verboseHelp: verboseHelp,
cache: cache,
platform: platform,
logger: logger,
featureFlags: featureFlags,
) {
argParser.addFlag(
'elinux',
negatable: true,
defaultsTo: false,
help: 'Precache artifacts for Embedded Linux development.',
);
}
final Cache _cache;
final Platform _platform;
bool get _includeOtherPlatforms =>
boolArg('android') ||
DevelopmentArtifact.values.any((DevelopmentArtifact artifact) =>
boolArg(artifact.name) && argResults.wasParsed(artifact.name));
@override
Future<FlutterCommandResult> runCommand() async {
final bool includeAllPlatforms = boolArg('all-platforms');
final bool includeELinux = boolArg('elinux');
final bool includeDefaults = !includeELinux && !_includeOtherPlatforms;
const String elinuxStampName = 'elinux-sdk';
// Re-lock the cache.
if (_platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') {
await _cache.lock();
}
if (includeAllPlatforms || includeDefaults || includeELinux) {
if (boolArg('force')) {
_cache.setStampFor(elinuxStampName, '');
}
await _cache.updateAll(<DevelopmentArtifact>{
ELinuxDevelopmentArtifact.elinux,
});
}
if (includeAllPlatforms || includeDefaults || _includeOtherPlatforms) {
// If the '--force' option is used, the super.runCommand() will delete
// the elinux's stamp file. It should be restored.
final String elinuxStamp = _cache.getStampFor(elinuxStampName);
final FlutterCommandResult result = await super.runCommand();
if (elinuxStamp != null) {
_cache.setStampFor(elinuxStampName, elinuxStamp);
}
return result;
}
return FlutterCommandResult.success();
}
}
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/run.dart';
import '../elinux_cache.dart';
import '../elinux_plugins.dart';
class ELinuxRunCommand extends RunCommand with ELinuxExtension {
ELinuxRunCommand({bool verboseHelp = false})
: super(verboseHelp: verboseHelp) {
argParser.addOption(
'target-backend-type',
defaultsTo: 'wayland',
allowed: <String>['wayland', 'gbm', 'eglstream', 'x11'],
help: 'Target backend type that the app will run on devices.',
);
}
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async =>
<DevelopmentArtifact>{
DevelopmentArtifact.androidGenSnapshot,
ELinuxDevelopmentArtifact.elinux,
};
}
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2021 Sony Group Corporation. All rights reserved.
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/src/commands/test.dart';
import '../elinux_plugins.dart';
class ELinuxTestCommand extends TestCommand with ELinuxExtension {
ELinuxTestCommand({bool verboseHelp = false})
: super(verboseHelp: verboseHelp);
}