project 28 KB

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