Skip to content

Commit 11da803

Browse files
vsmenoncommit-bot@chromium.org
authored andcommitted
[dartdevc] build the ddk sdk with dartdevc
This: (1) Uses dartdevc and kernel_worker directly to build ddk artifacts. (2) Generates an outline file instead of a full dill file for ddc_sdk.dill. (3) Fixes source maps in the shipped sdk so that urls from dart_sdk.js.map have correct relative paths to dart files in the sdk. This won't work with webdev/build as that copies and serves dart_sdk.js, but it will now be able to build the sdk directly. Change-Id: I7b9470fe18cac9b4343c7c520fe6ffd7bd9246b4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104842 Reviewed-by: Jake Macdonald <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Vijay Menon <[email protected]>
1 parent 8e3a75c commit 11da803

File tree

9 files changed

+166
-67
lines changed

9 files changed

+166
-67
lines changed

pkg/dev_compiler/lib/src/compiler/shared_command.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ Map placeSourceMap(Map sourceMap, String sourceMapPath,
371371
sourcePath = sourcePathToUri(p.absolute(p.fromUri(uri))).path;
372372

373373
// Allow bazel mappings to override.
374-
var match = bazelMappings[sourcePath];
374+
var match = bazelMappings != null ? bazelMappings[sourcePath] : null;
375375
if (match != null) return match;
376376

377377
// Fall back to a relative path against the source map itself.
@@ -385,7 +385,8 @@ Map placeSourceMap(Map sourceMap, String sourceMapPath,
385385
list[i] = makeRelative(list[i] as String);
386386
}
387387
map['sources'] = list;
388-
map['file'] = makeRelative(map['file'] as String);
388+
map['file'] =
389+
map['file'] != null ? makeRelative(map['file'] as String) : null;
389390
return map;
390391
}
391392

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Future<CompilerResult> _compile(List<String> args,
7676
var argParser = ArgParser(allowTrailingOptions: true)
7777
..addFlag('help',
7878
abbr: 'h', help: 'Display this message.', negatable: false)
79-
..addOption('out', abbr: 'o', help: 'Output file (required).')
79+
..addMultiOption('out', abbr: 'o', help: 'Output file (required).')
8080
..addOption('packages', help: 'The package spec file to use.')
8181
// TODO(jmesserly): is this still useful for us, or can we remove it now?
8282
..addFlag('summarize-text',
@@ -95,6 +95,8 @@ Future<CompilerResult> _compile(List<String> args,
9595
help: 'The directories to search when encountering uris with the '
9696
'specified multi-root scheme.',
9797
defaultsTo: [Uri.base.path])
98+
..addOption('multi-root-output-path',
99+
help: 'Path to set multi-root files relative to.', hide: true)
98100
..addOption('dart-sdk',
99101
help: '(unsupported with --kernel) path to the Dart SDK.', hide: true)
100102
..addFlag('compile-sdk',
@@ -113,12 +115,15 @@ Future<CompilerResult> _compile(List<String> args,
113115
return CompilerResult(64);
114116
}
115117

116-
var output = argResults['out'] as String;
117-
if (output == null) {
118+
var outPaths = argResults['out'] as List<String>;
119+
var moduleFormats = parseModuleFormatOption(argResults);
120+
if (outPaths.isEmpty) {
118121
print('Please specify the output file location. For example:\n'
119-
' -o PATH/TO/OUTPUT_FILE.js'
120-
'');
121-
print(_usageMessage(argParser));
122+
' -o PATH/TO/OUTPUT_FILE.js');
123+
return CompilerResult(64);
124+
} else if (outPaths.length != moduleFormats.length) {
125+
print('Number of output files (${outPaths.length}) must match '
126+
'number of module formats (${moduleFormats.length}).');
122127
return CompilerResult(64);
123128
}
124129

@@ -136,8 +141,17 @@ Future<CompilerResult> _compile(List<String> args,
136141
var multiRootPaths = (argResults['multi-root'] as Iterable<String>)
137142
.map(Uri.base.resolve)
138143
.toList();
139-
var multiRootOutputPath = _longestPrefixingPath(
140-
sourcePathToUri(p.absolute(output)), multiRootPaths);
144+
var multiRootOutputPath = argResults['multi-root-output-path'] as String;
145+
if (multiRootOutputPath == null) {
146+
if (outPaths.length > 1) {
147+
print(
148+
'If multiple output files (found ${outPaths.length}) are specified, '
149+
'then --multi-root-output-path must be explicitly provided.');
150+
return CompilerResult(64);
151+
}
152+
multiRootOutputPath = _longestPrefixingPath(
153+
sourcePathToUri(p.absolute(outPaths.first)), multiRootPaths);
154+
}
141155

142156
var fileSystem = MultiRootFileSystem(
143157
multiRootScheme, multiRootPaths, fe.StandardFileSystem.instance);
@@ -314,12 +328,15 @@ Future<CompilerResult> _compile(List<String> args,
314328
return CompilerResult(1, kernelState: compilerState);
315329
}
316330

317-
var file = File(output);
318-
await file.parent.create(recursive: true);
319-
320331
// Output files can be written in parallel, so collect the futures.
321332
var outFiles = <Future>[];
322333
if (argResults['summarize'] as bool) {
334+
if (outPaths.length > 1) {
335+
print(
336+
'If multiple output files (found ${outPaths.length}) are specified, '
337+
'the --summarize option is not supported.');
338+
return CompilerResult(64);
339+
}
323340
// TODO(jmesserly): CFE mutates the Kernel tree, so we can't save the dill
324341
// file if we successfully reused a cached library. If compiler state is
325342
// unchanged, it means we used the cache.
@@ -329,16 +346,22 @@ Future<CompilerResult> _compile(List<String> args,
329346
if (identical(compilerState, oldCompilerState)) {
330347
component.unbindCanonicalNames();
331348
}
332-
var sink = File(p.withoutExtension(output) + '.dill').openWrite();
349+
var sink = File(p.withoutExtension(outPaths.first) + '.dill').openWrite();
333350
// TODO(jmesserly): this appears to save external libraries.
334351
// Do we need to run them through an outlining step so they can be saved?
335352
kernel.BinaryPrinter(sink).writeComponentFile(component);
336353
outFiles.add(sink.flush().then((_) => sink.close()));
337354
}
338355
if (argResults['summarize-text'] as bool) {
356+
if (outPaths.length > 1) {
357+
print(
358+
'If multiple output files (found ${outPaths.length}) are specified, '
359+
'the --summarize-text option is not supported.');
360+
return CompilerResult(64);
361+
}
339362
StringBuffer sb = StringBuffer();
340363
kernel.Printer(sb, showExternal: false).writeComponentFile(component);
341-
outFiles.add(File(output + '.txt').writeAsString(sb.toString()));
364+
outFiles.add(File(outPaths.first + '.txt').writeAsString(sb.toString()));
342365
}
343366
if (hierarchy == null) {
344367
var target = compilerState.options.target as DevCompilerTarget;
@@ -351,24 +374,28 @@ Future<CompilerResult> _compile(List<String> args,
351374
var jsModule = compiler.emitModule(
352375
component, result.inputSummaries, inputSummaries, summaryModules);
353376

354-
// TODO(jmesserly): support for multiple output formats?
355-
//
356377
// Also the old Analyzer backend had some code to make debugging better when
357378
// --single-out-file is used, but that option does not appear to be used by
358379
// any of our build systems.
359-
var jsCode = jsProgramToCode(jsModule, options.moduleFormats.first,
360-
buildSourceMap: options.sourceMap,
361-
inlineSourceMap: options.inlineSourceMap,
362-
jsUrl: p.toUri(output).toString(),
363-
mapUrl: p.toUri(output + '.map').toString(),
364-
bazelMapping: options.bazelMapping,
365-
customScheme: multiRootScheme,
366-
multiRootOutputPath: multiRootOutputPath);
367-
368-
outFiles.add(file.writeAsString(jsCode.code));
369-
if (jsCode.sourceMap != null) {
370-
outFiles.add(
371-
File(output + '.map').writeAsString(json.encode(jsCode.sourceMap)));
380+
for (var i = 0; i < outPaths.length; ++i) {
381+
var output = outPaths[i];
382+
var moduleFormat = moduleFormats[i];
383+
var file = File(output);
384+
await file.parent.create(recursive: true);
385+
var jsCode = jsProgramToCode(jsModule, moduleFormat,
386+
buildSourceMap: options.sourceMap,
387+
inlineSourceMap: options.inlineSourceMap,
388+
jsUrl: p.toUri(output).toString(),
389+
mapUrl: p.toUri(output + '.map').toString(),
390+
bazelMapping: options.bazelMapping,
391+
customScheme: multiRootScheme,
392+
multiRootOutputPath: multiRootOutputPath);
393+
394+
outFiles.add(file.writeAsString(jsCode.code));
395+
if (jsCode.sourceMap != null) {
396+
outFiles.add(
397+
File(output + '.map').writeAsString(json.encode(jsCode.sourceMap)));
398+
}
372399
}
373400

374401
await Future.wait(outFiles);

pkg/dev_compiler/tool/ddb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ void main(List<String> args) async {
9292
ProcessResult runDdc(String command, List<String> args) {
9393
if (debug) {
9494
// Use unbuilt script. This only works from a source checkout.
95-
args.insertAll(0,
96-
['--enable-asserts', p.join(ddcPath, 'bin', '${command}.dart')]);
95+
args.insertAll(
96+
0, ['--enable-asserts', p.join(ddcPath, 'bin', '${command}.dart')]);
9797
command = dartBinary;
9898
} else {
9999
// Use built snapshot.
@@ -138,18 +138,14 @@ void main(List<String> args) async {
138138
if (debug) {
139139
var sdkRoot = p.dirname(p.dirname(ddcPath));
140140
var buildDir = p.join(sdkRoot, Platform.isMacOS ? 'xcodebuild' : 'out');
141-
sdkJsPath = p.join(buildDir, 'ReleaseX64', 'gen', 'utils', 'dartdevc',
142-
kernel ? 'kernel' : 'js', mod);
143-
requirePath = p.join(sdkRoot, 'third_party', 'requirejs');
144-
ddcSdk = p.join(buildDir, 'ReleaseX64', 'gen', 'utils', 'dartdevc',
145-
kernel ? p.join('kernel', 'ddc_sdk.dill') : 'ddc_sdk.sum');
146-
} else {
147-
var suffix = kernel ? p.join('kernel', mod) : mod;
148-
sdkJsPath = p.join(dartSdk, 'lib', 'dev_compiler', suffix);
149-
requirePath = sdkJsPath;
150-
ddcSdk = p.join(
151-
dartSdk, 'lib', '_internal', kernel ? 'ddc_sdk.dill' : 'ddc_sdk.sum');
141+
dartSdk = p.join(buildDir, 'ReleaseX64', 'dart-sdk');
152142
}
143+
var suffix = kernel ? p.join('kernel', mod) : mod;
144+
sdkJsPath = p.join(dartSdk, 'lib', 'dev_compiler', suffix);
145+
requirePath = sdkJsPath;
146+
ddcSdk = p.join(
147+
dartSdk, 'lib', '_internal', kernel ? 'ddc_sdk.dill' : 'ddc_sdk.sum');
148+
153149
ProcessResult result;
154150
var ddcArgs = [
155151
if (kernel) '--kernel',

pkg/dev_compiler/tool/kernel_sdk.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ Future main(List<String> args) async {
8989
var format = moduleFormats[name];
9090
var jsDir = p.join(outputDir, name);
9191
var jsPath = p.join(jsDir, 'dart_sdk.js');
92+
var mapPath = '$jsPath.map';
9293
await Directory(jsDir).create();
93-
var jsCode = jsProgramToCode(jsModule, format);
94+
var jsCode = jsProgramToCode(jsModule, format,
95+
jsUrl: jsPath, mapUrl: mapPath, buildSourceMap: true);
9496
await File(jsPath).writeAsString(jsCode.code);
95-
await File('$jsPath.map').writeAsString(json.encode(jsCode.sourceMap));
97+
await File(mapPath).writeAsString(json.encode(jsCode.sourceMap));
9698
}
9799
}

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
14971497
}
14981498
Name kernelName = new Name(name, library.library);
14991499
List<LocatedMessage> context;
1500-
if (candidate != null) {
1500+
if (candidate != null && candidate.location != null) {
15011501
Uri uri = candidate.location.file;
15021502
int offset = candidate.fileOffset;
15031503
Message contextMessage;

pkg/front_end/lib/src/fasta/source/outline_builder.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ class OutlineBuilder extends StackListener {
645645
if (isAbstract) {
646646
modifiers |= abstractMask;
647647
}
648+
if (nativeMethodName != null) {
649+
modifiers |= externalMask;
650+
}
648651
List<MetadataBuilder> metadata = pop();
649652
checkEmpty(beginToken.charOffset);
650653
library
@@ -826,6 +829,9 @@ class OutlineBuilder extends StackListener {
826829
}
827830
}
828831
int modifiers = Modifier.validate(pop(), isAbstract: isAbstract);
832+
if (nativeMethodName != null) {
833+
modifiers |= externalMask;
834+
}
829835
if ((modifiers & externalMask) != 0) {
830836
modifiers &= ~abstractMask;
831837
}
@@ -1507,6 +1513,9 @@ class OutlineBuilder extends StackListener {
15071513
int charOffset = pop();
15081514
Object name = pop();
15091515
int modifiers = pop();
1516+
if (nativeMethodName != null) {
1517+
modifiers |= externalMask;
1518+
}
15101519
List<MetadataBuilder> metadata = pop();
15111520
if (name is ParserRecovery) {
15121521
library.endNestedDeclaration("<syntax-error>");

pkg/front_end/testcases/rasta/native_is_illegal.dart.outline.expect

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import self as self;
33
import "dart:core" as core;
44

55
class Bar extends core::Object {
6-
get x() → self::Bar
7-
;
8-
set x(self::Bar value) → void
9-
;
10-
method f() → dynamic
11-
;
12-
static factory •() → self::Bar
13-
;
6+
external get x() → self::Bar;
7+
external set x(self::Bar value) → void;
8+
external method f() → dynamic;
9+
external static factory •() → self::Bar;
1410
}
15-
static method foo() → dynamic
16-
;
11+
external static method foo() → dynamic;

sdk/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ copy("copy_dev_compiler_summary") {
602602
deps = [
603603
":copy_libraries",
604604
"../utils/dartdevc:dartdevc_sdk",
605-
"../utils/dartdevc:dartdevc_kernel_sdk",
605+
"../utils/dartdevc:dartdevc_kernel_sdk_outline",
606606
]
607607
gen_dir = get_label_info("../utils/dartdevc:dartdevc_sdk", "target_gen_dir")
608608
sources = [

0 commit comments

Comments
 (0)