VS Code + CMake: Allow building in different directories per build type
https://github.com/microsoft/vscode-cmake-tools/issues/151
"cmake.buildDirectory" : "${workspaceRoot}/build/${buildType}"
https://github.com/microsoft/vscode-cmake-tools/issues/151
"cmake.buildDirectory" : "${workspaceRoot}/build/${buildType}"
和 add_custom_command
/ add_custom_target
不同,这个是在配置时就运行,但是一定要注意给对工作路径,否则运行结果出乎意料(或者以为没有运行)。
示例:
execute_process(COMMAND ./utils/pre-commit-cmake.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
主要问题:加了 add_subdirectory
但是仍然无法找到头文件。
解决方案:先加上 find_package(Python3 COMPONENTS Interpreter Development)
再添加 pybind11 子文件夹。不然 pybind11 找到的 python 版本可能不对。
首先必须处在仓库中,然后用 https://stackoverflow.com/a/42544963/ 提供的方法提取出每个文件的大小,最后用 perl 计算总的体积。
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
grep -vF --file=<(git ls-tree -r HEAD | awk '{print $3}') |
sort --numeric-sort --key=2 |
cut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest > legacy.txt
perl -ne 'BEGIN{my $sum=0} s/.* (.*) .*/$1/g;
s/B//g;s/Ki/*1024/g;s/Mi/*1024*1024/g;s/Gi/*1024*1024*1024/g;$sum+=eval($_);
END{printf "%.1f MiB\n", $sum/1024/1024}' legacy.txt
把上面的 objectsize
换成 objectsize:disk
就能看到压缩后的文件总体积,在我们仓库中大概是 2216.4 MiB,而压缩前大概是 7304.1 MiB。
What this script displays is the size each file would have in the working directory. If you want to see how much space a file occupies if not checked out, you can use
%(objectsize:disk)
instead of%(objectsize)
. However, mind that this metric also has its caveats, as is mentioned in the documentation.
另外 git-filter-repo 也很好用,速度非常快。需要注意:
gettext
的优先级:
LANGUAGE
LC_ALL
LC_xxx
, according to selected locale category: LC_CTYPE
, LC_NUMERIC
, LC_TIME
, LC_COLLATE
, LC_MONETARY
, LC_MESSAGES
, …LANG
算是一个 fallback
$LANGUAGE
is not part of the C locales, but specific to GNU gettext. If set it is given precedence over anything else.
所以设置 LANGUAGE
不通用,设置 LC_ALL
高优先级,如果系统里面什么都没有设置,LANG
就足够了。
包含了 stdint.h
,同时还有一些格式字符串宏帮助写可移植的 scanf
/printf
代码。
zsh 在 PATH 路径中添加的新命令可以使用 zsh-syntax-highlighting,但是不能用 tab 补全。使用 rehash
命令让 zsh 重新检查命令,就能补全了。
如果是 bash,则要用 hash -r。
在 zsh 的 tab 补全中自动使用 rehash,可以在 ~/.zshrc
中加入:
zstyle ':completion:*' rehash true
sudo usermod -s /bin/bash $(whoami)
chsh
也有同样的功能。两者都是改变了 /etc/passwd 的记录项达到切换登陆 shell 的。
注意,如果用 chsh
,必须先切换到要更改 shell 的用户,比如给当前用户切换 shell 则是:
chsh -s /bin/bash
这里没有 sudo,不是 root 的话会提示输入密码的。如果使用 sudo chsh
就成了给 root 修改登录 shell,含义不一样了!
这个变量表示 bash 真正的入口程序。这个变量的必要性体现在 source 某个 bash 脚本的时候 $0
不能准确反映入口程序。
#!/bin/bash
echo "[$0] vs. [${BASH_SOURCE[0]}]"
$ bash ./foo
[./foo] vs. [./foo]
$ ./foo
[./foo] vs. [./foo]
$ . ./foo
[bash] vs. [./foo]
参考 https://stackoverflow.com/a/35006505/
本来 BASH_SOURCE
是一个数组类型的变量。但是 bash 中使用 $ARR
相当于 ${ARR[0]}
,所以也可以简写。
Important
Caution
如果要创建新的 runner,要记得先把旧的配置文件夹删掉(/srv/gitlab-runner/config
),因为这里多加了映射,要小心残留影响(我之前遇到的一个问题是 runner 信息页面多出来一个 id 为 <legacy>
的 runner,会被 gitlab 分配任务,但是又不会实际执行,导致 jobs 永远无法执行完成)。
启用 runner:
docker run -d --name gitlab-runner --restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:latest
注册:注意 token 每次都不一样,url 一定得用内网(如果可能)而不是从公网绕一圈,不然速度跟不上。