如何创建一个自记录的Makefile
My new favorite way to completely underuse a Makefile? Creating personalized, per-project repository workflow command aliases that you can check in.
我最喜欢的完全没用Makefile的方法? 创建个性化的按项目存储库工作流命令别名,您可以检入。
Can a Makefile improve your DevOps and keep developers happy? How awesome would it be if a new developer working on your project didn’t start out by copying and pasting commands from your README? What if instead of:
Makefile可以改善您的DevOps并使开发人员满意吗? 如果一个新的开发人员没有通过复制和粘贴自述文件中的命令来开始工作,那将有多棒? 如果不是:
pip3 install pipenv pipenv shell --python 3.8 pipenv install --dev npm install pre-commit install --install-hooks # look up how to install Framework X... # copy and paste from README... npm run serve
… you could just type:
…您可以输入:
make start
make start
…and then start working?
…然后开始工作?
有所作为 (Making a difference)
I use
makeevery day to take the tedium out of common development activities like updating programs, installing dependencies, and testing.
我每天都会使用
make来消除繁琐的开发活动,例如更新程序,安装依赖项和测试。
To do all this with a Makefile (GNU make), we use Makefile rules and recipes. Similar parallels exist for POSIX flavor make, like Target Rules. Here’s a great article on POSIX-compatible Makefiles.
为了使用Makefile(GNU make)来完成所有这些工作,我们使用Makefile规则和配方 。 POSIX风味制造也存在类似的相似之处,例如目标规则 。 这是一篇有关POSIX兼容Makefile的好文章 。
Here’s some examples of things we can
makeeasier (sorry):
这里的有些东西在例子中,我们可以
make更容易(不好意思):
update: ## Do apt upgrade and autoremove sudo apt update && sudo apt upgrade -y sudo apt autoremove -y env: pip3 install pipenv pipenv shell --python 3.8 install: ## Install or update dependencies pipenv install --dev npm install pre-commit install --install-hooks serve: ## Run the local development server hugo serve --enableGitInfo --disableFastRender --environment development initial: update env install serve ## Install tools and start development server
Now we have some command-line aliases that you can check in. Great idea! If you’re wondering what’s up with that weird
##comment syntax, it gets better.
现在我们有了一些命令行别名,您可以签入。好主意! 如果您想知道奇怪的
##注释语法有什么用,它会变得更好。
一个自记录的Makefile (A self-documenting Makefile)
Aliases are great, if you remember what they all are and what they do without constantly typing
cat Makefile. Naturally, you need a
helpcommand:
别名很棒,如果您记住它们的全部含义而无需不断输入
cat Makefile就能做什么。 当然,您需要一个
help命令:
.PHONY: help help: ## Show this help @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
With a little command-line magic, this
egrepcommand takes the output of
MAKEFILE_LIST, sorts it, and uses
awkto find strings that follow the
##pattern. It then prints a helpful formatted version of the comments.
使用一点命令行魔术,此
egrep命令获取
MAKEFILE_LIST的输出,对其进行排序,然后使用
awk查找遵循
##模式的字符串。 然后,它会打印出有用的格式化的注释版本。
We’ll put it at the top of the file so it’s the default target. Now to see all our handy shortcuts and what they do, we just run
make, or
make help:
我们将其放在文件的顶部,因此它是默认目标。 现在,要查看我们所有方便的快捷方式及其作用,我们只需运行
make或
make help:
help Show this help initial Install tools and start development server install Install or update dependencies serve Run the local development server update Do apt upgrade and autoremove
Now we have our very own personalized and project-specific CLI tool!
现在,我们有了自己的个性化和特定于项目的CLI工具!
The possibilities for improving your DevOps flow with a self-documenting Makefile are almost endless. You can use one to simplify any workflow and produce some very happy developers.
使用自记录的Makefile改善DevOps流程的可能性几乎是无限的。 您可以使用它来简化任何工作流程并产生一些非常满意的开发人员。
翻译自: https://www.freecodecamp.org/news/self-documenting-makefile/
- 记录Android学习 - 如何创建一个活动
- 在Maximo7中如何使用日志记录应用程序创建一个日志文件?
- 【nodejs】新手如何一步步创建一个简单的express项目
- 函数指针类的虚函数表是一块连续的内存,每个内存单元中记录一个JMP指令的地址。 注意的是,编译器会为每个有虚函数的类创建一个虚函数表,该虚函数表将被该类的所有对象共享。类的每个虚成员占据虚函数表中的一
- 如何创建一个基本JQuery的插件
- 听Jake Wharton讲如何成为更优秀的开发者与创建一个成功的开源项目
- 如何在SQL Server上Enable Filestream以及创建一个支持File Stream的DB?
- 如何将Oracle中同一列的多行记录拼接成一个字符串 十一__262 | 浏览 8183 次 推荐于2016-01-25 17:34:18 最佳答案 需要用wm_concat函数来实现。
- 如何保证一个类只能在堆上被创建
- 【数据库开发】如何创建MySQL数据库连接池(一个基于libmysql的MySQL数据库连接池示例(C/C++版))
- 如何创建一个自己的.NET Core Global Tools
- 如何用 React Native 创建一个iOS APP?(二)
- 如何为windows2000创建一个tftp service
- 如何使用 CoreText 创建一个简单的杂志应用
- iOS中如何创建一个滑出式导航面板(1)
- JavaWeb中如何自己创建一个servlet
- 如何在linux下创建一个简单的JNI程序HelloWorld
- SIF如何创建一个安全上下文学习
- 如何创建数据库连接池(一个基于libmysql的MySQL数据库连接池示例)
- SQL语句如何在同一个表内复制一条记录