taggedrules.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #
  2. # Copyright (c) 2009-2011 Nokia Corporation and/or its subsidiary(-ies).
  3. # All rights reserved.
  4. # This component and the accompanying materials are made available
  5. # under the terms of the License "Eclipse Public License v1.0"
  6. # which accompanies this distribution, and is available
  7. # at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. #
  9. # Initial Contributors:
  10. # Nokia Corporation - initial contribution.
  11. #
  12. # Contributors:
  13. #
  14. # Description:
  15. # Tools for use in FLMs - enabling the output from
  16. # rules to be logged with start and end tags.
  17. # This is a place where one might to permit various information to
  18. # be logged, such as timestamps and host names or process ids
  19. #
  20. ifndef _TAGGEDRULES_FLM_
  21. _TAGGEDRULES_FLM_:=1
  22. # only run recipes once by default
  23. RECIPETRIES?=1
  24. ifeq ($(USE_TALON),)
  25. ##
  26. ## Example usage:
  27. ##
  28. # define func
  29. # auto_ok:
  30. # $(call startrule,auto) \
  31. # true && \
  32. # true && \
  33. # true \
  34. # $(call endrule,auto)
  35. #
  36. # auto_fail:
  37. # $(call startrule,auto) \
  38. # find /usr >/dev/null 2>&1 && \
  39. # false && \
  40. # true \
  41. # $(call endrule,auto)
  42. # endef
  43. # $(eval $(func))
  44. # $(1) is the name of the FLM function
  45. # $(2) indicates whether the failure of this rule should be ignored (but still logged)
  46. # FORCESUCCESS indicates "on"
  47. define startrule
  48. @set -o pipefail; RV=0; ATTEMPT=1; \
  49. { while (( $$$$ATTEMPT <= $(RECIPETRIES) )); do \
  50. echo -e "<recipe name='$(1)' \
  51. target='$$@' host='$$$$HOSTNAME' \
  52. layer='$(COMPONENT_LAYER)' component='$(COMPONENT_NAME)' \
  53. bldinf='$(COMPONENT_META)' mmp='$(PROJECT_META)' \
  54. config='$(SBS_CONFIGURATION)' platform='$(PLATFORM)' \
  55. phase='$(MAKEFILE_GROUP)' \
  56. source='$(3)'>\n<![CDATA["; \
  57. FLM_RECIPE_FLAGS='$(2)'; \
  58. export TIMEFORMAT="]]><time start='$$$$($(DATE) +%s.%N)' elapsed='%6R' />"; \
  59. { time { set -x;
  60. endef
  61. define endrule
  62. ; } } 2>&1 ; RV=$$$$?; set +x; \
  63. if (( $$$$RV==0 )); then \
  64. echo "<status exit='ok' attempt='$$$$ATTEMPT' />"; \
  65. echo "</recipe>"; \
  66. break; \
  67. else \
  68. if (( $$$$ATTEMPT < $(RECIPETRIES) )); then \
  69. echo "<status exit='retry' code='$$$$RV' attempt='$$$$ATTEMPT' />"; \
  70. sleep 1; \
  71. else \
  72. if [ ! "$$$${FLM_RECIPE_FLAGS//FORCESUCCESS/}" == "$$$${FLM_RECIPE_FLAGS}" ]; then \
  73. echo "<status exit='failed' code='$$$$RV' attempt='$$$$ATTEMPT' forcesuccess='FORCESUCCESS' />"; \
  74. RV=0; \
  75. else \
  76. echo "<status exit='failed' code='$$$$RV' attempt='$$$$ATTEMPT' />"; \
  77. fi; \
  78. fi; \
  79. fi; \
  80. echo "</recipe>"; \
  81. (( ATTEMPT=$$$$ATTEMPT + 1 )); \
  82. done ; exit $$$${RV}; } $(if $(DESCRAMBLE),2>&1 | $(DESCRAMBLE) -k $$$$$$$$)
  83. endef
  84. define startrawoutput
  85. @ set -o pipefail; {
  86. endef
  87. define endrawoutput
  88. ; exit 0; } $(if $(DESCRAMBLE),2>&1 | $(DESCRAMBLE) -k $$$$$$$$)
  89. endef
  90. else
  91. TALON_RECIPEATTRIBUTES:=\
  92. name='$$RECIPE'\
  93. target='$$TARGET'\
  94. host='$$HOSTNAME'\
  95. layer='$$COMPONENT_LAYER'\
  96. component='$$COMPONENT_NAME'\
  97. bldinf='$$COMPONENT_META' mmp='$$PROJECT_META'\
  98. config='$$SBS_CONFIGURATION' platform='$$PLATFORM'\
  99. phase='$$MAKEFILE_GROUP' source='$$SOURCE' $(if i$(FLMDEBUG),prereqs='$$RECIPE_PREREQS',)
  100. export TALON_RECIPEATTRIBUTES
  101. export TALON_RETRIES
  102. export TALON_DESCRAMBLE
  103. export TALON_SHELL_CL_MAX
  104. define startrule
  105. @|RECIPE=$1;TARGET=$$@;COMPONENT_LAYER=$(COMPONENT_LAYER);COMPONENT_NAME=$(COMPONENT_NAME);COMPONENT_META=$(COMPONENT_META);PROJECT_META=$(PROJECT_META);SBS_CONFIGURATION=$(SBS_CONFIGURATION);PLATFORM=$(PLATFORM);MAKEFILE_GROUP=$(MAKEFILE_GROUP);SOURCE=$3;TALON_FLAGS=$2;$(if $(SHELL_CL_MAX),TALON_SHELL_CL_MAX=$(SHELL_CL_MAX);)$(if $(FLMDEBUG),RECIPE_PREREQS=$$^;,)|
  106. endef
  107. define endrule
  108. endef
  109. define startrawoutput
  110. @|TALON_FLAGS=forcesuccess rawoutput;|
  111. endef
  112. define endrawoutput
  113. endef
  114. endif
  115. endif