Add local elinux-artifacts use support (#193)
This change add ELINUX_ENGINE_BASE_LOCAL_DIRECTORY environment to use local artifacts of elinux without downloading them from GitHub. Signed-off-by: Hidenori Matsubayashi <[email protected]>
This commit is contained in:
+74
-13
@@ -8,12 +8,13 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
|||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/os.dart' show OperatingSystemUtils;
|
import 'package:flutter_tools/src/base/os.dart' show OperatingSystemUtils;
|
||||||
import 'package:flutter_tools/src/base/platform.dart';
|
import 'package:flutter_tools/src/base/platform.dart';
|
||||||
|
import 'package:flutter_tools/src/base/process.dart';
|
||||||
import 'package:flutter_tools/src/cache.dart';
|
import 'package:flutter_tools/src/cache.dart';
|
||||||
import 'package:flutter_tools/src/features.dart';
|
import 'package:flutter_tools/src/features.dart';
|
||||||
import 'package:flutter_tools/src/flutter_cache.dart';
|
import 'package:flutter_tools/src/flutter_cache.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
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/runner/flutter_command.dart';
|
||||||
|
import 'package:process/process.dart';
|
||||||
|
|
||||||
mixin ELinuxRequiredArtifacts on FlutterCommand {
|
mixin ELinuxRequiredArtifacts on FlutterCommand {
|
||||||
@override
|
@override
|
||||||
@@ -44,32 +45,36 @@ class ELinuxDevelopmentArtifact implements DevelopmentArtifact {
|
|||||||
class ELinuxFlutterCache extends FlutterCache {
|
class ELinuxFlutterCache extends FlutterCache {
|
||||||
ELinuxFlutterCache({
|
ELinuxFlutterCache({
|
||||||
required Logger logger,
|
required Logger logger,
|
||||||
required FileSystem fileSystem,
|
required super.fileSystem,
|
||||||
required Platform platform,
|
required Platform platform,
|
||||||
required OperatingSystemUtils osUtils,
|
required super.osUtils,
|
||||||
required FlutterProjectFactory projectFactory,
|
required ProcessManager processManager,
|
||||||
}) : super(
|
required super.projectFactory,
|
||||||
logger: logger,
|
}) : super(logger: logger, platform: platform) {
|
||||||
fileSystem: fileSystem,
|
registerArtifact(ELinuxEngineArtifacts(this,
|
||||||
platform: platform,
|
logger: logger, platform: platform, processManager: processManager));
|
||||||
osUtils: osUtils,
|
|
||||||
projectFactory: projectFactory) {
|
|
||||||
registerArtifact(ELinuxEngineArtifacts(this, platform: platform));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ELinuxEngineArtifacts extends EngineCachedArtifact {
|
class ELinuxEngineArtifacts extends EngineCachedArtifact {
|
||||||
ELinuxEngineArtifacts(
|
ELinuxEngineArtifacts(
|
||||||
Cache cache, {
|
Cache cache, {
|
||||||
|
required Logger logger,
|
||||||
required Platform platform,
|
required Platform platform,
|
||||||
}) : _platform = platform,
|
required ProcessManager processManager,
|
||||||
|
}) : _logger = logger,
|
||||||
|
_platform = platform,
|
||||||
|
_processUtils =
|
||||||
|
ProcessUtils(processManager: processManager, logger: logger),
|
||||||
super(
|
super(
|
||||||
'elinux-sdk',
|
'elinux-sdk',
|
||||||
cache,
|
cache,
|
||||||
ELinuxDevelopmentArtifact.elinux,
|
ELinuxDevelopmentArtifact.elinux,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final Logger _logger;
|
||||||
final Platform _platform;
|
final Platform _platform;
|
||||||
|
final ProcessUtils _processUtils;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String? get version {
|
String? get version {
|
||||||
@@ -133,7 +138,16 @@ class ELinuxEngineArtifacts extends EngineCachedArtifact {
|
|||||||
FileSystem fileSystem,
|
FileSystem fileSystem,
|
||||||
OperatingSystemUtils operatingSystemUtils,
|
OperatingSystemUtils operatingSystemUtils,
|
||||||
) async {
|
) async {
|
||||||
final String downloadUrl = '$engineBaseUrl/download/$shortVersion';
|
String? downloadUrl;
|
||||||
|
|
||||||
|
final String? overrideLocal =
|
||||||
|
_platform.environment['ELINUX_ENGINE_BASE_LOCAL_DIRECTORY'];
|
||||||
|
if (overrideLocal != null) {
|
||||||
|
await _downloadArtifactsFromLocal(operatingSystemUtils, overrideLocal);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadUrl ??= '$engineBaseUrl/download/$shortVersion';
|
||||||
for (final List<String> toolsDir in getBinaryDirs()) {
|
for (final List<String> toolsDir in getBinaryDirs()) {
|
||||||
final String cacheDir = toolsDir[0];
|
final String cacheDir = toolsDir[0];
|
||||||
final String urlPath = toolsDir[1];
|
final String urlPath = toolsDir[1];
|
||||||
@@ -144,4 +158,51 @@ class ELinuxEngineArtifacts extends EngineCachedArtifact {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _downloadArtifactsFromLocal(
|
||||||
|
OperatingSystemUtils operatingSystemUtils,
|
||||||
|
String overrideLocalDirectory,
|
||||||
|
) async {
|
||||||
|
_logger.printStatus('Copying elinux artifacts from local directory...');
|
||||||
|
for (final List<String> toolsDir in getBinaryDirs()) {
|
||||||
|
final String cacheDir = toolsDir[0];
|
||||||
|
final String filePath = '$overrideLocalDirectory/${toolsDir[1]}';
|
||||||
|
final Directory artifactDir = location.childDirectory(cacheDir);
|
||||||
|
final Status status = _logger.startProgress('Copying $cacheDir tools...');
|
||||||
|
try {
|
||||||
|
if (artifactDir.existsSync()) {
|
||||||
|
artifactDir.deleteSync(recursive: true);
|
||||||
|
}
|
||||||
|
artifactDir.createSync(recursive: true);
|
||||||
|
final RunResult result = await _processUtils.run(<String>[
|
||||||
|
'unzip',
|
||||||
|
filePath,
|
||||||
|
'-d',
|
||||||
|
artifactDir.path,
|
||||||
|
]);
|
||||||
|
if (result.exitCode != 0) {
|
||||||
|
throwToolExit(
|
||||||
|
'Failed to copy elinux artifact from local.\n\n'
|
||||||
|
'$result',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
status.stop();
|
||||||
|
}
|
||||||
|
_makeFilesExecutable(artifactDir, operatingSystemUtils);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Source: [EngineCachedArtifact._makeFilesExecutable] in `cache.dart`
|
||||||
|
void _makeFilesExecutable(
|
||||||
|
Directory dir,
|
||||||
|
OperatingSystemUtils operatingSystemUtils,
|
||||||
|
) {
|
||||||
|
operatingSystemUtils.chmod(dir, 'a+r,a+x');
|
||||||
|
for (final File file in dir.listSync(recursive: true).whereType<File>()) {
|
||||||
|
if (file.basename == 'gen_snapshot') {
|
||||||
|
operatingSystemUtils.chmod(file, 'a+r,a+x');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ Future<void> main(List<String> args) async {
|
|||||||
platform: globals.platform,
|
platform: globals.platform,
|
||||||
osUtils: globals.os,
|
osUtils: globals.os,
|
||||||
projectFactory: globals.projectFactory,
|
projectFactory: globals.projectFactory,
|
||||||
|
processManager: globals.processManager,
|
||||||
),
|
),
|
||||||
TemplateRenderer: () => const MustacheTemplateRenderer(),
|
TemplateRenderer: () => const MustacheTemplateRenderer(),
|
||||||
ApplicationPackageFactory: () => ELinuxApplicationPackageFactory(),
|
ApplicationPackageFactory: () => ELinuxApplicationPackageFactory(),
|
||||||
|
|||||||
Reference in New Issue
Block a user