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
Don't use temporary file when creating tag files without running preprocessor #3204
Conversation
src/tagmanager/tm_workspace.c
Outdated
@@ -453,19 +419,19 @@ static GList *lookup_includes(const gchar **includes, gint includes_count) | |||
#ifdef HAVE_GLOB_H | |||
globbuf.gl_offs = 0; | |||
|
|||
if (includes[0][0] == '"') /* leading \" char for glob matching */ | |||
if (sources[0][0] == '"') /* leading \" char for glob matching */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know its not something you changed (except the variable name) but where did this "
come from? Its not mentioned in the manual as being required for globbing, nor in the parameter description of sources
?
Also its only tested on sources[0]
but then assumed on all sources below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know its not something you changed (except the variable name) but where did this " come from? Its not mentioned in the manual as being required for globbing, nor in the parameter description of sources?
This seems to be wrong. I think this was meant to detect
geany -g *
vs
geany -g "*"
where in the first case the shell expands *
to the list of files Geany receives as its argument list while in the second case it receives *
(but without the "
which gets removed by the shell).
Not sure what we want and whether we actually want/need to support globbing by ourselves or whether what the shell does for us is sufficient already. I think the situation where this might be useful is when there are too many files matching the patterns so they exceed the max. number of command-line arguments.
Maybe we could just drop this check completely and always try to apply globbing (when HAVE_GLOB_H
is defined).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference (in that order)
1 Leave globbing to the shell
2 explicitly enable internal globbing with a separate parameter
3 Always apply globbing
I'm not sure if 1 leaves windows users behind, but if not I would greatly prefer that.
src/tagmanager/tm_workspace.c
Outdated
gchar *clean_path; | ||
|
||
if (dirty_len < 2) | ||
continue; | ||
|
||
clean_path = g_malloc(dirty_len - 1); | ||
|
||
strncpy(clean_path, includes[i] + 1, dirty_len - 1); | ||
strncpy(clean_path, sources[i] + 1, dirty_len - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skips first character of source, see above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old code so I would ignore this problem for now.
But IIUC this is only a problem for the second and later arguments as the first should be enclosed by "
(so clean_path
strips "
), right?
Plus, as @techee mentions, the condition is probably never true. Best to leave globbing to the shell really (or clever find+xargs tricks)
I know its not something this PR changes, but fixing globbing it will probably conflict with this PR, so maybe it needs to be fixed first, created #3205? |
OK so if I understand the conclusion of #3205 correctly, is it OK to remove the globbing feature completely? |
Heh, should read the comments completely before looking at the code. So this needs a rebase and then we're back in the green, right? |
The code was probably originally written for c/c++ only and all the mentions of "include files" mean "source files" for other languages.
Is it OK to force-push the patches rebased on top of master (to resolve conflict with already merged #3207)? |
Yes, see the comment above :-) |
f5c7f6f
to
8a40f2c
Compare
OK, done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, only minor comments that you can chose to ignore.
src/tagmanager/tm_workspace.c
Outdated
guint i; | ||
tm_source_files = g_slist_prepend(tm_source_files, source_file); | ||
tm_source_file_parse(source_file, NULL, 0, FALSE); | ||
for (i = 0; i < source_file->tags_array->len; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could declare guint i
inside the for
, or alternatively use our beloved foreach_array()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still tend to follow the other code's style despite Geany now uses C99.
src/tagmanager/tm_workspace.c
Outdated
GPtrArray *tags = g_ptr_array_new(); | ||
GSList *tm_source_files = NULL; | ||
|
||
for (node = source_files; node; node = node->next) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use foreach_list()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach_*()
and other Geany stuff isn't currently available in tag manager - it's still in the form of (kind of) external library and doesn't include anything from Geany.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's under src/ so I consider it part of Geany completely. But it's "your area" so OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not that I'm against it, it's just that nobody did it yet. If we decide to do that, we should probably do it properly and go through all the for
loops and replace them if possible plus do other geany-style changes.
src/tagmanager/tm_workspace.c
Outdated
ret = create_global_tags_preprocessed(pre_process_cmd, source_files, tags_file, lang); | ||
else | ||
{ | ||
GList *node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe stuff the else case also in a static function like the preprocess case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's probably better. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still approving. I suggest to squash-merge the end result.
…rocessor The tm_workspace_create_global_tags() function generates tags for two cases: 1. Source files pre-processed by C pre-processor. It first generates a file combining the parsed header files by creating a temporary file in which all the header files are included and this file is passed to the pre-processor. The result of the pre-processed file is then parsed by the ctags parser. 2. Source files directly parsed by the ctags parser. In this case all the source files are concatenated to a single file which is then parsed by the ctags parser. This patch leaves (1) more or less unchanged; however, the creation of the temporary file in (2) is unnecessary - the individual files can be parsed directly, the tags from all the parses can be combined, sorted and pruned without creating the temporary file. The temporary file is a problem for unit tests where some languages use the file name as the name of module in which the tags are defined and by using a different name, the unit test generates a different tag file every time it's run. Note the changed output of the process_order unit test caused by this change. The test parses two files, one containing enum { I1_E1, I1_E2, }; the other contining enum { I2_E1, I2_E2, }; Previously, because the files were concatenated the enums were different tags and the anonnymous tag renaming function renamed them to anon_enum_1 and anon_enum_2. Because now the files are parsed separately, the enum from the first file gets renamed to anon_enum_1 and when parsing the second file, we get the name anon_enum_1 as well for the second enum. This however isn't a problem - we don't display global tags in the symbol tree, autocompletion, and they are also ignored in scope completion so this shouldn't matter much.
3ad0f50
to
8c7081c
Compare
I've pushed the squashed version. I'll keep this PR open for about a week and unless there are objections from others, I'll merge it then. |
This patch avoids creating a temporary file containing concatenated source files passed on the command-line when the
-P
option is used (or when tags are generated for other languages than C/C++) by e.g.More discussion can be found in #3163.