project 27 KB

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