Skip to content

Reuse executable when no-change in project #44151

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Thevakumar-Luheerathan
Copy link
Member

@Thevakumar-Luheerathan Thevakumar-Luheerathan commented Jun 5, 2025

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

Fixes #44136

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Consecutive bal build, bal run, bal test
image
image
image

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

if (CommandUtil.isFilesModifiedSinceLastBuild(buildJson, project)) {
return true;
}
if (isRebuildForCurrCmd()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIU, this method checks if there are any additional flags, and if that is the case, we rebuild. Can't we rename the method to reflect that?

if (isRebuildForCurrCmd()) {
return true;
}
return !CommandUtil.isPrevCurrCmdCompatible(project.buildOptions(), buildJson.getBuildOptions());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return !CommandUtil.isPrevCurrCmdCompatible(project.buildOptions(), buildJson.getBuildOptions());
return !CommandUtil.isPrevAndCurrCmdCompatible(project.buildOptions(), buildJson.getBuildOptions());

Comment on lines 1303 to 1309
if (isProjectFilesModified(buildJson, project)) {
return true;
}
if (isSettingsFileModified(buildJson)) {
return true;
}
return isExecutableModified(buildJson, project);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isProjectFilesModified(buildJson, project)) {
return true;
}
if (isSettingsFileModified(buildJson)) {
return true;
}
return isExecutableModified(buildJson, project);
return isProjectFilesModified(buildJson, project) || isSettingsFileModified(buildJson) || isExecutableModified(buildJson, project);

@Thevakumar-Luheerathan Thevakumar-Luheerathan marked this pull request as ready for review June 25, 2025 09:52
@keizer619 keizer619 requested a review from Copilot June 25, 2025 13:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #44136 by reusing the executable when no changes occur in the project. Key changes include:

  • Adding new fields and getters/setters in BuildJson to record build metadata.
  • Updating BuildOptions, command implementations, and various tasks to support skipping rebuilds when no modifications are detected.
  • Enhancing test coverage for build/test scenarios and adjusting task execution logic (e.g. skipTask flag).

Reviewed Changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BuildJson.java Added new metadata fields and associated accessors.
compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java Introduced a new method to retrieve locking mode.
cli/ballerina-cli/… Updated multiple test and command files to support skipping rebuilds and reusing executable output.
cli/ballerina-cli/src/main/java/io/ballerina/cli/task/* Introduced and propagated a skipTask flag to control task execution.
cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/* Adjusted rebuild detection and task execution logic based on file changes.
cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java Added SHA-256 digest computation and file modification checks for build fingerprinting.
Comments suppressed due to low confidence (1)

cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/RunCommand.java:343

  • [nitpick] It would be beneficial to add inline documentation for the isRebuildForCurrCmd() method explaining the rationale behind each condition to improve future maintainability.
        }


public static String getSHA256Digest(File fileToEvaluate) throws NoSuchAlgorithmException, IOException {
MessageDigest digest = MessageDigest.getInstance(SHA_256);
byte[] fileBytes = Files.readAllBytes(fileToEvaluate.toPath());
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

Consider using a buffered stream (e.g., DigestInputStream) to compute the SHA-256 digest for large files instead of reading the entire file into memory.

Copilot uses AI. Check for mistakes.

Comment on lines 83 to 85
if (!project.buildOptions().nativeImage()) {
this.out.println("Generating executable");
this.out.println("Generating executable" + (skipTask ? "(skipped)" : ""));
}
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The repeated pattern of checking 'skipTask' and printing '(skipped)' is seen in multiple tasks; consider abstracting this logic into a helper function to reduce duplication and improve readability.

Copilot uses AI. Check for mistakes.

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.

[Improvement]: Optimize subsequent build times for unchanged Ballerina projects
2 participants