Skip to content

Commit e3fe811

Browse files
authored
[hooks_runner] [hooks] Shorten output dir paths (#2682)
1 parent 29cf243 commit e3fe811

File tree

8 files changed

+101
-78
lines changed

8 files changed

+101
-78
lines changed

pkgs/hooks/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.20.2
2+
3+
- Change the length of the checksum used for `outputDirectory` to 10 hexadecimal
4+
characters to avoid running out of path length on Windows.
5+
16
## 0.20.1
27

38
- Update outdated documentation.

pkgs/hooks/lib/src/config.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ sealed class HookInput {
2828
/// The directory in which output and intermediate artifacts that are unique
2929
/// to the [config] can be placed.
3030
///
31-
/// This directory is unique per hook and per [config].
31+
/// This directory is unique per hook and per [config]. The directory is
32+
/// nested inside [outputDirectoryShared] and has a short checksum to avoid
33+
/// running out of path length on Winddows.
34+
///
35+
/// Prefer using a sub directory in [outputDirectoryShared] with a
36+
/// checksum of the fields on the [config] that influence your build. Reusing
37+
/// a precise subdirectory only dependent on what influences your build avoids
38+
/// cache misses for [config]s that differ in fields irrelevant for your
39+
/// build.
3240
///
3341
/// The contents of this directory will not be modified by anything else than
3442
/// the hook itself.
@@ -55,7 +63,12 @@ sealed class HookInput {
5563
/// The directory in which shared output and intermediate artifacts can be
5664
/// placed.
5765
///
58-
/// This directory is unique per hook.
66+
/// This directory is unique per hook. Use a sub directory of
67+
/// [outputDirectoryShared] with a checksum of the parts on the [config] that
68+
/// influence your assets. Ensure your checksum is relatively short to avoid
69+
/// running out of path lengths on Windows. Reusing a precise subdirectory
70+
/// only dependent on what influences your build avoids cache misses for
71+
/// [config]s that differ in fields irrelevant for your build.
5972
///
6073
/// The contents of this directory will not be modified by anything else than
6174
/// the hook itself.
@@ -194,10 +207,12 @@ String _jsonChecksum(Map<String, Object?> json) {
194207
final hash = sha256
195208
.convert(const JsonEncoder().fuse(const Utf8Encoder()).convert(json))
196209
.toString()
197-
// 256 bit hashes lead to 64 hex character strings.
198-
// To avoid overflowing file paths limits, only use 32.
199-
// Using 16 hex characters would also be unlikely to have collisions.
200-
.substring(0, 32);
210+
// 256 bit hashes lead to 64 hex character strings. To avoid overflowing
211+
// file paths limits on Windows, only use 10. 10 hex characters with 1000
212+
// different configs leads to a one in a million collision chance. On
213+
// collision, we'd get a cache miss and rerun the hooks and throw away the
214+
// cache for the colliding configuration.
215+
.substring(0, 10);
201216
return hash;
202217
}
203218

pkgs/hooks/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
A library that contains a Dart API for the JSON-based protocol for
44
`hook/build.dart` and `hook/link.dart`.
55
6-
version: 0.20.1
6+
version: 0.20.2
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/hooks
99

pkgs/hooks/test/checksum_test.dart

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -94,69 +94,69 @@ void main() {
9494
// needing to update this list).
9595

9696
final expectedChecksums = <String>[
97-
'61ab5ef403d9f006b6b5574a50e50daf',
98-
'e3a77db8c85c6b3549c8421e59e38e95',
99-
'e7a12aac9e17ddbb64887cd6cd9232d2',
100-
'cf1dd12731866d00afbbcdfe70e61589',
101-
'ad93ea8c702c5f11c92c52191883099c',
102-
'38c7c121e0c15cf54c984824e5051f4c',
103-
'c08bfcfb8272762b33a98f79bf350724',
104-
'e1270f247e192dc50b652621ae2e5a93',
105-
'e78c9baa330705077190565d8a847fb1',
106-
'9ad4121bade1db392de9ce083c13fc8f',
107-
'e5e00070ef4bc56a7ce3069424df4120',
108-
'838b8de06f73db3cea251697402babb0',
109-
'589ee41a4f1fdaaa428406cada32c4e3',
110-
'4746317758d511ffd2f47c44ea1e9ff8',
111-
'61773dc007d379d913773be8dab6d027',
112-
'cbdc799766b327b719acda0c8fa362df',
113-
'81ab30daef84759670866735ab9bdafe',
114-
'c3b5b08d9dfd763eefe1548fe1cebd15',
115-
'817d7a4498017835e17ed855fdcc810e',
116-
'43bf049e1e796472d5bf91b225026cda',
117-
'edeadb00c19dd64b77617ae191e4bedd',
118-
'c31e4bfcd55d57f37ca1e1ec96ffe592',
119-
'ab4f63c8d2bb35fa00568e682b800843',
120-
'2ef2c44c9571c14aeccae1d99f32a1b4',
121-
'553911c58185ec4bc0a91d38066f04b8',
122-
'bab035bb051f235c39b78e5607a8a01c',
123-
'c011395901dd42b098f486d2ff06a4dd',
124-
'e9f7fadde6dab0e7cc4ac0c7fb1a628c',
125-
'ebba044d322c1ceb81cf4e1e7c0e120e',
126-
'0b282c055b7817b099f84613af0c5c8a',
127-
'9a8e06eedabd3c6001aa114064390ce9',
128-
'75515f1094704fa6cfd486e506d2af18',
129-
'c86127d13e36019097d0707baf98e8f7',
130-
'4667534582f16a6551428fd045b3ac27',
131-
'f94ee3512b58bcc7f55e5f518d9441ce',
132-
'799b09a9cb7041165adc850c3bc34607',
133-
'1c2bddd1f0a1e8b889ca5b46817694f0',
134-
'af00c3aa5215cab39e58a696b886dc37',
135-
'c1505e20a93de1ab1143a79e965cd245',
136-
'31f2609c732d83722c420f8fb8465830',
137-
'7cd688235b6d1d8edb2f81fecb0a8da4',
138-
'81bac5e642e7b84dbd5fb1f71b07962d',
139-
'1a78f75ee147bbb5edf68b2e56e78a22',
140-
'9d6adcd09c95cc55d80f6cac5cc93590',
141-
'55fc558767c6e43269dc3de4556562ab',
142-
'9edb0db4a6b1e629f8fa949e42dc35e1',
143-
'd30575bba443794ee26b362fcd177406',
144-
'29d89c1c649dd8e60d2d4be8c8f87fae',
145-
'a304174ba2dcf0146bdd5b311bea9479',
146-
'7e55d4def09b16926719d5c3267ca6b8',
147-
'89bed1462b388cfed8e20a9f5d2cbb97',
148-
'3d6cb538997816a0c051748607352a79',
149-
'f33556a6cbc01e6e1390fdcb9f3aa82c',
150-
'20cf1a9119f96e519419e1b83633e289',
151-
'6b965e47445f5ff5549ff87b5b5d73c7',
152-
'64fffab256c810f794441a0f207d1691',
153-
'b4c4b511d1744f61eb95758e3a54386d',
154-
'20a0433b2ea9181634efa432d671a77e',
155-
'517b3c6690c52e6c2f905c22a6aa0096',
156-
'ebc520c76af5f114423363be7b025586',
157-
'7769c411f18744248a58b52d63ace420',
158-
'1baf5b978ec51f44383c407d31dc5ebf',
159-
'9fe464ec313e3465c9e43e12ec4fa5df',
97+
'61ab5ef403',
98+
'e3a77db8c8',
99+
'e7a12aac9e',
100+
'cf1dd12731',
101+
'ad93ea8c70',
102+
'38c7c121e0',
103+
'c08bfcfb82',
104+
'e1270f247e',
105+
'e78c9baa33',
106+
'9ad4121bad',
107+
'e5e00070ef',
108+
'838b8de06f',
109+
'589ee41a4f',
110+
'4746317758',
111+
'61773dc007',
112+
'cbdc799766',
113+
'81ab30daef',
114+
'c3b5b08d9d',
115+
'817d7a4498',
116+
'43bf049e1e',
117+
'edeadb00c1',
118+
'c31e4bfcd5',
119+
'ab4f63c8d2',
120+
'2ef2c44c95',
121+
'553911c581',
122+
'bab035bb05',
123+
'c011395901',
124+
'e9f7fadde6',
125+
'ebba044d32',
126+
'0b282c055b',
127+
'9a8e06eeda',
128+
'75515f1094',
129+
'c86127d13e',
130+
'4667534582',
131+
'f94ee3512b',
132+
'799b09a9cb',
133+
'1c2bddd1f0',
134+
'af00c3aa52',
135+
'c1505e20a9',
136+
'31f2609c73',
137+
'7cd688235b',
138+
'81bac5e642',
139+
'1a78f75ee1',
140+
'9d6adcd09c',
141+
'55fc558767',
142+
'9edb0db4a6',
143+
'd30575bba4',
144+
'29d89c1c64',
145+
'a304174ba2',
146+
'7e55d4def0',
147+
'89bed1462b',
148+
'3d6cb53899',
149+
'f33556a6cb',
150+
'20cf1a9119',
151+
'6b965e4744',
152+
'64fffab256',
153+
'b4c4b511d1',
154+
'20a0433b2e',
155+
'517b3c6690',
156+
'ebc520c76a',
157+
'7769c411f1',
158+
'1baf5b978e',
159+
'9fe464ec31',
160160
];
161161
printOnFailure('final expectedChecksums = <String>[');
162162
printOnFailure(checksums.map((e) => " '$e',").join('\n'));

pkgs/hooks_runner/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.23.1
2+
3+
- Change the length of the checksum used for `outputDirectory` to 10 hexadecimal
4+
characters to avoid running out of path length on Windows.
5+
16
## 0.23.0
27

38
- **Breaking change**: Replaced `NativeAssetsBuildRunner.hookEnvironmentVariablesFilter`

pkgs/hooks_runner/lib/src/build_runner/build_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class NativeAssetsBuildRunner {
383383
) => _timeAsync('_setupDirectories', () async {
384384
final buildDirName = inputBuilder.computeChecksum();
385385
final packageName = package.name;
386-
final buildDirUri = packageLayout.dartToolNativeAssetsBuilder.resolve(
386+
final buildDirUri = packageLayout.dartToolHooksRunner.resolve(
387387
'$packageName/$buildDirName/',
388388
);
389389
final outDirUri = buildDirUri.resolve('out/');
@@ -392,7 +392,7 @@ class NativeAssetsBuildRunner {
392392
// TODO(https://dartbug.com/50565): Purge old or unused folders.
393393
await outDir.create(recursive: true);
394394
}
395-
final outDirSharedUri = packageLayout.dartToolNativeAssetsBuilder.resolve(
395+
final outDirSharedUri = packageLayout.dartToolHooksRunner.resolve(
396396
'shared/${package.name}/${hook.name}/',
397397
);
398398
final outDirShared = _fileSystem.directory(outDirSharedUri);

pkgs/hooks_runner/lib/src/package_layout/package_layout.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ class PackageLayout {
112112
/// https://dart.dev/tools/pub/package-layout#project-specific-caching-for-tools
113113
late final Uri dartTool = packageConfigUri.resolve('./');
114114

115-
/// The directory where `package:hooks` stores all persistent
115+
/// The directory where `package:hooks_runner` stores all persistent
116116
/// information.
117117
///
118-
/// This folder is owned by `package:hooks`, no other package
118+
/// This folder is owned by `package:hooks_runnner`, no other package
119119
/// should read or modify it.
120120
/// https://dart.dev/tools/pub/package-layout#project-specific-caching-for-tools
121121
///
122122
/// `$rootPackageRoot/.dart_tool/hooks_runner/`.
123-
late final Uri dartToolNativeAssetsBuilder = dartTool.resolve(
124-
'hooks_runner/',
125-
);
123+
late final Uri dartToolHooksRunner = dartTool.resolve('hooks_runner/');
126124

127125
/// The root of `package:$packageName`.
128126
///

pkgs/hooks_runner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: hooks_runner
22
description: >-
33
This package is the backend that invokes build hooks.
44
5-
version: 0.23.0
5+
version: 0.23.1
66

77
repository: https://github.com/dart-lang/native/tree/main/pkgs/hooks_runner
88

0 commit comments

Comments
 (0)