.bash_helpers.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #
  2. # Copyright (c) 2008-2015 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Detect markers in the build tree
  23. if [ -f "$BUILD"/.fix-scm ]; then FIX_SCM=1; fi
  24. # Define helpers
  25. post_cmake() {
  26. if [ $ECLIPSE ]; then
  27. # Check if xmlstarlet software package is available for fixing the generated Eclipse project setting
  28. if [ $HAS_XMLSTARLET ]; then
  29. # Common fixes for all builds
  30. #
  31. # Remove build configuration from project name
  32. # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
  33. #
  34. xmlstarlet ed -P -L \
  35. -u "/projectDescription/name/text()" -x "concat(substring-before(., '-Release'), substring-before(., '-Debug'), substring-before(., '-RelWithDebInfo'))" \
  36. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.core.errorOutputParser']" -x "concat('org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;', substring-after(., 'org.eclipse.cdt.core.MakeErrorParser'))" \
  37. "$BUILD"/.project
  38. # Build-specific fixes
  39. if [ $ANDROID ]; then
  40. # For Android build, add the Android and Java nature to the project setting as it would be done by Eclipse during project import
  41. # This fix avoids the step to reimport the project everytime the Eclipse project setting is regenerated by cmake_generic.sh invocation
  42. echo -- post_cmake: Add Android and Java nature to Eclipse project setting files in $BUILD
  43. #
  44. # Add natures (Android nature must be inserted as first nature)
  45. #
  46. xmlstarlet ed -P -L \
  47. -i "/projectDescription/natures/nature[1]" -t elem -n nature -v "com.android.ide.eclipse.adt.AndroidNature" \
  48. -s "/projectDescription/natures" -t elem -n nature -v "org.eclipse.jdt.core.javanature" \
  49. "$BUILD"/.project
  50. #
  51. # Add build commands
  52. #
  53. for c in com.android.ide.eclipse.adt.ResourceManagerBuilder com.android.ide.eclipse.adt.PreCompilerBuilder org.eclipse.jdt.core.javabuilder com.android.ide.eclipse.adt.ApkBuilder; do
  54. xmlstarlet ed -P -L \
  55. -s "/projectDescription/buildSpec" -t elem -n buildCommandNew -v "" \
  56. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n name -v $c \
  57. -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n arguments -v "" \
  58. -r "/projectDescription/buildSpec/buildCommandNew" -v "buildCommand" \
  59. "$BUILD"/.project
  60. done
  61. fi
  62. if [ $FIX_SCM ]; then
  63. # Copy the Eclipse project setting files to Source tree in order to fix it so that Eclipse's SCM feature works again
  64. echo -- post_cmake: Move Eclipse project setting files to $SOURCE and fix them to reenable Eclipse SCM feature
  65. # Leave the original copy in the build tree
  66. for f in .project .cproject; do cp "$BUILD"/$f "$SOURCE"; done
  67. # Set a marker in the build tree that Eclipse project has been fixed
  68. touch "$BUILD"/.fix-scm
  69. #
  70. # Replace [Source directory] linked resource to [Build] instead
  71. # Modify build argument to first change directory to Build folder
  72. # Remove [Subprojects]/Urho3D linked resource
  73. #
  74. xmlstarlet ed -P -L \
  75. -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
  76. -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "`cd $BUILD; pwd`" \
  77. -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C $BUILD ', .)" \
  78. -d "/projectDescription/linkedResources/link[./name = '[Subprojects]/Urho3D']" \
  79. "$SOURCE"/.project
  80. #
  81. # Fix source path entry to Source folder and modify its filter condition
  82. # Fix output path entry to [Build] linked resource and modify its filter condition
  83. #
  84. xmlstarlet ed -P -L \
  85. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
  86. -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Build]/|[Subprojects]/|[Targets]/|Docs/AngelScriptAPI.h" \
  87. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
  88. -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
  89. "$SOURCE"/.cproject
  90. fi
  91. fi
  92. elif [ -e "$BUILD"/*.xcodeproj/project.pbxproj ] && perl -v >/dev/null 2>&1; then
  93. echo -- post_cmake: Fix generated Xcode project
  94. # Temporary workaround to fix file references being added into multiple groups warnings (CMake bug http://www.cmake.org/Bug/view.php?id=15272, stil exists in 3.1)
  95. perl -i -pe 'BEGIN {$/=undef} s/(Begin PBXGroup section.*?,).*?,/\1/s' "$BUILD"/*.xcodeproj/project.pbxproj
  96. # Set Xcode build settings to skip dSYM file generation for Debug configuration (other configurations still use the default dwarf-with-dsym)
  97. if [ $IOS ]; then
  98. perl -i -pe 'BEGIN {$/=undef} s/(Begin XCBuildConfiguration.*?Debug.*?Settings = {\n)/\1DEBUG_INFORMATION_FORMAT = dwarf;\n/s' "$BUILD"/*.xcodeproj/project.pbxproj
  99. fi
  100. fi
  101. }
  102. # vi: set ts=4 sw=4 expandtab: