project 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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. local sources_path="$2"
  393. # Not implemented yet / May end up not being needed
  394. #project_sources_prepare_blobs
  395. project_sources_prepare_patch "$project" "$sources_path" "$@"
  396. }
  397. project_sources_prepare_patch() {
  398. local project="$1"
  399. local sources_path="$2"
  400. local project_path="$(project_path "$project")"
  401. local patches_path="$project_path/$PATCHES"
  402. for patch in "$patches_path"/[!.]*.@(patch|diff); do
  403. diff_patch "$sources_path" "$patch"
  404. done
  405. }
  406. project_blobs_path() {
  407. local project=$1
  408. shift
  409. local project_path=$(project_path "$project")
  410. local configs_path="$project_path/$CONFIGS"
  411. local argument
  412. local path
  413. for argument in "" "$@"
  414. do
  415. if [[ -n "$argument" ]]
  416. then
  417. if [[ -z "$path" ]]
  418. then
  419. path="$argument"
  420. else
  421. path="$path/$argument"
  422. fi
  423. fi
  424. local blobs_path="$configs_path/$path/$BLOBS"
  425. if [[ -f "$blobs_path" ]]
  426. then
  427. printf '%s\n' "$blobs_path"
  428. return
  429. fi
  430. done
  431. printf '%s\n' "$blobs_path"
  432. }
  433. project_blobs_ignore_path() {
  434. local project=$1
  435. shift
  436. local project_path=$(project_path "$project")
  437. local configs_path="$project_path/$CONFIGS"
  438. local argument
  439. local path
  440. for argument in "" "$@"
  441. do
  442. if [[ -n "$argument" ]]
  443. then
  444. if [[ -z "$path" ]]
  445. then
  446. path="$argument"
  447. else
  448. path="$path/$argument"
  449. fi
  450. fi
  451. blobs_ignore_path="$configs_path/$path/$BLOBS_IGNORE"
  452. if [[ -f "$blobs_ignore_path" ]]
  453. then
  454. printf '%s\n' "$blobs_ignore_path"
  455. return
  456. fi
  457. done
  458. }
  459. project_arguments_targets() {
  460. local project=$1
  461. shift
  462. local project_path=$(project_path "$project")
  463. local targets_path="$project_path/$CONFIGS"
  464. local argument
  465. for argument in "$@"
  466. do
  467. targets_path="$targets_path/$argument"
  468. done
  469. targets_path="$targets_path/$TARGETS"
  470. if [[ -f "$targets_path" ]]
  471. then
  472. cat "$targets_path"
  473. fi
  474. }
  475. project_usage_actions() {
  476. local project="$1"
  477. shift
  478. printf '\n%s\n' 'Generic actions:'
  479. (
  480. for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do
  481. if function_check "$action"; then
  482. printf '%s\n' " $action"
  483. fi
  484. done
  485. )
  486. if [[ "$#" -gt 0 ]]; then
  487. printf '\n%s\n' 'Specific actions:'
  488. (
  489. for action in "$@"; do
  490. printf '%s\n' " $action"
  491. done
  492. )
  493. fi
  494. }
  495. project_usage_arguments() {
  496. local project="$1"
  497. shift
  498. printf '\n%s\n' 'Arguments:'
  499. project_usage_arguments_recursive "$project" ' ' "$@"
  500. }
  501. project_usage_arguments_recursive() {
  502. local project="$1"
  503. shift
  504. local spacing="$1"
  505. shift
  506. local action_helper_arguments
  507. local argument
  508. action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@")"
  509. if [[ -n "$action_helper_arguments" ]]; then
  510. for argument in $action_helper_arguments; do
  511. printf '%s\n' "$spacing$argument"
  512. project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument"
  513. done
  514. fi
  515. }
  516. project_download_git() {
  517. local project=$1
  518. shift
  519. local repository=$1
  520. shift
  521. local urls=$1
  522. shift
  523. requirements "git"
  524. if ! git_project_check "$repository"
  525. then
  526. project_sources_directory_filled_error "$project" "$repository" "$@"
  527. git_project_clone "$repository" "$urls"
  528. fi
  529. git_project_prepare "$project" "$repository" "$@"
  530. }
  531. project_download_check_git() {
  532. local project=$1
  533. shift
  534. local repository=$1
  535. shift
  536. requirements "git"
  537. git_project_check "$repository"
  538. git_project_prepare_check "$project" "$repository" "$@"
  539. }
  540. project_download_archive() {
  541. local project="$1"
  542. shift
  543. local archive_uri="$1"
  544. shift
  545. local archive_dsig_uri="$1"
  546. local archive="${archive_uri##*/}"
  547. local compress_fmt="${archive##*.tar}"
  548. local directory_prefix="$root/$SOURCES"
  549. local archive_path="$root/$SOURCES/$archive"
  550. local sources_path="$root/$SOURCES/$project"
  551. if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then
  552. ARCHIVE="tar$compress_fmt"
  553. fi
  554. # TODO: Split this code block into separate functions
  555. # Archive verification will be included at that point in time
  556. if ! project_sources_directory_filled_check "$project"; then
  557. download_wrapper "$directory_prefix" "$archive_uri" "$archive_dsig_uri"
  558. archive_extract "$archive_path" "$directory_prefix"
  559. mv "${archive_path%.tar*}" "$sources_path"
  560. fi
  561. # Patch the source, if necessary
  562. project_sources_prepare "$project" "$sources_path"
  563. }
  564. project_download_check_archive() {
  565. local project="$1"
  566. local sources_path="$2"
  567. # TODO: Write the following function
  568. #project_sources_archive_extract_check "$project" "$sources_path"
  569. }
  570. project_extract() {
  571. local project=$1
  572. shift
  573. local repository=$project
  574. if ! project_sources_directory_filled_check "$project" "$repository" "$@"
  575. then
  576. project_sources_archive_missing_error "$project" "$@" || return 1
  577. project_sources_archive_extract "$project" "$@"
  578. fi
  579. }
  580. project_extract_check() {
  581. local project=$1
  582. shift
  583. local repository=$project
  584. project_sources_directory_filled_check "$project" "$repository" "$@"
  585. }
  586. project_update_git() {
  587. local project=$1
  588. shift
  589. local repository=$1
  590. shift
  591. requirements "git"
  592. project_sources_directory_missing_empty_error "$project" "$repository" "$@"
  593. if git_project_check "$repository"
  594. then
  595. git_project_update "$project" "$repository" "$@"
  596. else
  597. if ! project_sources_archive_missing_check "$project" "$@"
  598. then
  599. project_sources_archive_update "$project" "$@"
  600. fi
  601. fi
  602. }
  603. project_update_check_git() {
  604. local project=$1
  605. shift
  606. local repository=$1
  607. shift
  608. requirements "git"
  609. if ! git_project_check "$repository"
  610. then
  611. # Git repository should always be updated (even if upstream didn't progress).
  612. # For instance, this is useful for testing new versions of patches without changing revision.
  613. return 1
  614. else
  615. project_sources_archive_missing_check "$project" "$@"
  616. fi
  617. }
  618. project_build_check() {
  619. local project=$1
  620. shift
  621. local project_path=$(project_path "$project")
  622. local build_path=$(project_build_path "$project" "$@")
  623. local source_file_path
  624. local argument
  625. local rule
  626. local path
  627. for argument in "" "$@"
  628. do
  629. if [[ -n "$argument" ]]
  630. then
  631. if [[ -z "$path" ]]
  632. then
  633. path="$argument"
  634. else
  635. path="$path/$argument"
  636. fi
  637. fi
  638. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  639. if ! [[ -f "$configs_install_path" ]]
  640. then
  641. continue
  642. fi
  643. while read -r rule
  644. do
  645. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  646. source_path="$build_path/$source"
  647. # Source may contain a wildcard.
  648. path_wildcard_expand "$source_path" | while read -r source_file_path
  649. do
  650. if ! [[ -f "$source_file_path" ]] && ! [[ -d "$source_file_path" ]]
  651. then
  652. false
  653. fi
  654. done
  655. done < "$configs_install_path"
  656. done
  657. }
  658. project_build_path() {
  659. local project=$1
  660. shift
  661. local build_path="$root/$BUILD/$project"
  662. local argument
  663. for argument in "$@"
  664. do
  665. build_path="$build_path-$argument"
  666. done
  667. printf '%s\n' "$build_path"
  668. }
  669. project_build_directory_missing_empty_error() {
  670. local project=$1
  671. shift
  672. local arguments="$*"
  673. local build_path=$(project_build_path "$project" "$@")
  674. if ! directory_filled_check "$build_path"
  675. then
  676. printf 1>&2 '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty"
  677. return 1
  678. else
  679. return 0
  680. fi
  681. }
  682. project_install() {
  683. local project=$1
  684. shift
  685. local project_path=$(project_path "$project")
  686. local build_path=$(project_build_path "$project" "$@")
  687. local install_path=$(project_install_path "$project" "$@")
  688. local source_file_path
  689. local argument
  690. local rule
  691. local path
  692. # Install built files first.
  693. for argument in "" "$@"
  694. do
  695. if [[ -n "$argument" ]]
  696. then
  697. if [[ -z "$path" ]]
  698. then
  699. path="$argument"
  700. else
  701. path="$path/$argument"
  702. fi
  703. fi
  704. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  705. if ! [[ -f "$configs_install_path" ]]
  706. then
  707. continue
  708. fi
  709. project_build_directory_missing_empty_error "$project" "$@"
  710. while read -r rule
  711. do
  712. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  713. source_path="$build_path/$source"
  714. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  715. destination_path="$install_path/$destination"
  716. destination_directory_path=$(dirname "$destination_path")
  717. mkdir -p "$destination_directory_path"
  718. # Source may contain a wildcard.
  719. path_wildcard_expand "$source_path" | while read -r source_file_path
  720. do
  721. cp -rT "$source_file_path" "$destination_path"
  722. done
  723. done < "$configs_install_path"
  724. done
  725. path=""
  726. # Install install files then.
  727. for argument in "" "$@"
  728. do
  729. if [[ -n "$argument" ]]
  730. then
  731. if [[ -z "$path" ]]
  732. then
  733. path="$argument"
  734. else
  735. path="$path/$argument"
  736. fi
  737. fi
  738. install_install_path="$project_path/$INSTALL/$path/$INSTALL"
  739. if ! [[ -f "$install_install_path" ]]
  740. then
  741. continue
  742. fi
  743. while read -r rule
  744. do
  745. source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
  746. source_path="$project_path/$INSTALL/$path/$source"
  747. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  748. destination_path="$install_path/$destination"
  749. destination_directory_path=$(dirname "$destination_path")
  750. mkdir -p "$destination_directory_path"
  751. # Source may contain a wildcard.
  752. path_wildcard_expand "$source_path" | while read -r source_file_path
  753. do
  754. cp -rT "$source_file_path" "$destination_path"
  755. done
  756. done < "$install_install_path"
  757. done
  758. }
  759. project_install_check() {
  760. local project=$1
  761. shift
  762. local project_path=$(project_path "$project")
  763. local build_path=$(project_build_path "$project" "$@")
  764. local install_path=$(project_install_path "$project" "$@")
  765. local argument
  766. local rule
  767. local path
  768. # Install built files first.
  769. for argument in "" "$@"
  770. do
  771. if [[ -n "$argument" ]]
  772. then
  773. if [[ -z "$path" ]]
  774. then
  775. path="$argument"
  776. else
  777. path="$path/$argument"
  778. fi
  779. fi
  780. configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"
  781. if ! [[ -f "$configs_install_path" ]]
  782. then
  783. continue
  784. fi
  785. project_build_directory_missing_empty_error "$project" "$@"
  786. while read -r rule
  787. do
  788. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  789. destination_path="$install_path/$destination"
  790. if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]]
  791. then
  792. false
  793. fi
  794. done < "$configs_install_path"
  795. done
  796. path=""
  797. # Install install files then.
  798. for argument in "" "$@"
  799. do
  800. if [[ -n "$argument" ]]
  801. then
  802. if [[ -z "$path" ]]
  803. then
  804. path="$argument"
  805. else
  806. path="$path/$argument"
  807. fi
  808. fi
  809. install_install_path="$project_path/$INSTALL/$path/$INSTALL"
  810. if ! [[ -f "$install_install_path" ]]
  811. then
  812. continue
  813. fi
  814. while read -r rule
  815. do
  816. destination=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\2/g")
  817. destination_path="$install_path/$destination"
  818. if ! [[ -f "$destination_path" ]] && ! [[ -d "$destination_path" ]]
  819. then
  820. false
  821. fi
  822. done < "$install_install_path"
  823. done
  824. }
  825. project_install_path() {
  826. local project=$1
  827. shift
  828. local install_path="$root/$INSTALL/$project"
  829. local argument
  830. for argument in "$@"
  831. do
  832. install_path="$install_path-$argument"
  833. done
  834. printf '%s\n' "$install_path"
  835. }
  836. project_install_directory_missing_empty_error() {
  837. local project=$1
  838. shift
  839. local arguments="$*"
  840. local install_path=$(project_install_path "$project" "$@")
  841. if ! directory_filled_check "$install_path"
  842. then
  843. printf 1>&2 '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty"
  844. return 1
  845. else
  846. return 0
  847. fi
  848. }
  849. project_release_path() {
  850. local project=$1
  851. shift
  852. local prefix=$1
  853. local release_path="$root/$RELEASE/$prefix"
  854. # Special care for tools and systems, that depend on the host arch.
  855. if [[ "$prefix" = "$SYSTEMS" ]] || [[ "$prefix" = "$TOOLS" ]]
  856. then
  857. local machine=$(uname -m)
  858. release_path="$release_path/$machine/$project"
  859. else
  860. release_path="$release_path/$project"
  861. fi
  862. printf '%s\n' "$release_path"
  863. }
  864. project_release_archive_path() {
  865. local project=$1
  866. shift
  867. local prefix=$1
  868. shift
  869. local release_path=$(project_release_path "$project" "$prefix")
  870. local argument
  871. local path="$project"
  872. for argument in "$@"
  873. do
  874. path="$path-$argument"
  875. done
  876. local archive_path="$release_path/$path.$ARCHIVE"
  877. printf '%s\n' "$archive_path"
  878. }
  879. project_release_rootfs_path() {
  880. local project=$1
  881. shift
  882. local prefix=$1
  883. shift
  884. local release_path=$(project_release_path "$project" "$prefix")
  885. local argument
  886. local path="$project"
  887. for argument in "$@"
  888. do
  889. path="$path-$argument"
  890. done
  891. local rootfs_path="$release_path/$path.$ARCHIVE"
  892. printf '%s\n' "$rootfs_path"
  893. }
  894. project_release_sources_archive_path() {
  895. local project=$1
  896. shift
  897. local repository="$project"
  898. local sources_path="$(project_sources_path "$project" "$repository" "$@")"
  899. local archive_path="$root/$RELEASE/$SOURCES/$project/${sources_path##*/}.$ARCHIVE"
  900. printf '%s\n' "$archive_path"
  901. }
  902. project_release_sources_archive_create() {
  903. local project=$1
  904. shift
  905. local arguments="$*"
  906. local repository=$project
  907. local archive_path=$(project_release_sources_archive_path "$project" "$@")
  908. local sources_path=$(project_sources_path "$project" "$repository" "$@")
  909. printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})"
  910. archive_create "$archive_path" "$sources_path"
  911. file_verification_create "$archive_path"
  912. }
  913. project_release_sources_archive_exists_check() {
  914. local project=$1
  915. shift
  916. local archive_path=$(project_release_sources_archive_path "$project" "$@")
  917. if [[ -z "$archive_path" ]] || ! [[ -f "$archive_path" ]]
  918. then
  919. return 1
  920. else
  921. return 0
  922. fi
  923. }
  924. project_release_sources_git() {
  925. local project=$1
  926. shift
  927. local repository=$1
  928. shift
  929. requirements "git"
  930. project_sources_directory_missing_empty_error "$project" "$repository" "$@"
  931. if git_project_check "$repository"
  932. then
  933. if ! git_project_release_check "$project" "$repository" "$@"
  934. then
  935. git_project_release "$project" "$repository" "$@"
  936. fi
  937. else
  938. if ! project_release_sources_archive_exists_check "$project" "$@"
  939. then
  940. project_release_sources_archive_create "$project" "$@"
  941. fi
  942. fi
  943. }
  944. project_release_check_sources_git() {
  945. local project=$1
  946. shift
  947. local repository=$1
  948. shift
  949. requirements "git"
  950. if git_project_check "$repository"
  951. then
  952. git_project_release_check "$project" "$repository" "$@"
  953. else
  954. project_release_sources_archive_exists_check "$project" "$@"
  955. fi
  956. }
  957. project_release_install() {
  958. local project=$1
  959. shift
  960. local prefix=$1
  961. shift
  962. local install_path=$(project_install_path "$project" "$@")
  963. local release_path=$(project_release_path "$project" "$prefix")
  964. local directory_path
  965. local path
  966. project_install_directory_missing_empty_error "$project" "$@"
  967. local files=$(find "$install_path" -type f || true)
  968. local file
  969. printf '%s\n' "$files" | while read -r file
  970. do
  971. path="$release_path/$file"
  972. directory_path=$(dirname "$path")
  973. mkdir -p "$directory_path"
  974. cp "$install_path/$file" "$path"
  975. file_verification_create "$path"
  976. done
  977. }
  978. project_release_install_check() {
  979. local project=$1
  980. shift
  981. local prefix=$1
  982. shift
  983. local install_path=$(project_install_path "$project" "$@")
  984. local release_path=$(project_release_path "$project" "$prefix")
  985. local path
  986. project_install_directory_missing_empty_error "$project" "$@"
  987. local files=$(find "$install_path" -type f || true)
  988. local file
  989. printf '%s\n' "$files" | while read -r file
  990. do
  991. path="$release_path/$file"
  992. file_exists_check "$path"
  993. done
  994. }
  995. project_release_install_archive() {
  996. local project=$1
  997. shift
  998. local prefix=$1
  999. shift
  1000. project_install_directory_missing_empty_error "$project" "$@"
  1001. project_release_install_archive_create "$project" "$prefix" "$@"
  1002. }
  1003. project_release_install_archive_check() {
  1004. local project=$1
  1005. shift
  1006. project_release_install_archive_exists_check "$project" "$@"
  1007. }
  1008. project_release_install_archive_create() {
  1009. local project=$1
  1010. shift
  1011. local prefix=$1
  1012. shift
  1013. local arguments="$*"
  1014. local install_path=$(project_install_path "$project" "$@")
  1015. local archive_path=$(project_release_archive_path "$project" "$prefix" "$@")
  1016. printf '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})"
  1017. archive_create "$archive_path" "$install_path"
  1018. file_verification_create "$archive_path"
  1019. }
  1020. project_release_install_archive_exists_check() {
  1021. local project=$1
  1022. shift
  1023. local prefix=$1
  1024. shift
  1025. local archive_path=$(project_release_archive_path "$project" "$prefix" "$@")
  1026. file_exists_check "$archive_path"
  1027. }
  1028. project_release_install_rootfs() {
  1029. local project=$1
  1030. shift
  1031. local prefix=$1
  1032. shift
  1033. project_install_directory_missing_empty_error "$project" "$@"
  1034. if ! project_release_install_rootfs_exists_check "$project" "$prefix" "$@"
  1035. then
  1036. project_release_install_rootfs_create "$project" "$prefix" "$@"
  1037. fi
  1038. }
  1039. project_release_install_rootfs_check() {
  1040. local project=$1
  1041. shift
  1042. project_release_install_rootfs_exists_check "$project" "$@"
  1043. }
  1044. project_release_install_rootfs_create() {
  1045. local project=$1
  1046. shift
  1047. local prefix=$1
  1048. shift
  1049. local arguments="$*"
  1050. local install_path=$(project_install_path "$project" "$@")
  1051. local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@")
  1052. printf '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})"
  1053. rootfs_create "$rootfs_path" "$install_path"
  1054. file_verification_create "$rootfs_path"
  1055. }
  1056. project_release_install_rootfs_exists_check() {
  1057. local project=$1
  1058. shift
  1059. local prefix=$1
  1060. shift
  1061. local rootfs_path=$(project_release_rootfs_path "$project" "$prefix" "$@")
  1062. file_exists_check "$rootfs_path"
  1063. }
  1064. project_clean() {
  1065. local project=$1
  1066. shift
  1067. project_clean_build "$project" "$@"
  1068. project_clean_install "$project" "$@"
  1069. project_clean_release "$project" "$@"
  1070. }
  1071. project_clean_build() {
  1072. local project=$1
  1073. shift
  1074. local build_path=$(project_build_path "$project" "$@")
  1075. rm -rf "$build_path"
  1076. }
  1077. project_clean_install() {
  1078. local project=$1
  1079. shift
  1080. local install_path=$(project_install_path "$project" "$@")
  1081. rm -rf "$install_path"
  1082. }
  1083. project_clean_release() {
  1084. local project=$1
  1085. shift
  1086. local prefix
  1087. for prefix in "$SOURCES" "$SYSTEMS" "$IMAGES" "$TOOLS" "$DOCS"
  1088. do
  1089. local release_path=$(project_release_path "$project" "$prefix")
  1090. rm -rf "$release_path"
  1091. done
  1092. }
  1093. project_clean_rootfs() {
  1094. local project=$1
  1095. shift
  1096. project_clean_build "$project" "$@"
  1097. project_clean_rootfs_install "$project" "$@"
  1098. project_clean_release "$project" "$@"
  1099. }
  1100. project_clean_rootfs_install() {
  1101. local project=$1
  1102. shift
  1103. local install_path=$(project_install_path "$project" "$@")
  1104. execute_root rm -rf "$install_path"
  1105. }
  1106. project_file_path() {
  1107. local project=$1
  1108. shift
  1109. local directory=$1
  1110. shift
  1111. local file=$1
  1112. shift
  1113. local project_path=$(project_path "$project")
  1114. local path="$project_path/$directory"
  1115. local argument
  1116. local file_path
  1117. for argument in "" "$@"
  1118. do
  1119. if [[ -n "$argument" ]]
  1120. then
  1121. path="$path/$argument"
  1122. fi
  1123. if ! [[ -f "$path/$file" ]]
  1124. then
  1125. continue
  1126. fi
  1127. file_path="$path/$file"
  1128. break
  1129. done
  1130. if [[ -z "$file_path" ]]
  1131. then
  1132. return 1
  1133. fi
  1134. printf '%s\n' "$file_path"
  1135. }
  1136. project_file_test() {
  1137. local file_path=$(project_file_path "$@")
  1138. test -f "$file_path"
  1139. }
  1140. project_file_contents() {
  1141. local file_path=$(project_file_path "$@")
  1142. if [[ -f "$file_path" ]]
  1143. then
  1144. cat "$file_path"
  1145. fi
  1146. }
  1147. project_file_contents_herit() {
  1148. local project=$1
  1149. shift
  1150. local directory=$1
  1151. shift
  1152. local file=$1
  1153. shift
  1154. local project_path=$(project_path "$project")
  1155. local path="$project_path/$directory"
  1156. local argument
  1157. local file_path
  1158. for argument in "" "$@"
  1159. do
  1160. if [[ -n "$argument" ]]
  1161. then
  1162. path="$path/$argument"
  1163. fi
  1164. file_path="$path/$file"
  1165. if ! [[ -f "$file_path" ]]
  1166. then
  1167. continue
  1168. fi
  1169. cat "$file_path"
  1170. done
  1171. }