project 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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. done
  1084. if [[ -z "$file_path" ]]
  1085. then
  1086. return 1
  1087. fi
  1088. printf '%s\n' "$file_path"
  1089. }
  1090. project_file_test() {
  1091. local file_path=$(project_file_path "$@")
  1092. test -f "$file_path"
  1093. }
  1094. project_file_contents() {
  1095. local file_path=$(project_file_path "$@")
  1096. if [[ -f "$file_path" ]]
  1097. then
  1098. cat "$file_path"
  1099. fi
  1100. }
  1101. project_file_contents_herit() {
  1102. local project=$1
  1103. shift
  1104. local directory=$1
  1105. shift
  1106. local file=$1
  1107. shift
  1108. local project_path=$(project_path "$project")
  1109. local path="$project_path/$directory"
  1110. local argument
  1111. local file_path
  1112. for argument in "" "$@"
  1113. do
  1114. if [[ -n "$argument" ]]
  1115. then
  1116. path="$path/$argument"
  1117. fi
  1118. file_path="$path/$file"
  1119. if ! [[ -f "$file_path" ]]
  1120. then
  1121. continue
  1122. fi
  1123. cat "$file_path"
  1124. done
  1125. }