PackagingPostBuild_common.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. message(STATUS "Executing packaging postbuild...")
  9. # ly_is_s3_url
  10. # if the given URL is a s3 url of thr form "s3://(stuff)" then sets
  11. # the output_variable_name to TRUE otherwise unsets it.
  12. function (ly_is_s3_url download_url output_variable_name)
  13. if ("${download_url}" MATCHES "s3://.*")
  14. set(${output_variable_name} TRUE PARENT_SCOPE)
  15. else()
  16. unset(${output_variable_name} PARENT_SCOPE)
  17. endif()
  18. endfunction()
  19. function(ly_upload_to_url in_url in_local_path in_file_regex)
  20. message(STATUS "Uploading ${in_local_path}/${in_file_regex} artifacts to ${in_url}")
  21. ly_is_s3_url(${in_url} _is_s3_bucket)
  22. if(NOT _is_s3_bucket)
  23. message(FATAL_ERROR "Only S3 installer uploading is supported at this time")
  24. endif()
  25. # strip the scheme and extract the bucket/key prefix from the URL
  26. string(REPLACE "s3://" "" _stripped_url ${in_url})
  27. string(REPLACE "/" ";" _tokens ${_stripped_url})
  28. list(POP_FRONT _tokens _bucket)
  29. string(JOIN "/" _prefix ${_tokens})
  30. set(_extra_args [[{"ACL":"bucket-owner-full-control"}]])
  31. file(TO_NATIVE_PATH "${LY_ROOT_FOLDER}/scripts/build/tools/upload_to_s3.py" _upload_script)
  32. set(_upload_command
  33. ${CPACK_LY_PYTHON_CMD} -s
  34. -u ${_upload_script}
  35. --base_dir ${in_local_path}
  36. --file_regex="${in_file_regex}"
  37. --bucket ${_bucket}
  38. --key_prefix ${_prefix}
  39. --extra_args ${_extra_args}
  40. )
  41. if(CPACK_AWS_PROFILE)
  42. list(APPEND _upload_command --profile ${CPACK_AWS_PROFILE})
  43. endif()
  44. execute_process(
  45. COMMAND ${_upload_command}
  46. RESULT_VARIABLE _upload_result
  47. OUTPUT_VARIABLE _upload_output
  48. ERROR_VARIABLE _upload_error
  49. OUTPUT_STRIP_TRAILING_WHITESPACE
  50. )
  51. if (${_upload_result} EQUAL 0)
  52. message(STATUS "Artifact uploading complete!")
  53. else()
  54. message(FATAL_ERROR "An error occurred uploading to s3.\n Output: ${_upload_output}\n\ Error: ${_upload_error}")
  55. endif()
  56. endfunction()
  57. function(ly_upload_to_latest in_url in_path)
  58. message(STATUS "Updating latest tagged build")
  59. # make sure we can extra the commit info from the URL first
  60. string(REGEX MATCH "([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9a-zA-Z]+)"
  61. commit_info ${in_url}
  62. )
  63. if(NOT commit_info)
  64. message(FATAL_ERROR "Failed to extract the build tag")
  65. endif()
  66. # Create a temp directory where we are going to rename the file to take out the version
  67. # and then upload it
  68. set(temp_dir ${CPACK_BINARY_DIR}/temp)
  69. if(NOT EXISTS ${temp_dir})
  70. file(MAKE_DIRECTORY ${temp_dir})
  71. endif()
  72. file(COPY ${in_path} DESTINATION ${temp_dir})
  73. cmake_path(GET in_path FILENAME in_path_filename)
  74. string(REPLACE "_${CPACK_PACKAGE_VERSION}" "" non_versioned_in_path_filename ${in_path_filename})
  75. file(RENAME "${temp_dir}/${in_path_filename}" "${temp_dir}/${non_versioned_in_path_filename}")
  76. # include the commit info in a text file that will live next to the exe
  77. set(_temp_info_file ${temp_dir}/build_tag.txt)
  78. file(WRITE ${_temp_info_file} ${commit_info})
  79. # update the URL and upload
  80. string(REPLACE
  81. ${commit_info} "Latest"
  82. latest_upload_url ${in_url}
  83. )
  84. ly_upload_to_url(
  85. ${latest_upload_url}
  86. ${temp_dir}
  87. ".*(${non_versioned_in_path_filename}|build_tag.txt)$"
  88. )
  89. # cleanup the temp files
  90. file(REMOVE_RECURSE ${temp_dir})
  91. message(STATUS "Latest build update complete!")
  92. endfunction()