Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local caching #78

Merged
merged 16 commits into from
Apr 6, 2022
Merged

Local caching #78

merged 16 commits into from
Apr 6, 2022

Conversation

aomarks
Copy link
Member

@aomarks aomarks commented Apr 5, 2022

Script output is now saved and restored using a local cache directory:

<package>/.wireit/<script-name-hex>/cache/<cache-key-sha256>

This includes all output files, plus the stdout and stderr replays.

Fixes #12

Related upcoming work

Copy link
Collaborator

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful!

src/caching/local-cache.ts Show resolved Hide resolved
src/executor.ts Outdated Show resolved Hide resolved
src/executor.ts Show resolved Hide resolved
src/test/optimize-copies.test.ts Show resolved Hide resolved
src/test/optimize-mkdirs.test.ts Outdated Show resolved Hide resolved
src/util/optimize-fs-ops.ts Show resolved Hide resolved
}
});

test.run();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could either this test or the optimize-cp test receive an empty string as a path?

Copy link
Member Author

@aomarks aomarks Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test that it just treats "" as its own thing, which is what it does right now. I'm not 100% sure what the correct thing is there.

I guess "" could mean the root directory, and then in the mkdir case it should always get removed if there are any other directories, and in the copy case it would always win over any other entries.

I'm not sure it can happen in practice given the current implementation.

@@ -8,6 +8,7 @@ import {WireitError} from './error.js';
import {DefaultLogger} from './logging/default-logger.js';
import {Analyzer} from './analyzer.js';
import {Executor} from './executor.js';
import {LocalCache} from './caching/local-cache.js';

const packageDir = process.env.npm_config_local_prefix;
const logger = new DefaultLogger(packageDir ?? process.cwd());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check to see if the current node is >= our minimum version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have the engines check already, which will warn on install. I feel like that's ok for now.

//
// Convert Windows-style paths to POSIX-style paths if we are on
// Windows, because fast-glob only understands POSIX-style paths.
posixifyPathIfOnWindows(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to glob the replay paths, or should those be outside the call to glob?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm including them in glob because that's an easy way to only include them if they exist. Added a comment.

assert.not(await rig.exists('output/1/c/d/e'));
assert.equal(await rig.read('output/0/a'), 'v0');
assert.equal(await rig.read('output/0/b'), 'v0');
assert.equal(await rig.read('output/0/c/d/e'), 'v0');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also assert that the excluded file still exists and still has the expected contents

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Previous output should be deleted.
assert.not(await rig.exists('output/0/a'));
assert.not(await rig.exists('output/0/b'));
assert.not(await rig.exists('output/0/c/d/e'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert that the excluded file is still present

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

README.md Outdated Show resolved Hide resolved
src/caching/local-cache.ts Outdated Show resolved Hide resolved
src/test/optimize-copies.test.ts Outdated Show resolved Hide resolved
src/util/script-data-dir.ts Outdated Show resolved Hide resolved
@aomarks aomarks merged commit ed5fb15 into main Apr 6, 2022
@aomarks aomarks deleted the cache branch April 6, 2022 23:07
aomarks added a commit that referenced this pull request Apr 7, 2022
- Adds the missing `test:local-cache` script, which I forgot to include in the merge between #84 and #78.

- Bump the version of `wireit` we are building ourselves with.

- Set `WIREIT_PARALLEL=1` for now, because it's difficult to read the test output when stdio is interleaved (I'm planning a fix for that soon, where we only allow one process at a time to write to stdio).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache output locally
4 participants