create_package.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------------------------------
  3. # Copyright (C) Microsoft. All rights reserved.
  4. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  5. #-------------------------------------------------------------------------------------------------------
  6. DEFAULT_COLOR='\033[0m'
  7. ERROR_COLOR='\033[0;31m'
  8. GREEN_COLOR='\033[0;32m'
  9. IF_ERROR_EXIT() {
  10. ERROR_CODE=$1
  11. if [[ $ERROR_CODE != 0 ]]; then
  12. echo -e "${ERROR_COLOR} $2 ${DEFAULT_COLOR}"
  13. exit $ERROR_CODE
  14. fi
  15. }
  16. PRINT_USAGE() {
  17. echo -e "\n${GREEN_COLOR}ChakraCore Package Creation Script${DEFAULT_COLOR}"
  18. echo -e "${ERROR_COLOR}This script may\n- download third party software\n- \
  19. make changes to your system\nand it won't ask you any questions while doing it.${DEFAULT_COLOR}"
  20. echo -e "For this reason,\nyou should run this script with\n${ERROR_COLOR}\
  21. I_ACCEPT_TO_RUN_THIS${DEFAULT_COLOR} secret argument, ${ERROR_COLOR}at your own risk${DEFAULT_COLOR}\n"
  22. echo -e "${GREEN_COLOR}Usage:${DEFAULT_COLOR} tools/create_package.sh <secret argument> <version>"
  23. echo -e "${GREEN_COLOR}Sample:${DEFAULT_COLOR} tools/create_package.sh <secret argument> 2.0.0\n"
  24. }
  25. if [[ $# < 2 || $1 != "I_ACCEPT_TO_RUN_THIS" ]]; then
  26. PRINT_USAGE
  27. exit 0
  28. fi
  29. CHAKRA_VERSION=$2
  30. CHAKRA_VERSION=${CHAKRA_VERSION//./_}
  31. if [[ $2 == $CHAKRA_VERSION ]]; then
  32. PRINT_USAGE
  33. echo -e "${ERROR_COLOR}Unexpected version argument. Try something similar to \
  34. 2.0.0${DEFAULT_COLOR}"
  35. exit 1
  36. fi
  37. if [[ ! -f './build.sh' ]]; then
  38. echo -e "${ERROR_COLOR} Run this script from the repository root folder.${DEFAULT_COLOR}"
  39. echo "Try -> tools/create_package.sh"
  40. exit 1
  41. fi
  42. HOST_OS="osx"
  43. HOST_EXT="dylib"
  44. if [[ ! "$OSTYPE" =~ "darwin" ]]; then # osx
  45. HOST_OS="linux"
  46. HOST_EXT="so"
  47. tools/compile_clang.sh -y
  48. IF_ERROR_EXIT $? "Clang build failed"
  49. fi
  50. ## Build
  51. BUILD="./build.sh --embed-icu -y --lto -j=3"
  52. ${BUILD} --target-path=out/shared
  53. IF_ERROR_EXIT $? "ChakraCore shared library build failed."
  54. ${BUILD} --static --target-path=out/static
  55. IF_ERROR_EXIT $? "ChakraCore static library build failed."
  56. ## Create folders
  57. rm -rf out/ChakraCoreFiles/
  58. mkdir -p out/ChakraCoreFiles/include/ out/ChakraCoreFiles/lib/ out/ChakraCoreFiles/bin/ out/ChakraCoreFiles/sample/
  59. IF_ERROR_EXIT $? "Creating ChakraCoreFiles folder failed"
  60. ## Copy Files
  61. # lib (so or dylib)
  62. cp "out/shared/Release/libChakraCore.${HOST_EXT}" out/ChakraCoreFiles/lib/
  63. # bin
  64. cp out/static/Release/ch out/ChakraCoreFiles/bin/
  65. # include
  66. cp out/shared/Release/include/*.h out/ChakraCoreFiles/include/
  67. # license
  68. cat LICENSE.txt > out/ChakraCoreFiles/LICENSE
  69. echo -e "\n***** Third Party Notices [ for PreBuilt Binaries ] *****\n" >> out/ChakraCoreFiles/LICENSE
  70. cat tools/XPlatInstall/BINARY-DIST-ONLY-NOTICES.txt >> out/ChakraCoreFiles/LICENSE
  71. # sample
  72. cp "tools/XPlatInstall/sample/README.md" out/ChakraCoreFiles/sample/README.md
  73. cp "tools/XPlatInstall/sample/Makefile" out/ChakraCoreFiles/sample/Makefile
  74. cp "tools/XPlatInstall/sample/sample.cpp.txt" out/ChakraCoreFiles/sample/sample.cpp
  75. ## Test
  76. python test/native-tests/test-python/helloWorld.py Release \
  77. "out/ChakraCoreFiles/lib/libChakraCore.${HOST_EXT}" > /dev/null
  78. IF_ERROR_EXIT $? "Shared library test failed"
  79. out/ChakraCoreFiles/bin/ch test/Basics/hello.js > /dev/null
  80. IF_ERROR_EXIT $? "CH binary test failed"
  81. ## Package
  82. pushd out/ > /dev/null
  83. PACKAGE_FILE="cc_${HOST_OS}_x64_${CHAKRA_VERSION}.tar.gz"
  84. tar -czf "${PACKAGE_FILE}" ChakraCoreFiles/
  85. mkdir -p temp/ChakraCoreFiles/
  86. cp "${PACKAGE_FILE}" temp/chakracore.tar.gz
  87. cd temp
  88. SHASUM_FILE="cc_${HOST_OS}_x64_${CHAKRA_VERSION}_s.tar.gz"
  89. shasum -a 512256 chakracore.tar.gz > ChakraCoreFiles/shasum
  90. tar -czf "$SHASUM_FILE" ChakraCoreFiles
  91. mv $SHASUM_FILE ../
  92. cd ..
  93. rm -rf temp/
  94. popd > /dev/null
  95. ## Credits
  96. echo -e "\nPackage & Shasum files are ready under ${GREEN_COLOR}out/${DEFAULT_COLOR}"