-
Notifications
You must be signed in to change notification settings - Fork 162
Conversation
It looks like the tests are failing because of: I don't really understand the logic of having |
src/platform_win.cc
Outdated
std::wstring_convert<convert_type, wchar_t> converter; | ||
cfg_path = converter.to_bytes(roaming_stream.str()); | ||
} | ||
CoTaskMemFree(static_cast<void*>(roaming_path)); |
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.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680722(v=vs.85).aspx it sounds like this should only be used if the memory was allocated using CoTaskMemAlloc or CoTaskMemRealloc.
Btw, is there a sample somewhere to do this? I'd recommend referencing any doc pages here.
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.
In the docs for https://msdn.microsoft.com/en-us/library/bb762188(VS.85).aspx, it says call is responsible for freeing ppszPath
(in this case roaming_path
) using CoTaskMemFree
. I have moved the call inside the block where the we use it because CoTaskMemFree
does nothing when the parameter is NULL.
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 have referenced the docs in a comment above the call as you recommended
src/project.cc
Outdated
@@ -472,6 +472,15 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) { | |||
} | |||
}); | |||
|
|||
optional<std::string> maybe_cfg = GetGlobalConfigDirectory(); | |||
if (folder_args.empty() && maybe_cfg) { | |||
std::string cfg(*maybe_cfg + ".cquery"); |
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.
nit: std::string config = *maybe_config + ".cquery";
src/project.cc
Outdated
if (FileExists(project->project_dir + ".cquery")) | ||
return LoadFromDirectoryListing(project); | ||
else if (GetGlobalConfigDirectory() && | ||
FileExists(*GetGlobalConfigDirectory() + ".cquery")) |
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.
nit: {}
src/project.cc
Outdated
@@ -472,6 +472,15 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) { | |||
} | |||
}); | |||
|
|||
optional<std::string> maybe_cfg = GetGlobalConfigDirectory(); |
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.
Is the purpose of this block only for the LOG_S(INFO)? In that case we can move the LOG_S(...) into LoadFromDirectoryListing which should eliminate the need for this block.
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.
No sure what you're referring to here? It that the right block?
src/platform_posix.cc
Outdated
EnsureEndsInSlash(config); | ||
config += "cquery"; | ||
if (!FileExists(config)) { | ||
MakeDirectoryRecursive(AbsolutePath(config, true)); |
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.
MakeDirectoryRecursive(AbsolutePath(config, false /*validate*/));
If validate is true then cquery may abort since validate means the directory should exist.
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 catch, have fixed it up
src/platform_posix.cc
Outdated
} else if (home) { | ||
config = home; | ||
} else { | ||
return {}; |
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.
nit: return nullopt;
But instead of having a separate return here (returns in the middle of a func make control-flow hard to read) you can refactor this function so that config
is an optional. The final call to EnsureEndsInSlash
will need to be if (config) EnsureEndsInSlash(*config);
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.
The refactor definitely makes it cleaner, have done as you recommended
The CI failure is unrelated, master is broken at the moment. We don't have any tests that would validate this logic. |
One thing to make sure is that a local compile_commands.json will override the global .cquery file. |
I've fixed it so compile_commands.json is preferred over the global .cquery. Have explained the rational in 9c53e2b. The cleanest way I could think of was adding a default parameter to |
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.
We should make sure to write up the logic of how compilation commands are selected, since the logic is a bit complex/subtle.
src/project.cc
Outdated
[&folder_args, &files, &use_global_config](const std::string& path) { | ||
if (SourceFileLanguage(path) != LanguageId::Unknown) { | ||
files.push_back(path); | ||
} else if (GetBaseName(path) == ".cquery" && !use_global_config) { |
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.
So this is disabling a local .cquery file in the source tree if there is a global config? I think we should honor a local .cquery over the global one even if there is not a .cquery at the top level.
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.
In retrospect I can see how this is not very clear. My rational was that if LoadFromDirectoryListing
is called with use_global_config
set to true then the caller is intending for the global config to be loaded. I'll change it so that the local .cquery is loaded in all cases
This platform specific function is used to get the user's home directory. This gives us a base from where to get the global config file for. Currently WIP as I'm not sure how to implement this for Windows.
This is a tentative implementation, I don't have access to windows so haven't tested it but based on MSDN and StackOverflow this seems to be the way to go.
As discussed in jacobdufault#648, fallback to $HOME if $XDG_CINFIG_HOME is not found.
Previously the global .cquery config was being loaded before the project specific compile_commands.json file. The global .cquery config is intended as a fallback when there are no other configs, so we don't want this. To make it explicit that the global .cquery is being loaded, add a new parameter to LoadFromDirectorylisting (use_global_config) which, if true, will load the global .cquery. This parameter defaults to false, so no changes are required to existing calls.
To document the process of selecting compilation commands, I think adding a second paragraph under the compile_commands.json header of the wiki home page with something like what I've written below would be sufficient. There are three options for specifying the compilation commands that cquery uses for a project.
The selection order of the compilation commands is: |
I can do a squash and merge, but if you'd like to preserve commit history this needs to be rebased. Let me know which you prefer. |
I think a squash and merge is probably best. There's nothing in the commit history of particular importance. |
* Create `GetHomedirectory()` function This platform specific function is used to get the user's home directory. This gives us a base from where to get the global config file for. Currently WIP as I'm not sure how to implement this for Windows. * Find and parse .cquery in home dir if not in project dir * GetHomeDirectory() -> GetGlobalConfigDirectory() * Windows specific implementation of `GetGlobalConfigDirectory()` This is a tentative implementation, I don't have access to windows so haven't tested it but based on MSDN and StackOverflow this seems to be the way to go. * Update *nix implementation of `GetGlobalConfigDirectory()` As discussed in jacobdufault#648, fallback to $HOME if $XDG_CINFIG_HOME is not found. * Use a global .cquery file if none found in the project dir * Add rational to usage of XDG_CONFIG_HOME * Create "cquery" directory in .config if it does not exist * Fix up on Windows * Only call `CoTaskMemFree` if `ShGetKnownFolderpath` passes * Refactor config to optional to improve control flow * Add comment referencing MSDN blog on getting config dir on Windows * Implicitly call string constructor using = operator * Add braces around if-else block * Fixup some errors introduced when making config optional * config -> cfg * Fixup crash when assigning to config * Load global .cquery config at end of LoadCompilationEntriesfromdirectory Previously the global .cquery config was being loaded before the project specific compile_commands.json file. The global .cquery config is intended as a fallback when there are no other configs, so we don't want this. To make it explicit that the global .cquery is being loaded, add a new parameter to LoadFromDirectorylisting (use_global_config) which, if true, will load the global .cquery. This parameter defaults to false, so no changes are required to existing calls. * Add reference for usage of CoTaskMemFree after SHGetKnownFolderPath * Load the local .cquery in all cases that it is present
Reading this thread and also the commit message, I get completely lost about the the position of the global configuration file. Which one is it:
|
For the global config file you can either have a |
I just found a better way to set the global options which is to add a For me, there is no system wide |
Am I right in reading that you want to have the options set by I didn't know about having Having a global config setting the baseline options and the a project local config overriding these as necessary would probably be quite useful, @jacobdufault thoughts? |
@nick96, I didn't mean that I expect to add an In summary, there are at least three ways to set the config for cquery:
|
This PR implements the feature requested in #648.
The key changes are:
.cquery
file in$XDG_CONFIG_HOME/cquery
or in$HOME
if this fails.cquery
file in the%APPDATA
I've tested this a bit on my machine but haven't tested out the Windows specific stuff as a I don't have access to a Windows machine so I hope it works 😄