project 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  1. #!/usr/bin/env bash
  2. # Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
  3. # Copyright (C) 2018,2019 Andrew Robbins <contact@andrewrobbins.info>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. PROJECT_ACTIONS_GENERIC=(usage dependencies download extract update build install release clean)
  18. PROJECT_ACTIONS_GENERIC_IGNORE_CHECK=(usage clean)
  19. PROJECT_ACTIONS_HELPERS=(arguments dependencies)
  20. INSTALL_REGEX='\([^:]*\):\(.*\)'
  21. project_include() {
  22. local project=$1
  23. local project_path=$(project_path "$project")
  24. unset -f "${PROJECT_ACTIONS[@]}"
  25. source "$project_path/$project"
  26. project_helper_include "$project"
  27. }
  28. project_helper_include() {
  29. local project=$1
  30. local project_path=$(project_path "$project")
  31. local include="$project_path/$project-helper"
  32. if [[ -f "$include" ]]
  33. then
  34. source "$include"
  35. fi
  36. }
  37. project_check() {
  38. local project="${1##*/}"
  39. local project_path="$(project_path "$project")"
  40. if ! [[ -f "$project_path/$project" ]]; then
  41. return 1
  42. fi
  43. }
  44. project_dependencies() {
  45. local project=$1
  46. shift
  47. local -a dependencies
  48. mapfile -t dependencies < <(project_file_contents_herit "$project" "$CONFIGS" "$DEPENDENCIES" "$@")
  49. if [[ -n ${dependencies[*]} ]]; then
  50. printf '%s\n' "${dependencies[@]}"
  51. fi
  52. }
  53. project_dependencies_check() {
  54. local project=$1
  55. shift
  56. local -a dependencies
  57. mapfile -t dependencies < <(project_dependencies "$project" "$@")
  58. local -i missing=0
  59. for ((i = 0, nodeps = ${#dependencies[@]}; i < nodeps; ++i)); do
  60. local -a dependency=(${dependencies[i]})
  61. project_check "${dependency[0]}" || let ++missing
  62. done
  63. return $missing
  64. }
  65. project_dependencies_sources_check() {
  66. local project=$1
  67. shift
  68. local -a dependencies
  69. mapfile -t dependencies < <(project_dependencies "$project" "$@")
  70. local -i missing=0
  71. for ((i = 0, nodeps = ${#dependencies[@]}; i < nodeps; ++i)); do
  72. local -a dependency=(${dependencies[i]})
  73. project_sources_directory_filled_check "${dependency[0]}" ||
  74. let ++missing
  75. done
  76. return $missing
  77. }
  78. project_dependencies_action_arguments() {
  79. local action=$1
  80. local project=$2
  81. shift 2
  82. local -a dependencies
  83. mapfile -t dependencies < <(project_dependencies "$project" "$@")
  84. for ((i = 0, nodeps = ${#dependencies[@]}; i < nodeps; ++i)); do
  85. local -a dependency=(${dependencies[i]})
  86. if project_function_check "${dependency[0]}" "$action"; then
  87. project_action_arguments "$action" "${dependency[@]}"
  88. fi
  89. done
  90. }
  91. project_function_check() {
  92. local project=$1
  93. local function=$2
  94. project_include "$project"
  95. if ! function_check "$function"
  96. then
  97. return 1
  98. fi
  99. return 0
  100. }
  101. project_action() {
  102. local action="$1"
  103. shift
  104. local project="$1"
  105. shift
  106. local arguments="$*"
  107. project_action_check "$action" "$project" "$@"
  108. printf '%s\n\n' "Project $project $action (with ${arguments:-no argument})"
  109. if (set +e; "$action" "$@"); then
  110. printf '\n%s\n' "Project $project $action (with ${arguments:-no argument}) completed"
  111. else
  112. printf 1>&2 '\n%s\n' "Project $project $action (with ${arguments:-no argument}) failed"
  113. return 1
  114. fi
  115. }
  116. project_action_check() {
  117. local action="$1"
  118. shift
  119. local project="$1"
  120. shift
  121. (
  122. set +e
  123. if ! function_check "${action}_check"; then
  124. return 1
  125. fi
  126. for project_force in $PROJECTS_FORCE; do
  127. if [[ "$project_force" == "$project" ]]; then
  128. return 1
  129. fi
  130. done
  131. (
  132. set -e
  133. "${action}_check" "$@"
  134. )
  135. )
  136. }
  137. project_action_helper() {
  138. local helper="$1"
  139. shift
  140. local project="$1"
  141. shift
  142. if ! function_check "$helper"; then
  143. return 0
  144. fi
  145. "$helper" "$@"
  146. }
  147. project_action_arguments() {
  148. local action="$1"
  149. shift
  150. local project="$1"
  151. shift
  152. project_include "$project"
  153. project_action_arguments_verify_recursive "$action" "$project" "$@"
  154. project_action_arguments_recursive "$action" "$project" "$@"
  155. }
  156. project_action_arguments_verify_recursive() {
  157. local action="$1"
  158. shift
  159. local project="$1"
  160. shift
  161. local action_helper_arguments
  162. # Store final argument.
  163. local argument="${*:$#}"
  164. local test
  165. if [[ "$#" -gt 1 ]]; then
  166. # Set previous arguments.
  167. set "${@:1:$#-1}"
  168. elif [[ "$#" -eq 1 ]]; then
  169. shift
  170. else
  171. return 0
  172. fi
  173. action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")"
  174. if [[ -n "$action_helper_arguments" ]]; then
  175. test="$(printf '%s\n' "$action_helper_arguments" | grep -e "^$argument\$" || true)"
  176. if [[ -z "$test" ]]; then
  177. printf 1>&2 '%s\n' "Invalid argument $argument for project $project action $action"
  178. return 1
  179. fi
  180. fi
  181. project_action_arguments_verify_recursive "$action" "$project" "$@"
  182. }
  183. project_action_arguments_recursive() {
  184. local action="$1"
  185. shift
  186. local project="$1"
  187. shift
  188. local action_helper_arguments
  189. local argument
  190. action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@" || true)"
  191. if [[ -z "$action_helper_arguments" ]]; then
  192. project_action "$action" "$project" "$@"
  193. else
  194. # This is to allow space characters in arguments.
  195. local ifs_save="$IFS"
  196. local IFS=$'\n'
  197. for argument in $(printf '%s\n' "$action_helper_arguments")
  198. do
  199. IFS="$ifs_save"
  200. # Only a single argument at a time is returned by the helper.
  201. project_action_arguments_recursive "$action" "$project" "$@" "$argument"
  202. done
  203. fi
  204. }
  205. project_action_projects() {
  206. local action="$1"
  207. shift
  208. local project="$1"
  209. shift
  210. local project_path="$(project_path "$project")"
  211. local project_projects_path="$project_path/$CONFIGS/$PROJECTS"
  212. local project_projects_action_path="$project_path/$CONFIGS/$PROJECTS-$action"
  213. local arguments
  214. local path
  215. if [[ -f "$project_projects_action_path" ]]; then
  216. path="$project_projects_action_path"
  217. else
  218. path="$project_projects_path"
  219. fi
  220. # Multiple arguments can be read from the file.
  221. while read -r arguments; do
  222. eval "project_action_arguments $action $arguments"
  223. done < "$path"
  224. }
  225. project_path() {
  226. local project=$1
  227. local project_path="$root/$PROJECTS/$project"
  228. printf '%s\n' "$project_path"
  229. }
  230. project_sources_path() {
  231. local project=$1
  232. shift
  233. local repository=$1
  234. shift
  235. local sources_path
  236. local argument
  237. local path
  238. # Check downloaded and extracted sources first, using "$project."
  239. path="$root/$SOURCES/$project"
  240. for argument in "" "$@"
  241. do
  242. if [[ -n "$argument" ]]
  243. then
  244. path="$path-$argument"
  245. fi
  246. if ! directory_filled_check "$path"
  247. then
  248. continue
  249. fi
  250. sources_path=$path
  251. done
  252. if [[ -n "$sources_path" ]]
  253. then
  254. printf '%s\n' "$sources_path"
  255. return
  256. fi
  257. # Check downloaded sources then, using "$repository."
  258. path="$root/$SOURCES/$repository"
  259. if directory_filled_check "$path"
  260. then
  261. printf '%s\n' "$path"
  262. return
  263. fi
  264. # Check project sources finally, using "$project."
  265. path="$root/$PROJECTS/$project/$SOURCES"
  266. for argument in "" "$@"
  267. do
  268. if [[ -n "$argument" ]]
  269. then
  270. path="$path/$argument"
  271. fi
  272. if ! directory_filled_check "$path"
  273. then
  274. continue
  275. fi
  276. sources_path=$path
  277. done
  278. if [[ -n "$sources_path" ]]
  279. then
  280. printf '%s\n' "$sources_path"
  281. return
  282. fi
  283. }
  284. project_sources_directory_filled_check() {
  285. local project=$1
  286. shift
  287. local sources_path=$(project_sources_path "$project" "$@")
  288. test ! -z "$sources_path"
  289. }
  290. project_sources_directory_filled_error() {
  291. local project=$1
  292. shift
  293. local arguments="$*"
  294. local sources_path=$(project_sources_path "$project" "$@")
  295. if [[ -n "$sources_path" ]]
  296. then
  297. printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists"
  298. return 1
  299. else
  300. return 0
  301. fi
  302. }
  303. project_sources_directory_missing_empty_error() {
  304. local project=$1
  305. shift
  306. local arguments="$*"
  307. local sources_path=$(project_sources_path "$project" "$@")
  308. if [[ -z "$sources_path" ]]
  309. then
  310. printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty"
  311. return 1
  312. else
  313. return 0
  314. fi
  315. }
  316. project_sources_archive() {
  317. local project=$1
  318. shift
  319. local sources_archive
  320. local argument
  321. local path="$root/$SOURCES/$project"
  322. for argument in "" "$@"
  323. do
  324. if [[ -n "$argument" ]]
  325. then
  326. path="$path-$argument"
  327. fi
  328. local archive="$path.$ARCHIVE"
  329. if ! [[ -f "$archive" ]]
  330. then
  331. continue
  332. fi
  333. sources_archive=$archive
  334. done
  335. if [[ -n "$sources_archive" ]]
  336. then
  337. printf '%s\n' "$sources_archive"
  338. fi
  339. }
  340. project_sources_archive_extract() {
  341. local project=$1
  342. shift
  343. local arguments="$*"
  344. local archive=$(project_sources_archive "$project" "$@")
  345. local destination=$(dirname "$archive")
  346. printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})"
  347. file_verification_check "$archive"
  348. archive_extract "$archive" "$destination"
  349. }
  350. project_sources_archive_update() {
  351. local project=$1
  352. shift
  353. local arguments="$*"
  354. local repository=$project
  355. local sources_path=$(project_sources_path "$project" "$repository" "$@")
  356. local archive=$(project_sources_archive "$project" "$@")
  357. local destination=$(dirname "$archive")
  358. if [[ -d "$sources_path" ]]
  359. then
  360. rm -rf "$sources_path"
  361. fi
  362. printf '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})"
  363. file_verification_check "$archive"
  364. archive_extract "$archive" "$destination"
  365. }
  366. project_sources_archive_missing_error() {
  367. local project=$1
  368. shift
  369. local arguments="$*"
  370. local archive=$(project_sources_archive "$project" "$@")
  371. if [[ -z "$archive" ]] || ! [[ -f "$archive" ]]
  372. then
  373. printf 1>&2 '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})"
  374. return 1
  375. else
  376. return 0
  377. fi
  378. }
  379. project_sources_archive_missing_check() {
  380. local project=$1
  381. shift
  382. local archive=$(project_sources_archive "$project" "$@")
  383. if [[ -z "$archive" ]] || ! [[ -f "$archive" ]]
  384. then
  385. return 0
  386. else
  387. return 1
  388. fi
  389. }
  390. project_sources_prepare() {
  391. local project="$1"
  392. shift
  393. project_sources_prepare_blobs "$project" "$@"
  394. project_sources_prepare_patch "$project" "$@"
  395. }
  396. project_sources_prepare_blobs() {
  397. local project=$1
  398. shift
  399. local sources_path=$(project_sources_path "$project" "$project" "$@")
  400. local blobs_path=$(project_blobs_path "$project" "$@")
  401. local blobs_ignore_path=$(project_blobs_ignore_path "$project" "$@")
  402. if ! [[ -f $blobs_path ]]; then
  403. return 0
  404. fi
  405. (
  406. cd "$sources_path" || exit 1
  407. while IFS= read -r blob; do
  408. rm -f -- "$blob"
  409. done < <(comm -23 "$blobs_path" "$blobs_ignore_path")
  410. )
  411. }
  412. project_sources_prepare_patch() {
  413. local project="$1"
  414. shift
  415. local argument
  416. local path
  417. for argument in "$@"; do
  418. if [[ -z $path ]]; then
  419. path=$argument
  420. else
  421. path=$path/$argument
  422. fi
  423. done
  424. if [[ -n $project ]]; then
  425. project_sources_patch_recursive "$project" "$path"
  426. fi
  427. }
  428. project_sources_prepare_check() {
  429. local project=$1
  430. shift
  431. local sources_path=$(project_sources_path "$project" "$project" "$@")
  432. directory_filled_check "$sources_path"
  433. }
  434. project_sources_patch_recursive() {
  435. local project=$1
  436. local path=$2
  437. local project_path=$(project_path "$project")
  438. local sources_path=$(project_sources_path "$project" "$project" "$@")
  439. local patches_path=$project_path/$PATCHES/$path
  440. if ! [[ -d $project_path/$PATCHES ]]; then
  441. return 0
  442. fi
  443. for patch in "$patches_path"/[!.]*.@(patch|diff); do
  444. project_sources_patch "$sources_path" "$patch" || return 1
  445. done
  446. if [[ -n $path && $path != . ]]; then
  447. project_sources_patch_recursive "$project" "$(dirname "$path")"
  448. fi
  449. }
  450. project_sources_patch() {
  451. local sources_path=$1
  452. local patch_path=$2
  453. if diff_patch_check "$sources_path" "$patch_path"; then
  454. diff_patch "$sources_path" "$patch_path"
  455. else
  456. return 1
  457. fi
  458. }
  459. project_blobs_path() {
  460. local project=$1
  461. shift
  462. local project_path=$(project_path "$project")
  463. local configs_path="$project_path/$CONFIGS"
  464. local argument
  465. local path
  466. for argument in "" "$@"
  467. do
  468. if [[ -n "$argument" ]]
  469. then
  470. if [[ -z "$path" ]]
  471. then
  472. path="$argument"
  473. else
  474. path="$path/$argument"
  475. fi
  476. fi
  477. local blobs_path="$configs_path/$path/$BLOBS"
  478. if [[ -f "$blobs_path" ]]
  479. then
  480. printf '%s\n' "$blobs_path"
  481. return
  482. fi
  483. done
  484. printf '%s\n' "$blobs_path"
  485. }
  486. project_blobs_ignore_path() {
  487. local project=$1
  488. shift
  489. local project_path=$(project_path "$project")
  490. local configs_path="$project_path/$CONFIGS"
  491. local argument
  492. local path
  493. for argument in "" "$@"
  494. do
  495. if [[ -n "$argument" ]]
  496. then
  497. if [[ -z "$path" ]]
  498. then
  499. path="$argument"
  500. else
  501. path="$path/$argument"
  502. fi
  503. fi
  504. blobs_ignore_path="$configs_path/$path/$BLOBS_IGNORE"
  505. if [[ -f "$blobs_ignore_path" ]]
  506. then
  507. printf '%s\n' "$blobs_ignore_path"
  508. return
  509. fi
  510. done
  511. }
  512. project_arguments_targets() {
  513. local project=$1
  514. shift
  515. local project_path=$(project_path "$project")
  516. local targets_path="$project_path/$CONFIGS"
  517. local argument
  518. for argument in "$@"
  519. do
  520. targets_path="$targets_path/$argument"
  521. done
  522. targets_path="$targets_path/$TARGETS"
  523. if [[ -f "$targets_path" ]]
  524. then
  525. cat "$targets_path"
  526. fi
  527. }
  528. project_usage_actions() {
  529. local project="$1"
  530. shift
  531. printf '\n%s\n' 'Generic actions:'
  532. (
  533. for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do
  534. if function_check "$action"; then
  535. printf '%s\n' " $action"
  536. fi
  537. done
  538. )
  539. if [[ "$#" -gt 0 ]]; then
  540. printf '\n%s\n' 'Specific actions:'
  541. (
  542. for action in "$@"; do
  543. printf '%s\n' " $action"
  544. done
  545. )
  546. fi
  547. }
  548. project_usage_arguments() {
  549. local project="$1"
  550. shift
  551. printf '\n%s\n' 'Arguments:'
  552. project_usage_arguments_recursive "$project" ' ' "$@"
  553. }
  554. project_usage_arguments_recursive() {
  555. local project="$1"
  556. shift
  557. local spacing="$1"
  558. shift
  559. local action_helper_arguments
  560. local argument
  561. action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")"
  562. if [[ -n "$action_helper_arguments" ]]; then
  563. for argument in $action_helper_arguments; do
  564. printf '%s\n' "$spacing$argument"
  565. project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument"
  566. done
  567. fi
  568. }
  569. project_download_git() {
  570. local project=$1
  571. shift
  572. local repository=$1
  573. shift
  574. local urls=$1
  575. shift
  576. requirements "git"
  577. if ! git_project_check "$repository"
  578. then
  579. project_sources_directory_filled_error "$project" "$repository" "$@"
  580. git_project_clone "$repository" "$urls"
  581. fi
  582. git_project_prepare "$project" "$repository" "$@"
  583. }
  584. project_download_check_git() {
  585. local project=$1
  586. shift
  587. local repository=$1
  588. shift
  589. requirements "git"
  590. git_project_check "$repository"
  591. git_project_prepare_check "$project" "$repository" "$@"
  592. }
  593. project_download_archive() {
  594. local project="$1"
  595. shift
  596. local archive_uri="$1"
  597. shift
  598. local archive_dsig_uri="$1"
  599. local archive="${archive_uri##*/}"
  600. local compress_fmt="${archive##*.tar}"
  601. local directory_prefix="$root/$SOURCES"
  602. local archive_path="$root/$SOURCES/$archive"
  603. local sources_path="$root/$SOURCES/$project"
  604. if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then
  605. ARCHIVE="tar$compress_fmt"
  606. fi
  607. # TODO: Split this code block into separate functions
  608. # Archive verification will be included at that point in time
  609. if ! project_sources_directory_filled_check "$project"; then
  610. download_wrapper "$directory_prefix" "$archive_uri" "$archive_dsig_uri"
  611. archive_extract "$archive_path" "$directory_prefix"
  612. mv "${archive_path%.tar*}" "$sources_path"
  613. fi
  614. project_sources_prepare "$project"
  615. }
  616. project_download_check_archive() {
  617. local project="$1"
  618. local sources_path="$2"
  619. # TODO: Write the following function
  620. #project_sources_archive_extract_check "$project" "$sources_path"
  621. }
  622. project_extract() {
  623. local project=$1
  624. shift
  625. local repository=$project
  626. if ! project_sources_directory_filled_check "$project" "$repository" "$@"
  627. then
  628. project_sources_archive_missing_error "$project" "$@" || return 1
  629. project_sources_archive_extract "$project" "$@"
  630. fi
  631. }
  632. project_extract_check() {
  633. local project=$1
  634. shift
  635. local repository=$project
  636. project_sources_directory_filled_check "$project" "$repository" "$@"
  637. }
  638. project_update_git() {
  639. local project=$1
  640. shift
  641. local repository=$1
  642. shift
  643. requirements "git"
  644. project_sources_directory_missing_empty_error "$project" "$repository" "$@"
  645. if git_project_check "$repository"
  646. then
  647. git_project_update "$project" "$repository" "$@"
  648. else
  649. if ! project_sources_archive_missing_check "$project" "$@"
  650. then
  651. project_sources_archive_update "$project" "$@"
  652. fi
  653. fi
  654. }
  655. project_update_check_git() {
  656. local project=$1
  657. shift
  658. local repository=$1
  659. shift
  660. requirements "git"
  661. if ! git_project_check "$repository"
  662. then
  663. # Git repository should always be updated (even if upstream didn't progress).
  664. # For instance, this is useful for testing new versions of patches without changing revision.
  665. return 1
  666. else
  667. project_sources_archive_missing_check "$project" "$@"
  668. fi
  669. }
  670. project_build_check() {
  671. local project=$1
  672. shift
  673. local project_path=$(project_path "$project")
  674. local build_path=$(project_build_path "$project" "$@")
  675. local source_file_path
  676. local argument
  677. local rule
  678. local path
  679. for argument in "" "$@"
  680. do
  681. if [[ -n "$argument" ]]
  682. then
  683. if [[ -z "$path" ]]
  684. then
  685. path="$argument"
  686. else
  687. path="$path/$argument"
  688. fi
  689. fi
  690. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  691. if ! [[ -f "$configs_install_path" ]]
  692. then
  693. continue
  694. fi
  695. while read -r rule
  696. do
  697. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  698. source_path="$build_path/$source"
  699. # Source may contain a wildcard.
  700. path_wildcard_expand "$source_path" | while read -r source_file_path
  701. do
  702. if ! [[ -f "$source_file_path" ]] && ! [[ -d "$source_file_path" ]]
  703. then
  704. false
  705. fi
  706. done
  707. done < "$configs_install_path"
  708. done
  709. }
  710. project_build_path() {
  711. local project=$1
  712. shift
  713. local build_path="$root/$BUILD/$project"
  714. local argument
  715. for argument in "$@"
  716. do
  717. build_path="$build_path-$argument"
  718. done
  719. printf '%s\n' "$build_path"
  720. }
  721. project_build_directory_missing_empty_error() {
  722. local project=$1
  723. shift
  724. local arguments="$*"
  725. local build_path=$(project_build_path "$project" "$@")
  726. if ! directory_filled_check "$build_path"
  727. then
  728. printf 1>&2 '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty"
  729. return 1
  730. else
  731. return 0
  732. fi
  733. }
  734. project_install() {
  735. local project=$1
  736. shift
  737. local project_path=$(project_path "$project")
  738. local build_path=$(project_build_path "$project" "$@")
  739. local install_path=$(project_install_path "$project" "$@")
  740. local source_file_path
  741. local argument
  742. local rule
  743. local path
  744. # Install built files first.
  745. for argument in "" "$@"
  746. do
  747. if [[ -n "$argument" ]]
  748. then
  749. if [[ -z "$path" ]]
  750. then
  751. path="$argument"
  752. else
  753. path="$path/$argument"
  754. fi
  755. fi
  756. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  757. if ! [[ -f "$configs_install_path" ]]
  758. then
  759. continue
  760. fi
  761. project_build_directory_missing_empty_error "$project" "$@"
  762. while read -r rule
  763. do
  764. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  765. source_path="$build_path/$source"
  766. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  767. destination_path="$install_path/$destination"
  768. destination_directory_path=$(dirname "$destination_path")
  769. mkdir -p "$destination_directory_path"
  770. # Source may contain a wildcard.
  771. path_wildcard_expand "$source_path" | while read -r source_file_path
  772. do
  773. cp -rT "$source_file_path" "$destination_path"
  774. done
  775. done < "$configs_install_path"
  776. done
  777. path=""
  778. # Install install files then.
  779. for argument in "" "$@"
  780. do
  781. if [[ -n "$argument" ]]
  782. then
  783. if [[ -z "$path" ]]
  784. then
  785. path="$argument"
  786. else
  787. path="$path/$argument"
  788. fi
  789. fi
  790. install_install_path="$project_path/$INSTALL/$path/$INSTALL"
  791. if ! [[ -f "$install_install_path" ]]
  792. then
  793. continue
  794. fi
  795. while read -r rule
  796. do
  797. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  798. source_path="$project_path/$INSTALL/$path/$source"
  799. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  800. destination_path="$install_path/$destination"
  801. destination_directory_path=$(dirname "$destination_path")
  802. mkdir -p "$destination_directory_path"
  803. # Source may contain a wildcard.
  804. path_wildcard_expand "$source_path" | while read -r source_file_path
  805. do
  806. cp -rT "$source_file_path" "$destination_path"
  807. done
  808. done < "$install_install_path"
  809. done
  810. }
  811. project_install_check() {
  812. local project=$1
  813. shift
  814. local project_path=$(project_path "$project")
  815. local build_path=$(project_build_path "$project" "$@")
  816. local install_path=$(project_install_path "$project" "$@")
  817. local argument
  818. local rule
  819. local path
  820. # Install built files first.
  821. for argument in "" "$@"
  822. do
  823. if [[ -n "$argument" ]]
  824. then
  825. if [[ -z "$path" ]]
  826. then
  827. path="$argument"
  828. else
  829. path="$path/$argument"
  830. fi
  831. fi
  832. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  833. if ! [[ -f "$configs_install_path" ]]
  834. then
  835. continue
  836. fi
  837. project_build_directory_missing_empty_error "$project" "$@"
  838. while read -r rule
  839. do
  840. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  841. destination_path="$install_path/$destination"
  842. if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]]
  843. then
  844. false
  845. fi
  846. done < "$configs_install_path"
  847. done
  848. path=""
  849. # Install install files then.
  850. for argument in "" "$@"
  851. do
  852. if [[ -n "$argument" ]]
  853. then
  854. if [[ -z "$path" ]]
  855. then
  856. path="$argument"
  857. else
  858. path="$path/$argument"
  859. fi
  860. fi
  861. install_install_path="$project_path/$INSTALL/$path/$INSTALL"
  862. if ! [[ -f "$install_install_path" ]]
  863. then
  864. continue
  865. fi
  866. while read -r rule
  867. do
  868. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  869. destination_path="$install_path/$destination"
  870. if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]]
  871. then
  872. false
  873. fi
  874. done < "$install_install_path"
  875. done
  876. }
  877. project_install_path() {
  878. local project=$1
  879. shift
  880. local install_path="$root/$INSTALL/$project"
  881. local argument
  882. for argument in "$@"
  883. do
  884. install_path="$install_path-$argument"
  885. done
  886. printf '%s\n' "$install_path"
  887. }
  888. project_install_directory_missing_empty_error() {
  889. local project=$1
  890. shift
  891. local arguments="$*"
  892. local install_path=$(project_install_path "$project" "$@")
  893. if ! directory_filled_check "$install_path"
  894. then
  895. printf 1>&2 '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty"
  896. return 1
  897. else
  898. return 0
  899. fi
  900. }
  901. project_release_path() {
  902. local project=$1
  903. shift
  904. local prefix=$1
  905. local release_path="$root/$RELEASE/$prefix"
  906. # Special care for tools and systems, that depend on the host arch.
  907. if [[ "$prefix" = "$SYSTEMS" ]] || [[ "$prefix" = "$TOOLS" ]]
  908. then
  909. local machine=$(uname -m)
  910. release_path="$release_path/$machine/$project"
  911. else
  912. release_path="$release_path/$project"
  913. fi
  914. printf '%s\n' "$release_path"
  915. }
  916. project_release_archive_path() {
  917. local project=$1
  918. shift
  919. local prefix=$1
  920. shift
  921. local release_path=$(project_release_path "$project" "$prefix")
  922. local argument
  923. local path="$project"
  924. for argument in "$@"
  925. do
  926. path="$path-$argument"
  927. done
  928. local archive_path="$release_path/$path.$ARCHIVE"
  929. printf '%s\n' "$archive_path"
  930. }
  931. project_release_rootfs_path() {
  932. local project=$1
  933. shift
  934. local prefix=$1
  935. shift
  936. local release_path=$(project_release_path "$project" "$prefix")
  937. local argument
  938. local path="$project"
  939. for argument in "$@"
  940. do
  941. path="$path-$argument"
  942. done
  943. local rootfs_path="$release_path/$path.$ARCHIVE"
  944. printf '%s\n' "$rootfs_path"
  945. }
  946. project_release_sources_archive_path() {
  947. local project=$1
  948. shift
  949. local repository="$project"
  950. local sources_path="$(project_sources_path "$project" "$repository" "$@")"
  951. local archive_path="$root/$RELEASE/$SOURCES/$project/${sources_path##*/}.$ARCHIVE"
  952. printf '%s\n' "$archive_path"
  953. }
  954. project_release_sources_archive_create() {
  955. local project=$1
  956. shift
  957. local arguments="$*"
  958. local repository=$project
  959. local archive_path=$(project_release_sources_archive_path "$project" "$@")
  960. local sources_path=$(project_sources_path "$project" "$repository" "$@")
  961. printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})"
  962. archive_create "$archive_path" "$sources_path"
  963. file_verification_create "$archive_path"
  964. }
  965. project_release_sources_archive_exists_check() {
  966. local project=$1
  967. shift
  968. local archive_path=$(project_release_sources_archive_path "$project" "$@")
  969. if [[ -z "$archive_path" ]] || ! [[ -f "$archive_path" ]]
  970. then
  971. return 1
  972. else
  973. return 0
  974. fi
  975. }
  976. project_release_sources_git() {
  977. local project=$1
  978. shift
  979. local repository=$1
  980. shift
  981. requirements "git"
  982. project_sources_directory_missing_empty_error "$project" "$repository" "$@"
  983. if git_project_check "$repository"
  984. then
  985. if ! git_project_release_check "$project" "$repository" "$@"
  986. then
  987. git_project_release "$project" "$repository" "$@"
  988. fi
  989. else
  990. if ! project_release_sources_archive_exists_check "$project" "$@"
  991. then
  992. project_release_sources_archive_create "$project" "$@"
  993. fi
  994. fi
  995. }
  996. project_release_check_sources_git() {
  997. local project=$1
  998. shift
  999. local repository=$1
  1000. shift
  1001. requirements "git"
  1002. if git_project_check "$repository"
  1003. then
  1004. git_project_release_check "$project" "$repository" "$@"
  1005. else
  1006. project_release_sources_archive_exists_check "$project" "$@"
  1007. fi
  1008. }
  1009. project_release_install() {
  1010. local project=$1
  1011. shift
  1012. local prefix=$1
  1013. shift
  1014. local install_path=$(project_install_path "$project" "$@")
  1015. local release_path=$(project_release_path "$project" "$prefix")
  1016. local directory_path
  1017. local path
  1018. project_install_directory_missing_empty_error "$project" "$@"
  1019. local files=$(find "$install_path" -type f || true)
  1020. local file
  1021. printf '%s\n' "$files" | while read -r file
  1022. do
  1023. path="$release_path/$file"
  1024. directory_path=$(dirname "$path")
  1025. mkdir -p "$directory_path"
  1026. cp "$install_path/$file" "$path"
  1027. file_verification_create "$path"
  1028. done
  1029. }
  1030. project_release_install_check() {
  1031. local project=$1
  1032. shift
  1033. local prefix=$1
  1034. shift
  1035. local install_path=$(project_install_path "$project" "$@")
  1036. local release_path=$(project_release_path "$project" "$prefix")
  1037. local path
  1038. project_install_directory_missing_empty_error "$project" "$@"
  1039. local files=$(find "$install_path" -type f || true)
  1040. local file
  1041. printf '%s\n' "$files" | while read -r file
  1042. do
  1043. path="$release_path/$file"
  1044. file_exists_check "$path"
  1045. done
  1046. }
  1047. project_release_install_archive() {
  1048. local project=$1
  1049. shift
  1050. local prefix=$1
  1051. shift
  1052. project_install_directory_missing_empty_error "$project" "$@"
  1053. project_release_install_archive_create "$project" "$prefix" "$@"
  1054. }
  1055. project_release_install_archive_check() {
  1056. local project=$1
  1057. shift
  1058. project_release_install_archive_exists_check "$project" "$@"
  1059. }
  1060. project_release_install_archive_create() {
  1061. local project=$1
  1062. shift
  1063. local prefix=$1
  1064. shift
  1065. local arguments="$*"
  1066. local install_path=$(project_install_path "$project" "$@")
  1067. local archive_path=$(project_release_archive_path "$project" "$prefix" "$@")
  1068. printf '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})"
  1069. archive_create "$archive_path" "$install_path"
  1070. file_verification_create "$archive_path"
  1071. }
  1072. project_release_install_archive_exists_check() {
  1073. local project=$1
  1074. shift
  1075. local prefix=$1
  1076. shift
  1077. local archive_path=$(project_release_archive_path "$project" "$prefix" "$@")
  1078. file_exists_check "$archive_path"
  1079. }
  1080. project_release_install_rootfs() {
  1081. local project=$1
  1082. shift
  1083. local prefix=$1
  1084. shift
  1085. project_install_directory_missing_empty_error "$project" "$@"
  1086. if ! project_release_install_rootfs_exists_check "$project" "$prefix" "$@"
  1087. then
  1088. project_release_install_rootfs_create "$project" "$prefix" "$@"
  1089. fi
  1090. }
  1091. project_release_install_rootfs_check() {
  1092. local project=$1
  1093. shift
  1094. project_release_install_rootfs_exists_check "$project" "$@"
  1095. }
  1096. project_release_install_rootfs_create() {
  1097. local project=$1
  1098. shift
  1099. local prefix=$1
  1100. shift
  1101. local arguments="$*"
  1102. local install_path=$(project_install_path "$project" "$@")
  1103. local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@")
  1104. printf '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})"
  1105. rootfs_create "$rootfs_path" "$install_path"
  1106. file_verification_create "$rootfs_path"
  1107. }
  1108. project_release_install_rootfs_exists_check() {
  1109. local project=$1
  1110. shift
  1111. local prefix=$1
  1112. shift
  1113. local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@")
  1114. file_exists_check "$rootfs_path"
  1115. }
  1116. project_clean() {
  1117. local project=$1
  1118. shift
  1119. project_clean_build "$project" "$@"
  1120. project_clean_install "$project" "$@"
  1121. project_clean_release "$project" "$@"
  1122. }
  1123. project_clean_build() {
  1124. local project=$1
  1125. shift
  1126. local build_path=$(project_build_path "$project" "$@")
  1127. rm -rf "$build_path"
  1128. }
  1129. project_clean_install() {
  1130. local project=$1
  1131. shift
  1132. local install_path=$(project_install_path "$project" "$@")
  1133. rm -rf "$install_path"
  1134. }
  1135. project_clean_release() {
  1136. local project=$1
  1137. shift
  1138. local prefix
  1139. for prefix in "$SOURCES" "$SYSTEMS" "$IMAGES" "$TOOLS" "$DOCS"
  1140. do
  1141. local release_path=$(project_release_path "$project" "$prefix")
  1142. rm -rf "$release_path"
  1143. done
  1144. }
  1145. project_clean_rootfs() {
  1146. local project=$1
  1147. shift
  1148. project_clean_build "$project" "$@"
  1149. project_clean_rootfs_install "$project" "$@"
  1150. project_clean_release "$project" "$@"
  1151. }
  1152. project_clean_rootfs_install() {
  1153. local project=$1
  1154. shift
  1155. local install_path=$(project_install_path "$project" "$@")
  1156. execute_root rm -rf "$install_path"
  1157. }
  1158. project_file_path() {
  1159. local project=$1
  1160. shift
  1161. local directory=$1
  1162. shift
  1163. local file=$1
  1164. shift
  1165. local project_path=$(project_path "$project")
  1166. local path="$project_path/$directory"
  1167. local argument
  1168. local file_path
  1169. for argument in "" "$@"
  1170. do
  1171. if [[ -n "$argument" ]]
  1172. then
  1173. path="$path/$argument"
  1174. fi
  1175. if ! [[ -f "$path/$file" ]]
  1176. then
  1177. continue
  1178. fi
  1179. file_path="$path/$file"
  1180. break
  1181. done
  1182. if [[ -z "$file_path" ]]
  1183. then
  1184. return 1
  1185. fi
  1186. printf '%s\n' "$file_path"
  1187. }
  1188. project_file_test() {
  1189. local file_path=$(project_file_path "$@")
  1190. test -f "$file_path"
  1191. }
  1192. project_file_contents() {
  1193. local file_path=$(project_file_path "$@")
  1194. if [[ -f "$file_path" ]]
  1195. then
  1196. cat "$file_path"
  1197. fi
  1198. }
  1199. project_file_contents_herit() {
  1200. local project=$1
  1201. shift
  1202. local directory=$1
  1203. shift
  1204. local file=$1
  1205. shift
  1206. local project_path=$(project_path "$project")
  1207. local path="$project_path/$directory"
  1208. local argument
  1209. local file_path
  1210. for argument in "" "$@"
  1211. do
  1212. if [[ -n "$argument" ]]
  1213. then
  1214. path="$path/$argument"
  1215. fi
  1216. file_path="$path/$file"
  1217. if ! [[ -f "$file_path" ]]
  1218. then
  1219. continue
  1220. fi
  1221. cat "$file_path"
  1222. done
  1223. }