Skip to content

Commit 130f9c6

Browse files
committed
[native_toolchain_c] Format with tall style
1 parent f478b31 commit 130f9c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1288
-1396
lines changed

pkgs/native_toolchain_c/lib/src/cbuilder/build_mode.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ final class BuildMode {
3131
static const release = BuildMode._('release');
3232

3333
/// All known build modes.
34-
static const values = [
35-
debug,
36-
release,
37-
];
34+
static const values = [debug, release];
3835

3936
/// The name of this [BuildMode].
4037
///

pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ class CBuilder extends CTool implements Builder {
100100
super.optimizationLevel = OptimizationLevel.o3,
101101
this.buildMode = BuildMode.release,
102102
}) : super(
103-
type: OutputType.executable,
104-
assetName: null,
105-
installName: null,
106-
pic: pie,
107-
linkModePreference: null,
108-
);
103+
type: OutputType.executable,
104+
assetName: null,
105+
installName: null,
106+
pic: pie,
107+
linkModePreference: null,
108+
);
109109

110110
/// Runs the C Compiler with on this C build spec.
111111
///
@@ -118,8 +118,10 @@ class CBuilder extends CTool implements Builder {
118118
String? linkInPackage,
119119
}) async {
120120
if (!input.config.buildCodeAssets) {
121-
logger?.info('buildAssetTypes did not contain "${CodeAsset.type}", '
122-
'skipping CodeAsset $assetName build.');
121+
logger?.info(
122+
'buildAssetTypes did not contain "${CodeAsset.type}", '
123+
'skipping CodeAsset $assetName build.',
124+
);
123125
return;
124126
}
125127
assert(
@@ -130,12 +132,15 @@ class CBuilder extends CTool implements Builder {
130132
final outDir = input.outputDirectory;
131133
final packageRoot = input.packageRoot;
132134
await Directory.fromUri(outDir).create(recursive: true);
133-
final linkMode =
134-
getLinkMode(linkModePreference ?? input.config.code.linkModePreference);
135-
final libUri = outDir
136-
.resolve(input.config.code.targetOS.libraryFileName(name, linkMode));
137-
final exeUri =
138-
outDir.resolve(input.config.code.targetOS.executableFileName(name));
135+
final linkMode = getLinkMode(
136+
linkModePreference ?? input.config.code.linkModePreference,
137+
);
138+
final libUri = outDir.resolve(
139+
input.config.code.targetOS.libraryFileName(name, linkMode),
140+
);
141+
final exeUri = outDir.resolve(
142+
input.config.code.targetOS.executableFileName(name),
143+
);
139144
final sources = [
140145
for (final source in this.sources)
141146
packageRoot.resolveUri(Uri.file(source)),
@@ -167,9 +172,10 @@ class CBuilder extends CTool implements Builder {
167172
type == OutputType.library && linkMode == DynamicLoadingBundled()
168173
? libUri
169174
: null,
170-
staticLibrary: type == OutputType.library && linkMode == StaticLinking()
171-
? libUri
172-
: null,
175+
staticLibrary:
176+
type == OutputType.library && linkMode == StaticLinking()
177+
? libUri
178+
: null,
173179
executable: type == OutputType.executable ? exeUri : null,
174180
// ignore: invalid_use_of_visible_for_testing_member
175181
installName: installName,
@@ -205,14 +211,15 @@ class CBuilder extends CTool implements Builder {
205211
}
206212
// ignore: deprecated_member_use
207213
if (!input.config.dryRun) {
208-
final includeFiles = await Stream.fromIterable(includes)
209-
.asyncExpand(
210-
(include) => Directory(include.toFilePath())
211-
.list(recursive: true)
212-
.where((entry) => entry is File)
213-
.map((file) => file.uri),
214-
)
215-
.toList();
214+
final includeFiles =
215+
await Stream.fromIterable(includes)
216+
.asyncExpand(
217+
(include) => Directory(include.toFilePath())
218+
.list(recursive: true)
219+
.where((entry) => entry is File)
220+
.map((file) => file.uri),
221+
)
222+
.toList();
216223

217224
output.addDependencies({
218225
// Note: We use a Set here to deduplicate the dependencies.

pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,20 @@ class CLinker extends CTool implements Linker {
5252
required Logger? logger,
5353
}) async {
5454
if (OS.current != OS.linux || input.config.code.targetOS != OS.linux) {
55-
throw UnsupportedError('Currently, only linux is supported for this '
56-
'feature. See also https://github.com/dart-lang/native/issues/1376');
55+
throw UnsupportedError(
56+
'Currently, only linux is supported for this '
57+
'feature. See also https://github.com/dart-lang/native/issues/1376',
58+
);
5759
}
5860
final outDir = input.outputDirectory;
5961
final packageRoot = input.packageRoot;
6062
await Directory.fromUri(outDir).create(recursive: true);
61-
final linkMode =
62-
getLinkMode(linkModePreference ?? input.config.code.linkModePreference);
63-
final libUri = outDir
64-
.resolve(input.config.code.targetOS.libraryFileName(name, linkMode));
63+
final linkMode = getLinkMode(
64+
linkModePreference ?? input.config.code.linkModePreference,
65+
);
66+
final libUri = outDir.resolve(
67+
input.config.code.targetOS.libraryFileName(name, linkMode),
68+
);
6569
final sources = [
6670
for (final source in this.sources)
6771
packageRoot.resolveUri(Uri.file(source)),
@@ -99,23 +103,26 @@ class CLinker extends CTool implements Linker {
99103
await task.run();
100104

101105
if (assetName != null) {
102-
output.assets.code.add(CodeAsset(
103-
package: input.packageName,
104-
name: assetName!,
105-
file: libUri,
106-
linkMode: linkMode,
107-
os: input.config.code.targetOS,
108-
architecture: input.config.code.targetArchitecture,
109-
));
106+
output.assets.code.add(
107+
CodeAsset(
108+
package: input.packageName,
109+
name: assetName!,
110+
file: libUri,
111+
linkMode: linkMode,
112+
os: input.config.code.targetOS,
113+
architecture: input.config.code.targetArchitecture,
114+
),
115+
);
110116
}
111-
final includeFiles = await Stream.fromIterable(includes)
112-
.asyncExpand(
113-
(include) => Directory(include.toFilePath())
114-
.list(recursive: true)
115-
.where((entry) => entry is File)
116-
.map((file) => file.uri),
117-
)
118-
.toList();
117+
final includeFiles =
118+
await Stream.fromIterable(includes)
119+
.asyncExpand(
120+
(include) => Directory(include.toFilePath())
121+
.list(recursive: true)
122+
.where((entry) => entry is File)
123+
.map((file) => file.uri),
124+
)
125+
.toList();
119126

120127
output.addDependencies({
121128
// Note: We use a Set here to deduplicate the dependencies.

pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class CompilerResolver {
3131
required this.logger,
3232
OS? hostOS, // Only visible for testing.
3333
Architecture? hostArchitecture, // Only visible for testing.
34-
}) : hostOS = hostOS ?? OS.current,
35-
hostArchitecture = hostArchitecture ?? Architecture.current;
34+
}) : hostOS = hostOS ?? OS.current,
35+
hostArchitecture = hostArchitecture ?? Architecture.current;
3636

3737
Future<ToolInstance> resolveCompiler() async {
3838
// First, check if the launcher provided a direct path to the compiler.
@@ -103,20 +103,24 @@ class CompilerResolver {
103103
final inputCcUri = codeConfig.cCompiler?.compiler;
104104
if (inputCcUri != null) {
105105
assert(await File.fromUri(inputCcUri).exists());
106-
logger?.finer('Using compiler ${inputCcUri.toFilePath()} '
107-
'from BuildInput.cCompiler.cc.');
108-
return (await CompilerRecognizer(inputCcUri).resolve(logger: logger))
109-
.first;
106+
logger?.finer(
107+
'Using compiler ${inputCcUri.toFilePath()} '
108+
'from BuildInput.cCompiler.cc.',
109+
);
110+
return (await CompilerRecognizer(
111+
inputCcUri,
112+
).resolve(logger: logger)).first;
110113
}
111114
logger?.finer('No compiler set in BuildInput.cCompiler.cc.');
112115
return null;
113116
}
114117

115118
Future<ToolInstance?> _tryLoadToolFromNativeToolchain(Tool tool) async {
116-
final resolved = (await tool.defaultResolver!.resolve(logger: logger))
117-
.where((i) => i.tool == tool)
118-
.toList()
119-
..sort();
119+
final resolved =
120+
(await tool.defaultResolver!.resolve(
121+
logger: logger,
122+
)).where((i) => i.tool == tool).toList()
123+
..sort();
120124
return resolved.isEmpty ? null : resolved.first;
121125
}
122126

@@ -188,10 +192,13 @@ class CompilerResolver {
188192
final inputArUri = codeConfig.cCompiler?.archiver;
189193
if (inputArUri != null) {
190194
assert(await File.fromUri(inputArUri).exists());
191-
logger?.finer('Using archiver ${inputArUri.toFilePath()} '
192-
'from BuildInput.cCompiler.ar.');
193-
return (await ArchiverRecognizer(inputArUri).resolve(logger: logger))
194-
.first;
195+
logger?.finer(
196+
'Using archiver ${inputArUri.toFilePath()} '
197+
'from BuildInput.cCompiler.ar.',
198+
);
199+
return (await ArchiverRecognizer(
200+
inputArUri,
201+
).resolve(logger: logger)).first;
195202
}
196203
logger?.finer('No archiver set in BuildInput.cCompiler.ar.');
197204
return null;
@@ -262,8 +269,10 @@ class CompilerResolver {
262269
final inputLdUri = codeConfig.cCompiler?.linker;
263270
if (inputLdUri != null) {
264271
assert(await File.fromUri(inputLdUri).exists());
265-
logger?.finer('Using linker ${inputLdUri.toFilePath()} '
266-
'from cCompiler.ld.');
272+
logger?.finer(
273+
'Using linker ${inputLdUri.toFilePath()} '
274+
'from cCompiler.ld.',
275+
);
267276
final tools = await LinkerRecognizer(inputLdUri).resolve(logger: logger);
268277
return tools.first;
269278
}

pkgs/native_toolchain_c/lib/src/cbuilder/language.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ class Language {
2020
static const Language objectiveC = Language._('objective c');
2121

2222
/// Known values for [Language].
23-
static const List<Language> values = [
24-
c,
25-
cpp,
26-
objectiveC,
27-
];
23+
static const List<Language> values = [c, cpp, objectiveC];
2824

2925
@override
3026
String toString() => name;

pkgs/native_toolchain_c/lib/src/cbuilder/linker_options.dart

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,25 @@ class LinkerOptions {
3838
List<String>? flags,
3939
bool? gcSections,
4040
this.linkerScript,
41-
}) : _linkerFlags = flags ?? [],
42-
gcSections = gcSections ?? true,
43-
_wholeArchiveSandwich = false;
41+
}) : _linkerFlags = flags ?? [],
42+
gcSections = gcSections ?? true,
43+
_wholeArchiveSandwich = false;
4444

4545
/// Create linking options to tree-shake symbols from the input files.
4646
///
4747
/// The [symbols] specify the symbols which should be kept.
4848
LinkerOptions.treeshake({
4949
Iterable<String>? flags,
5050
required Iterable<String>? symbols,
51-
}) : _linkerFlags = <String>[
52-
...flags ?? [],
53-
'--strip-debug',
54-
if (symbols != null) ...symbols.expand((e) => ['-u', e]),
55-
].toList(),
56-
gcSections = true,
57-
_wholeArchiveSandwich = symbols == null,
58-
linkerScript = _createLinkerScript(symbols);
51+
}) : _linkerFlags =
52+
<String>[
53+
...flags ?? [],
54+
'--strip-debug',
55+
if (symbols != null) ...symbols.expand((e) => ['-u', e]),
56+
].toList(),
57+
gcSections = true,
58+
_wholeArchiveSandwich = symbols == null,
59+
linkerScript = _createLinkerScript(symbols);
5960

6061
Iterable<String> _toLinkerSyntax(Tool linker, List<String> flagList) {
6162
if (linker.isClangLike) {
@@ -92,16 +93,14 @@ extension LinkerOptionsExt on LinkerOptions {
9293
/// trick, which includes all symbols when linking object files.
9394
///
9495
/// Throws if the [linker] is not supported.
95-
Iterable<String> preSourcesFlags(
96-
Tool linker,
97-
Iterable<String> sourceFiles,
98-
) =>
96+
Iterable<String> preSourcesFlags(Tool linker, Iterable<String> sourceFiles) =>
9997
_toLinkerSyntax(
100-
linker,
101-
sourceFiles.any((source) => source.endsWith('.a')) ||
102-
_wholeArchiveSandwich
103-
? ['--whole-archive']
104-
: []);
98+
linker,
99+
sourceFiles.any((source) => source.endsWith('.a')) ||
100+
_wholeArchiveSandwich
101+
? ['--whole-archive']
102+
: [],
103+
);
105104

106105
/// The flags for the specified [linker], which are inserted _after_ the
107106
/// sources.
@@ -113,14 +112,12 @@ extension LinkerOptionsExt on LinkerOptions {
113112
Iterable<String> postSourcesFlags(
114113
Tool linker,
115114
Iterable<String> sourceFiles,
116-
) =>
117-
_toLinkerSyntax(linker, [
118-
..._linkerFlags,
119-
if (gcSections) '--gc-sections',
120-
if (linkerScript != null)
121-
'--version-script=${linkerScript!.toFilePath()}',
122-
if (sourceFiles.any((source) => source.endsWith('.a')) ||
123-
_wholeArchiveSandwich)
124-
'--no-whole-archive',
125-
]);
115+
) => _toLinkerSyntax(linker, [
116+
..._linkerFlags,
117+
if (gcSections) '--gc-sections',
118+
if (linkerScript != null) '--version-script=${linkerScript!.toFilePath()}',
119+
if (sourceFiles.any((source) => source.endsWith('.a')) ||
120+
_wholeArchiveSandwich)
121+
'--no-whole-archive',
122+
]);
126123
}

pkgs/native_toolchain_c/lib/src/cbuilder/linkmode.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ LinkMode getLinkMode(LinkModePreference preference) {
99
preference == LinkModePreference.preferDynamic) {
1010
return DynamicLoadingBundled();
1111
}
12-
assert(preference == LinkModePreference.static ||
13-
preference == LinkModePreference.preferStatic);
12+
assert(
13+
preference == LinkModePreference.static ||
14+
preference == LinkModePreference.preferStatic,
15+
);
1416
return StaticLinking();
1517
}

pkgs/native_toolchain_c/lib/src/cbuilder/optimization_level.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ final class OptimizationLevel {
3131
static const OptimizationLevel oS = OptimizationLevel._('Os');
3232

3333
/// Unspecified optimization level; the default or compiler-chosen level.
34-
static const OptimizationLevel unspecified =
35-
OptimizationLevel._('unspecified');
34+
static const OptimizationLevel unspecified = OptimizationLevel._(
35+
'unspecified',
36+
);
3637

3738
/// Returns the string representation of the optimization level.
3839
@override
@@ -41,9 +42,9 @@ final class OptimizationLevel {
4142
String clangFlag() => '-$_level';
4243

4344
String msvcFlag() => switch (this) {
44-
o3 => o2.msvcFlag(),
45-
_ => '/$_level',
46-
};
45+
o3 => o2.msvcFlag(),
46+
_ => '/$_level',
47+
};
4748

4849
static const List<OptimizationLevel> values = [
4950
o0,

pkgs/native_toolchain_c/lib/src/cbuilder/output_type.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
enum OutputType {
6-
executable,
7-
library,
8-
}
5+
enum OutputType { executable, library }

0 commit comments

Comments
 (0)