ed6c557d1a
To allow ddc sdk kernel generation internally, add a way to provide paths to dependent files explicitly, instead of assuming relative from Platform.script. Also remove .packages file parameter. We don't have this file internally and sdk shouldn't depend on any of packages anyway, so it just work without this option. Change-Id: Iec892cbb640d35e64d107c6af36d214632815bae Reviewed-on: https://dart-review.googlesource.com/c/77485 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Jenny Messerly <jmesserly@google.com> Auto-Submit: Ivan Naydonov <inayd@google.com>
75 lines
2.8 KiB
Dart
Executable File
75 lines
2.8 KiB
Dart
Executable File
#!/usr/bin/env dart
|
|
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'dart:convert' show json;
|
|
import 'dart:io';
|
|
import 'package:args/args.dart' show ArgParser;
|
|
import 'package:dev_compiler/src/compiler/module_builder.dart';
|
|
import 'package:dev_compiler/src/compiler/shared_command.dart'
|
|
show SharedCompilerOptions;
|
|
import 'package:dev_compiler/src/kernel/target.dart';
|
|
import 'package:dev_compiler/src/kernel/command.dart';
|
|
import 'package:dev_compiler/src/kernel/compiler.dart';
|
|
import 'package:front_end/src/api_prototype/compiler_options.dart';
|
|
import 'package:front_end/src/api_prototype/kernel_generator.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
Future main(List<String> args) async {
|
|
var ddcPath = path.dirname(path.dirname(path.fromUri(Platform.script)));
|
|
|
|
// Parse flags.
|
|
var parser = ArgParser()
|
|
..addOption('output')
|
|
..addOption('libraries',
|
|
defaultsTo: path.join(ddcPath, '../../sdk/lib/libraries.json'));
|
|
var parserOptions = parser.parse(args);
|
|
|
|
var outputPath = parserOptions['output'] as String;
|
|
if (outputPath == null) {
|
|
var sdkRoot = path.absolute(path.dirname(path.dirname(ddcPath)));
|
|
var buildDir = path.join(sdkRoot, Platform.isMacOS ? 'xcodebuild' : 'out');
|
|
var genDir = path.join(buildDir, 'ReleaseX64', 'gen', 'utils', 'dartdevc');
|
|
outputPath = path.join(genDir, 'kernel', 'ddc_sdk.dill');
|
|
}
|
|
|
|
var target = DevCompilerTarget();
|
|
var options = CompilerOptions()
|
|
..compileSdk = true
|
|
// TODO(sigmund): remove this unnecessary option when possible.
|
|
..sdkRoot = Uri.base
|
|
..librariesSpecificationUri =
|
|
Uri.base.resolveUri(Uri.file(parserOptions['libraries']))
|
|
..target = target;
|
|
|
|
var inputs = target.extraRequiredLibraries.map(Uri.parse).toList();
|
|
var component = await kernelForComponent(inputs, options);
|
|
|
|
var outputDir = path.dirname(outputPath);
|
|
await Directory(outputDir).create(recursive: true);
|
|
await writeComponentToBinary(component, outputPath);
|
|
|
|
var jsModule =
|
|
ProgramCompiler(component, target.hierarchy, SharedCompilerOptions(), {})
|
|
.emitModule(component, [], {});
|
|
var moduleFormats = {
|
|
'amd': ModuleFormat.amd,
|
|
'common': ModuleFormat.common,
|
|
'es6': ModuleFormat.es6,
|
|
'legacy': ModuleFormat.legacy,
|
|
};
|
|
|
|
for (var name in moduleFormats.keys) {
|
|
var format = moduleFormats[name];
|
|
var jsDir = path.join(outputDir, name);
|
|
var jsPath = path.join(jsDir, 'dart_sdk.js');
|
|
await Directory(jsDir).create();
|
|
var jsCode = jsProgramToCode(jsModule, format);
|
|
await File(jsPath).writeAsString(jsCode.code);
|
|
await File('$jsPath.map').writeAsString(json.encode(jsCode.sourceMap));
|
|
}
|
|
}
|