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

Improved getting resources from the gcc commandline. #311

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

ewaterlander
Copy link
Contributor

The old method assumed all resources were at the end of the line, optionally followed by option -o.
Now the complete line is scanned for valid resource file extensions.

@github-actions
Copy link

github-actions bot commented Mar 7, 2023

Test Results

     592 files       592 suites   14m 10s ⏱️
10 057 tests 10 035 ✔️ 22 💤 0
10 179 runs  10 157 ✔️ 22 💤 0

Results for commit 5834281.

♻️ This comment has been updated with latest results.

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

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

Your change looks good. It really makes me wonder why originally it was coded to only consider the last arguments to the command line though. I hope there is nothing we are overlooking on this and really wish that there were some preexisting tests for this. It seems unlikely there would be an errant .c or similar in the command line so I am ok with this change.

The code you copied needed to use regular expressions because it was integrated into a longer regex. As you only care about extensions here I recommend a simpler bit of code for your consideration.

@Override
public IResource[] getResourcesFromCommand(List<String> cmd, URI buildDirectoryURI) {
// Start at the back looking for arguments
List<IResource> resources = new ArrayList<>();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String extensionPattern = getPatternFileExtensions();
Copy link
Member

Choose a reason for hiding this comment

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

Below I recommend getting rid of the regular expression entirely, but if it is needed: Because this code can be processing large amounts of output we should be pre-compiling, or compiling as early as possible, the patterns.

uri = Paths.get(mingwPath).toUri();

String ext = getFileExtension(arg);
if (Pattern.matches(extensionPattern, ext)) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think a regular expression is the suitable data structure here. How about something like this:

	private Set<String> getPatternFileExtensions() {
		IContentTypeManager manager = Platform.getContentTypeManager();

		Set<String> fileExts = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);

		IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
		fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));

		IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
		fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC)));

		return fileExts;
	}

and then here do:

    if (getPatternFileExtensions().contains(ext)) {

(although it may be best to cache the getPatternFileExtensions result somewhere as the number of arguments and number of command lines to be processed could be quite large)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Jonah,
Thanks for your comment. Regular expression is indeed overkill here. I will update the change.
kind regards,
Erwin

@ewaterlander ewaterlander force-pushed the getResourcesFromCommand branch from 98a1116 to a723041 Compare March 8, 2023 10:11
Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

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

LGTM. I will be merging soon

@jonahgraham jonahgraham added the build Build components of CDT, anything to do with running the compiler, using Make, CMake, or any builder label Mar 8, 2023
@jonahgraham jonahgraham added this to the 11.2.0 milestone Mar 8, 2023
The old method assumed all resources were at the end of the line,
optionally followed by option -o.
Now the complete line is scanned for valid resource file extensions.
@jonahgraham jonahgraham force-pushed the getResourcesFromCommand branch from a723041 to 5834281 Compare March 16, 2023 14:22
@jonahgraham
Copy link
Member

I have rebased the change to make sure that it builds cleanly on main now that we released 11.1.0. Normally this is just a check that code cleanliness still passes, especially bundle version numbers are where they are supposed to be.

@jonahgraham jonahgraham merged commit a89ce59 into eclipse-cdt:main Mar 16, 2023
@jonahgraham
Copy link
Member

Thank you @ewaterlander for the fix.

@ewaterlander
Copy link
Contributor Author

Thank you @ewaterlander for the fix.

You're welcome.

@ewaterlander ewaterlander deleted the getResourcesFromCommand branch March 16, 2023 16:05
ewaterlander added a commit to ewaterlander/cdt that referenced this pull request Apr 21, 2023
GCCToolChain.stripCommand() assumed that all resources are at the end
of the command, like in the old version of
GCCToolChain.getResourcesFromCommand() which was fixed in PR eclipse-cdt#311 (see
commit a89ce59). Now stripCommand() is in line with
getResourcesFromCommand().
jonahgraham pushed a commit that referenced this pull request Apr 21, 2023
GCCToolChain.stripCommand() assumed that all resources are at the end
of the command, like in the old version of
GCCToolChain.getResourcesFromCommand() which was fixed in PR #311 (see
commit a89ce59). Now stripCommand() is in line with
getResourcesFromCommand().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build components of CDT, anything to do with running the compiler, using Make, CMake, or any builder
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants