åæãšæ³šæäºé
以äžãåæãšæ³šæäºé ã«ãªããŸãã
- Ubuntu 22.04
- Ubuntu ãåäœãã端æ«ã® CPU 㯠x64
ãã®èšäºã®ãŽãŒã«
ç¹å®ã®ãã£ã¬ã¯ããªãç£èŠããŠãæ¡ä»¶ãæºããããæã«ã¹ã¯ãªãããèªåå®è¡ããŸãã
äŸãã°ããã£ã¬ã¯ã㪠A ã«åç»ãã¡ã€ã«ïŒæ¡åŒµåã.mp4
ã§ãããã¡ã€ã«ãšããŸããïŒãæ°èŠè¿œå ãæŽæ°ãåé€ããããããã®åç»ãã¡ã€ã«ããã£ã¬ã¯ã㪠B ã«èªåã§ã³ããŒããããã«ããŸãã
ããã ãã ãš Watchman ã䜿ãã¡ãªããã¯å°ãªãããã«æããŸãããWatchman ã䜿ã£ãŠç¹å®ã®ãã£ã¬ã¯ããªãç£èŠãæ¡ä»¶ãæºããããæã«ã¹ã¯ãªãããå®è¡ãããšããããšãã§ããããã«ãªããšãæ§ã
ãªããšãèªååã§ããããã«ãªããŸãã
Watchman ã«ã€ããŠ
Watchman 㯠Meta 瀟(æ§ Facebook 瀟)ããªãŒãã³ãœãŒã¹ã§éçºããŠããŸãã以äžãå
¬åŒãµã€ããšãªããžããªã§ãã
Watchman 㯠WindowsãmacOSãLinux ã«å¯Ÿå¿ããŠããŸãã
Watchman - A file watching service -
Watches files and records, or triggers actions, when they change.
facebook.github.io
facebook / watchman
Watchman exists to watch files and record when they actually change. It can also trigger actions (such as rebuilding assets) when matching files change.
github.com
Watchman ãã€ã³ã¹ããŒã«ãã
å ¬åŒããã¥ã¡ã³ãã«åŸã£ãŠ Watchman ãã€ã³ã¹ããŒã«ããŸãã ãã®èšäºã§ã¯ Ubuntu ãžã®ã€ã³ã¹ããŒã«ãè¡ããŸãããå ¬åŒããã¥ã¡ã³ãã«ã¯ WindowsãmacOS ãžã®ã€ã³ã¹ããŒã«æ¹æ³ãèšèŒãããŠããŸãã
ãŸãã¯ããã«ãUbuntu çšã«ãã«ãæžã¿ã®.deb
ããã±ãŒãžã®ææ°çãå
¬åŒãªããžããªã®ãªãªãŒã¹ããŒãžããããŠã³ããŒãããŸãã
以äžã®ããã«å
¬åŒãªããžããªã®ãªãªãŒã¹ããŒãžã®äžã§ãä»åã€ã³ã¹ããŒã«ãè¡ã Ubuntu çšã®.deb
ããã±ãŒãžã確èªããŸãã
ãªãªãŒã¹ããŒãžã®ãªã³ã¯ãã¯ãªãã¯ããŠããŠã³ããŒããããã以äžã®ããã«wget
ã³ãã³ãã§ããŠã³ããŒãããŠã OK ã§ãã
$ wget https://github.com/facebook/watchman/releases/download/v2023.10.09.00/watchman_ubuntu22.04_v2023.10.09.00.deb
ãªãããªãªãŒã¹ããŒãžã®äžã«ããäžçªæ°ããããŒãžã§ã³ã ãš Ubuntu çšã®ããã±ãŒãžã Windows çšã®ããã±ãŒãžããŸã çšãããŠããªãå ŽåããããŸãã
ã©ãããŠãææ°çã䜿ãããå Žåã¯ããœãŒã¹ãããã«ãããããšãã§ããŸãããã«ãæ¹æ³ãå
¬åŒããã¥ã¡ã³ãã«èšèŒãããŠããŸãã
èšäºå
¬éæç¹ã§ã¯ãUbuntu çšã«ãã«ãæžã¿ã®deb
ããã±ãŒãžã®ææ°çã¯v2023.10.09
ã§ããã
ããŠã³ããŒããã.deb
ãã¡ã€ã«ã以äžã®ããã«dpkg
ã³ãã³ãã䜿ã£ãŠã€ã³ã¹ããŒã«ããŸãã
$ sudo dpkg -i watchman_ubuntu22.04_v2023.10.09.00.deb
äžèšãå®è¡ãããšä»¥äžã®ããã«ãšã©ãŒã衚瀺ãããŸããããšã©ãŒãåºãããšèªäœãå ¬åŒããã¥ã¡ã³ãã«èšèŒãããŠããã®ã§ãã®ãŸãŸé²ã¿ãŸãã
$ sudo dpkg -i watchman_ubuntu22.04_v2023.10.09.00.deb
[sudo] hisui ã®ãã¹ã¯ãŒã:
以åã«æªéžæã®ããã±ãŒãž watchman ãéžæããŠããŸãã
(ããŒã¿ããŒã¹ãèªã¿èŸŒãã§ããŸã ... çŸåš 225056 åã®ãã¡ã€ã«ãšãã£ã¬ã¯ããªãã€ã³ã¹ããŒã«ãããŠããŸãã)
watchman_ubuntu22.04_v2023.10.09.00.deb ãå±éããæºåãããŠããŸã ...
watchman (20231008.002904.0) ãå±éããŠããŸã...
dpkg: äŸåé¢ä¿ã®åé¡ã«ãã watchman ã®èšå®ãã§ããŸãã:
watchman ã¯ä»¥äžã«äŸå (depends) ããŸã: libgoogle-glog0v5 ...ããã:
ããã±ãŒãž libgoogle-glog0v5 ã¯ãŸã ã€ã³ã¹ããŒã«ãããŠããŸããã
watchman ã¯ä»¥äžã«äŸå (depends) ããŸã: libboost-context1.74.0 ...ããã:
ããã±ãŒãž libboost-context1.74.0 ã¯ãŸã ã€ã³ã¹ããŒã«ãããŠããŸããã
watchman ã¯ä»¥äžã«äŸå (depends) ããŸã: libevent-2.1-7 ...ããã:
ããã±ãŒãž libevent-2.1-7 ã¯ãŸã ã€ã³ã¹ããŒã«ãããŠããŸããã
dpkg: ããã±ãŒãž watchman ã®åŠçäžã«ãšã©ãŒãçºçããŸãã (--install):
äŸåé¢ä¿ã®åé¡ - èšå®ãèŠéããŸã
åŠçäžã«ãšã©ãŒãçºçããŸãã:
watchman
äžèšã®ãšã©ãŒã解決ããããã«ä»¥äžãå®è¡ããŸãã
$ sudo apt-get -f install
äžèšã§äŸåé¢ä¿ã®ã€ã³ã¹ããŒã«ãå®äºããã Watchman ã®ã€ã³ã¹ããŒã«ãå®äºã§ãã è©Šãã«ä»¥äžã§ããŒãžã§ã³ã衚瀺ããŠã¿ãŠãã ããã
$ watchman version
version: 20231008.002904.0
buildinfo: 5ebaad98ba4ac71edc1c904b30e7ca6bae4703b3
äžèšã®ããã«ããŒãžã§ã³æ
å ±ã衚瀺ãããã°æ£åžžã«ã€ã³ã¹ããŒã«ãå®äºããŠããŸãã
ãªããããcargo
ã³ãã³ãã䜿ããå Žåã¯ãUbuntu çšã«ãã«ãããããã®ã§ã¯ãªãææ°ã®ãã®ããœãŒã¹ãããã«ãããŠããã¡ãã OK ã§ãã
watchman ã䜿ã£ãŠãã£ã¬ã¯ããªãç£èŠãã
以äžãå®è¡ããããšã§æå®ãããã£ã¬ã¯ããªãç£èŠããããšãã§ããŸãã
$ watchman watch testa
{
"version": "20231008.002904.0",
"watcher": "inotify",
"watch": "/home/hisui/workspace/watchman-script/testa"
}
äžèšã¯ãã£ã¬ã¯ããª/home/hisui/workspace/watchman-script/testa
ãç£èŠããããšæå³ããŸãã
ç£èŠç¶æ
ã«ããã ãã§ã¯äœãèµ·ããŸããããç£èŠç¶æ
ã®ãã£ã¬ã¯ããªã«å¯ŸããŠåŠçãå®è¡ããæ¡ä»¶ãšå®è¡ããã³ãã³ãïŒä»¥éãããããããªã¬ãšåŒã³ãŸããïŒãèšå®ããŸããèšå®æ¹æ³ãåŸè¿°ããŸãã
ç£èŠäžã®ãã£ã¬ã¯ããªäžèŠ§ã確èªãã
watch-list
ã䜿ãããšã§ç£èŠå¯Ÿè±¡ãšããŠãããã£ã¬ã¯ããªäžèŠ§ã確èªã§ããŸãã
ãªããç£èŠããŠããã ãã§äœãããªã¬ãç»é²ããŠããªãå Žåã§ã衚瀺ãããŸãã
$ watchman watch-list
{
"version": "20231008.002904.0",
"roots": [
"/home/hisui/workspace/watchman-script/testa"
]
}
ç¹å®ã®ãã£ã¬ã¯ããªã® ç£èŠç¶æ ã確èªãã
watch-project ãã£ã¬ã¯ããªãã¹
ã䜿ãããšã§ç¹å®ã®ãã£ã¬ã¯ããªã®ç£èŠæç¡ã確èªã§ããŸãã
$ watchman watch-project ./testa/
{
"version": "20231008.002904.0",
"watcher": "inotify",
"watch": "/home/hisui/workspace/watchman-script/testa"
}
ããªã¬ãèšå®ãã
ç£èŠå¯Ÿè±¡ã®ãã£ã¬ã¯ããªã«å¯ŸããŠãããªã¬ãèšå®ããŠæ¡ä»¶ãšåŠçå
容ãæå®ããŸãã
ããªã¬ãèšå®ã®ããã®ã³ãã³ãã¯ã以äžã®æ§æã«ãªã£ãŠããŸãã
$ watchman -- trigger [ç£èŠãããã£ã¬ã¯ããªãã¹] [ä»»æã®ããªã¬å] [ããªã¬æ¡ä»¶] -- [å®è¡ããã³ãã³ã]
å ·äœäŸã¯ä»¥äžã«ãªããŸãã
$ watchman -- trigger /home/hisui/workspace/watchman-script/testa cpmp4 '*.mp4' -- 'sh /home/hisui/workspace/watchman-script/cp_script.sh'
以äžãå®è¡çµæã§ãã
$ watchman -- trigger /home/hisui/workspace/watchman-script/testa cpmp4 '*.mp4' -- 'sh /home/hisui/workspace/watchman-script/cp_script.sh'
{
"version": "20231008.002904.0",
"triggerid": "cpmp4",
"disposition": "created"
}
äžèšã¯ã以äžã®å 容ãæå®ããŠããŸãã
/home/hisui/workspace/watchman-script/testa
ãç£èŠãã- ããªã¬åã¯
cpmp4
ãšãã - ãã£ã¬ã¯ããª
testa
ã«ãã¡ã€ã«ã®æ¡åŒµåã.mp4
ã§ãããã¡ã€ã«ãäœæãæŽæ°ãåé€ãããããšãæ¡ä»¶ãšãã - æ¡ä»¶ãæºããããæã«
sh /home/hisui/workspace/watchman-script/cp_script.sh
ãå®è¡ãã
ããã®cp_script.sh
ã¯ã以äžã®ãããªå
容ã«ããŠãããtesta
ãã£ã¬ã¯ããªã«ãã.mp4
ãã¡ã€ã«ãtestb
ãã£ã¬ã¯ããªã«ã³ããŒããããã«ããŠããŸãã
#!/bin/bash
# testaã®.mp4ãã¡ã€ã«ãtestbã«ã³ããŒãã
cp /home/hisui/workspace/watchman-script/testa/*.mp4 /home/hisui/workspace/watchman-script/testb/
äžèšã¯ãã ãã ãã¡ã€ã«ãã³ããŒããã ãã§ãããã·ã§ã«ã¹ã¯ãªãããå®è¡ã§ãããããã·ã§ã«ã¹ã¯ãªããã§ã§ããããšãªãã°äœã§ãã§ããŸãã ãã ããäžèšã ãšãã¡ã€ã«ã®äœæã ãã§ãªãããã¡ã€ã«ã®æŽæ°ãšåé€ãããªã¬ãšãªãããã®åºŠã«æå®ããã¹ã¯ãªãããå®è¡ãããŸãã
åäœç¢ºèª
åç¯ã§èšå®ããããªã¬ãæ£ããåäœããã確èªããŸãã
ãã£ã¬ã¯ããªtesta
ã«é©åœãª.mp4
ãã¡ã€ã«ãäœæããŸãã
$ touch ./testa/test.mp4
ãããšãtestb
ãã£ã¬ã¯ããªã«.mp4
ãã¡ã€ã«ãã³ããŒãããŸãã
$ ls ./testb
test.mp4
ãã®ããã«ãtesta
ãã£ã¬ã¯ããªã«.mp4
ãã¡ã€ã«ãæ°èŠäœæãããããtestb
ãã£ã¬ã¯ããªã«.mp4
ãã¡ã€ã«ãã³ããŒããããã«èšå®ã§ããŸããã
ããªã¬äžèŠ§ã確èªãã
以äžã§èšå®ããããªã¬äžèŠ§ã確èªã§ããŸãã
trigger-list
ã®åŸã«ã¯ãããªã¬ãèšå®ãããã£ã¬ã¯ããªã®ãã¹ãæå®ããå¿
èŠããããŸãã
$ watchman trigger-list testa
{
"version": "20231008.002904.0",
"triggers": [
{
"append_files": true,
"stdin": [
"name",
"exists",
"new",
"size",
"mode"
],
"expression": [
"anyof",
[
"match",
"*.mp4",
"wholename"
]
],
"name": "cpmp4",
"command": [
"sh",
"/home/hisui/workspace/watchman-script/cp_script.sh"
]
}
]
}
ããã©ã®ãã£ã¬ã¯ããªã«ããªã¬ãèšå®ãããå¿ããŠããŸã£ãå Žåã¯ããã§ã«è§£èª¬ããwatch-list
ã³ãã³ãã䜿ãããšã§ç£èŠå¯Ÿè±¡ãšãããã£ã¬ã¯ããªã®ãã¹ã確èªã§ããŸãã
ã¡ãªã¿ã«ãããªã¬æªèšå®ã®ãã£ã¬ã¯ããªã«å¯ŸããŠtrigger-list
ã³ãã³ããå®è¡ãããšä»¥äžã®ããã«ãšã©ãŒã衚瀺ãããŸãã
$ watchman trigger-list testb
{
"version": "20231008.002904.0",
"error": "watchman::RootResolveError: failed to resolve root: unable to resolve root /home/hisui/workspace/watchman-script/testb: failed to resolve root: directory /home/hisui/workspace/watchman-script/testb is not watched"
}
ããªã¬ãåé€ãã
èšå®ããããªã¬ãåé€ããã«ã¯ãtrigger-del
ã³ãã³ãã䜿ããŸãã
$ watchman trigger-del [ãã£ã¬ã¯ããªã®ãã¹] [ããªã¬ãŒå]
ããªã¬ãŒåã«ã€ããŠã¯ããã§ã«è§£èª¬ããtrigger-list
ã³ãã³ãã§ç¢ºèªã§ããŸãã
ãŸãšã
Watchman ã䜿ãããšã§ãæå®ãããã£ã¬ã¯ããªãç£èŠããŠãæ¡ä»¶ãæºããããæã«ã¹ã¯ãªãããå®è¡ã§ããŸããã¹ã¯ãªãããè²ã ãšå·¥å€«ããã°ããªãæè»ã«è²ã ãªããšãã§ããŸããã€ã³ã¹ããŒã«ãç°¡åãªã®ã§ãäœããã£ã¬ã¯ããªã®ç£èŠãšæäœãèªååããããšããå Žåã¯ãã²äœ¿ã£ãŠã¿ãŠãã ããã