mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 12:49:36 -06:00
Sort include directives within each block (separated by a blank line) in
lexicographic order (except to prioritize `sys/types.h` first). First
run `clang-format` with the config file:
---
SortIncludes: false
...
Commit the result temporarily. Then run `clang-format` again with:
---
SortIncludes: true
IncludeCategories:
- Regex: 'sys/types.h'
Priority: -1
...
Commit the result temporarily. Start a new branch and cherry-pick the
second commit. Manually resolve conflicts to preserve indentation of
re-ordered includes. This cleans up the include ordering without
changing any other style.
Use the following command to run `clang-format`:
$ git ls-files -z -- \
'*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
egrep -z -v '(Lexer|Parser|ParserHelper)\.' |
egrep -z -v '^Source/cm_sha2' |
egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
egrep -z -v '^Utilities/(KW|cm).*/' |
egrep -z -v '^Tests/Module/GenerateExportHeader' |
egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' |
xargs -0 clang-format -i
This selects source files that do not come from a third-party.
Inspired-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
int fileExists(char* filename)
|
|
{
|
|
#ifndef R_OK
|
|
# define R_OK 04
|
|
#endif
|
|
if ( access(filename, R_OK) != 0 )
|
|
{
|
|
printf("Cannot find file: %s\n", filename);
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int findBundleFile(char* exec, const char* file)
|
|
{
|
|
int res;
|
|
char* nexec = strdup(exec);
|
|
char* fpath = (char*)malloc(strlen(exec) + 100);
|
|
int cc;
|
|
int cnt = 0;
|
|
printf("Process executable name: %s\n", exec);
|
|
|
|
// Remove the executable name and directory name
|
|
for ( cc = strlen(nexec)-1; cc > 0; cc -- )
|
|
{
|
|
if ( nexec[cc] == '/' )
|
|
{
|
|
nexec[cc] = 0;
|
|
if ( cnt == 1 )
|
|
{
|
|
break;
|
|
}
|
|
cnt ++;
|
|
}
|
|
}
|
|
printf("Process executable path: %s\n", nexec);
|
|
sprintf(fpath, "%s/%s", nexec, file);
|
|
printf("Check for file: %s\n", fpath);
|
|
res = fileExists(fpath);
|
|
free(nexec);
|
|
free(fpath);
|
|
return res;
|
|
}
|
|
|
|
int foo(char *exec)
|
|
{
|
|
// Call a CoreFoundation function...
|
|
//
|
|
CFBundleRef br = CFBundleGetMainBundle();
|
|
(void) br;
|
|
|
|
int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist");
|
|
int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt");
|
|
int res3 = findBundleFile(exec, "MacOS/README.rst");
|
|
if ( !res1 ||
|
|
!res2 ||
|
|
!res3 )
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|