project 26 KB

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