mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
fix bug in lint.fish helper script
I just noticed that depending on the state of your working tree there can be one or more spaces after the modification token and the file name. If there is more than one space that causes the `string split` to produce unexpected output.
This commit is contained in:
parent
85799ee86e
commit
6431c0de16
2 changed files with 30 additions and 42 deletions
|
@ -34,13 +34,8 @@ if test $all = yes
|
||||||
else
|
else
|
||||||
# We haven't been asked to lint all the source. If there are uncommitted
|
# We haven't been asked to lint all the source. If there are uncommitted
|
||||||
# changes lint those, else lint the files in the most recent commit.
|
# changes lint those, else lint the files in the most recent commit.
|
||||||
set pending (git status --porcelain --short --untracked-files=all | sed -e 's/^ *//')
|
set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
||||||
if set -q pending[1]
|
if not set -q files[1]
|
||||||
# There are pending changes so lint those files.
|
|
||||||
for arg in $pending
|
|
||||||
set files $files (string split -m 1 ' ' $arg)[2]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# No pending changes so lint the files in the most recent commit.
|
# No pending changes so lint the files in the most recent commit.
|
||||||
set files (git show --word-diff=porcelain --name-only --pretty=oneline head)[2..-1]
|
set files (git show --word-diff=porcelain --name-only --pretty=oneline head)[2..-1]
|
||||||
end
|
end
|
||||||
|
@ -56,10 +51,9 @@ if set -q c_files[1]
|
||||||
echo ========================================
|
echo ========================================
|
||||||
echo Running cppcheck
|
echo Running cppcheck
|
||||||
echo ========================================
|
echo ========================================
|
||||||
# The stderr to stdout redirection is because cppcheck, incorrectly
|
# The stderr to stdout redirection is because cppcheck, incorrectly IMHO, writes its
|
||||||
# IMHO, writes its diagnostic messages to stderr. Anyone running
|
# diagnostic messages to stderr. Anyone running this who wants to capture its output will
|
||||||
# this who wants to capture its output will expect those messages to be
|
# expect those messages to be written to stdout.
|
||||||
# written to stdout.
|
|
||||||
cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>& 1
|
cppcheck -q --verbose --std=posix --std=c11 --language=c++ --template "[{file}:{line}]: {severity} ({id}): {message}" --suppress=missingIncludeSystem --inline-suppr --enable=$cppchecks $cppcheck_args $c_files 2>& 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,10 +62,9 @@ if set -q c_files[1]
|
||||||
echo ========================================
|
echo ========================================
|
||||||
echo Running oclint
|
echo Running oclint
|
||||||
echo ========================================
|
echo ========================================
|
||||||
# The stderr to stdout redirection is because oclint, incorrectly
|
# The stderr to stdout redirection is because oclint, incorrectly writes its final summary
|
||||||
# writes its final summary counts of the errors detected to stderr.
|
# counts of the errors detected to stderr. Anyone running this who wants to capture its
|
||||||
# Anyone running this who wants to capture its output will expect those
|
# output will expect those messages to be written to stdout.
|
||||||
# messages to be written to stdout.
|
|
||||||
if test (uname -s) = "Darwin"
|
if test (uname -s) = "Darwin"
|
||||||
if not test -f compile_commands.json
|
if not test -f compile_commands.json
|
||||||
xcodebuild > xcodebuild.log
|
xcodebuild > xcodebuild.log
|
||||||
|
|
45
src/fish.cpp
45
src/fish.cpp
|
@ -92,39 +92,34 @@ extern "C" {
|
||||||
int _NSGetExecutablePath(char* buf, uint32_t* bufsize);
|
int _NSGetExecutablePath(char* buf, uint32_t* bufsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the path to the current executable. This needs to be realpath'd. */
|
// Return the path to the current executable. This needs to be realpath'd.
|
||||||
static std::string get_executable_path(const char *argv0)
|
static std::string get_executable_path(const char *argv0)
|
||||||
{
|
{
|
||||||
char buff[PATH_MAX];
|
char buff[PATH_MAX + 1];
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
{
|
// On OS X use it's proprietary API to get the path to the executable.
|
||||||
/* Returns 0 on success, -1 if the buffer is too small */
|
|
||||||
uint32_t buffSize = sizeof buff;
|
uint32_t buffSize = sizeof buff;
|
||||||
if (0 == _NSGetExecutablePath(buff, &buffSize))
|
if (_NSGetExecutablePath(buff, &buffSize) == 0) return std::string(buff);
|
||||||
|
#else
|
||||||
|
// On non-OS X UNIXes, try /proc directory.
|
||||||
|
ssize_t len;
|
||||||
|
len = readlink("/proc/self/exe", buff, sizeof buff); // Linux
|
||||||
|
if (len == -1) {
|
||||||
|
len = readlink("/proc/curproc/file", buff, sizeof buff); // BSD
|
||||||
|
if (len == -1) {
|
||||||
|
len = readlink("/proc/self/path/a.out", buff, sizeof buff); // Solaris
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len > 0) {
|
||||||
|
buff[len] = '\0';
|
||||||
return std::string(buff);
|
return std::string(buff);
|
||||||
|
|
||||||
/* Loop until we're big enough */
|
|
||||||
char *mbuff = (char *)malloc(buffSize);
|
|
||||||
while (0 > _NSGetExecutablePath(mbuff, &buffSize))
|
|
||||||
mbuff = (char *)realloc(mbuff, buffSize);
|
|
||||||
|
|
||||||
/* Return the string */
|
|
||||||
std::string result = mbuff;
|
|
||||||
free(mbuff);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
{
|
|
||||||
/* On other Unixes, try /proc directory. This might be worth breaking out into macros. */
|
|
||||||
if (0 < readlink("/proc/self/exe", buff, sizeof buff) || // Linux
|
|
||||||
0 < readlink("/proc/curproc/file", buff, sizeof buff) || // BSD
|
|
||||||
0 < readlink("/proc/self/path/a.out", buff, sizeof buff)) // Solaris
|
|
||||||
{
|
|
||||||
return std::string(buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Just return argv0, which probably won't work (i.e. it's not an absolute path or a path relative to the working directory, but instead something the caller found via $PATH). We'll eventually fall back to the compile time paths. */
|
// Just return argv0, which probably won't work (i.e. it's not an absolute path or a path
|
||||||
|
// relative to the working directory, but instead something the caller found via $PATH). We'll
|
||||||
|
// eventually fall back to the compile time paths.
|
||||||
return std::string(argv0 ? argv0 : "");
|
return std::string(argv0 ? argv0 : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue