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

extend utils & update compilation process #396

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

Raid5594
Copy link
Collaborator

[# What ❔

Avoiding compilation, when it is not required

Why ❔

Hardhat caching isn't always working correctly & sometimes we use scripts, so compilation is always triggered.

Checklist

const timestampFilePath = _path.join(process.cwd(), TIMESTAMP_FILE_YUL);
const folderToCheck = _path.join(process.cwd(), CONTRACTS_DIR);

if (needsRecompilation(folderToCheck, timestampFilePath)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checking the folder, rather than specific subfolders, like "contracts-preprocessed/precompiles/test-contracts".
If necessary, we can check each of the compilation targets separately

@@ -253,3 +254,79 @@ export function prepareCompilerPaths(path: string): CompilerPaths {

return new CompilerPaths(absolutePathSources, absolutePathArtifacts);
}

// Get the latest file modification time in the watched folder
function getLatestModificationTime(folder: string): Date | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a comment on when it can return null

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

comment added below


const CONTRACTS_DIR = "contracts";
const OUTPUT_DIR = "contracts-preprocessed";
const TIMESTAMP_FILE = "last_compilation_preprocessing.timestamp"; // File to store the last compilation time
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to add it to .gitignore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


if ((await isFolderEmpty(OUTPUT_DIR)) || needsRecompilation(folderToCheck, timestampFilePath)) {
console.log("Preprocessing needed.");
await deleteDir("./contracts-preprocessed");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use OUTPUT_DIR constant here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

return latestModificationTime > lastCompilationTime;
}

export function deleteDir(path: string): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rmdirSync?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

const timestampFilePath = path.join(process.cwd(), TIMESTAMP_FILE);
const folderToCheck = path.join(process.cwd(), CONTRACTS_DIR);

if ((await isFolderEmpty(OUTPUT_DIR)) || needsRecompilation(folderToCheck, timestampFilePath)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if it will work if:

  1. I first compile in normal mode
    2.I try to run the tests (for this the recompilation in testMode is done.

Seems like on (2) the recompilation wont happen since no changes have been made to the contracts

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@Raid5594 Raid5594 merged commit 4c0e566 into dev Apr 24, 2024
21 checks passed
@Raid5594 Raid5594 deleted the feat/avoid-unnecessary-compilation branch April 24, 2024 13:36
matzayonc pushed a commit to neotheprogramist/era-contracts that referenced this pull request Jun 19, 2024
Yberjon pushed a commit to neotheprogramist/era-contracts that referenced this pull request Aug 12, 2024
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.

2 participants