diff --git a/.github/workflows/get-native-external-version.js b/.github/workflows/get-native-external-version.js new file mode 100644 index 0000000000..aba1e38803 --- /dev/null +++ b/.github/workflows/get-native-external-version.js @@ -0,0 +1,8 @@ +const path = require('path'); +const fs = require('fs'); + +const configJsonPath = path.join(__dirname, '../../native/external-config.json'); +const configData = fs.readFileSync(configJsonPath); +const config = JSON.parse(configData); +const externalVersion = config.from.checkout; +console.log(externalVersion); \ No newline at end of file diff --git a/.github/workflows/native-bindings.yml b/.github/workflows/native-bindings.yml index 2c8eb9c6e2..2f3fdb887f 100644 --- a/.github/workflows/native-bindings.yml +++ b/.github/workflows/native-bindings.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 - name: Download external libraries run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external rm -rf native/external/.git diff --git a/.github/workflows/native-compile-linux.yml b/.github/workflows/native-compile-linux.yml index 868e915f54..d79c976216 100644 --- a/.github/workflows/native-compile-linux.yml +++ b/.github/workflows/native-compile-linux.yml @@ -11,7 +11,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings run: | @@ -27,7 +27,7 @@ jobs: env: COCOS_ENGINE_DEV: 1 run: | - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native echo "Compiling Linux ... " cd $GITHUB_WORKSPACE/templates/linux mkdir -p build-linux/proj @@ -43,6 +43,6 @@ jobs: RES_DIR=$GITHUB_WORKSPACE/templates/linux/build-linux cd build-linux - cmake ../ -GNinja -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT + cmake ../ -GNinja -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$NATIVE_ROOT set +e cmake --build . \ No newline at end of file diff --git a/.github/workflows/native-compile-platforms.yml b/.github/workflows/native-compile-platforms.yml index 162298817a..3d06d148d6 100644 --- a/.github/workflows/native-compile-platforms.yml +++ b/.github/workflows/native-compile-platforms.yml @@ -12,7 +12,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Install deps run: | @@ -59,7 +59,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings run: | @@ -70,7 +70,7 @@ jobs: env: COCOS_ENGINE_DEV: 1 run: | - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native ANDORID_NDK=$ANDROID_NDK_LATEST_HOME NATIVE_DIR=$GITHUB_WORKSPACE/templates/android-template echo "Compiling Android ... " @@ -96,7 +96,7 @@ jobs: sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties - sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$COCOS2DX_ROOT@g" gradle.properties + sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties sed -i "s@^NATIVE_DIR.*@NATIVE_DIR=$NATIVE_DIR@g" gradle.properties # To speedup CI, compile arm64-v8a only @@ -119,7 +119,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings run: | @@ -131,7 +131,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native echo "Compiling MacOSX ... " cd $GITHUB_WORKSPACE/templates/mac echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake @@ -148,7 +148,7 @@ jobs: RES_DIR=$GITHUB_WORKSPACE/templates/mac/build-mac cd build-mac - cmake ../ -GXcode -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT + cmake ../ -GXcode -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$NATIVE_ROOT set +e cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch x86_64 retcode=$? @@ -172,7 +172,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings run: | @@ -184,7 +184,7 @@ jobs: COCOS_ENGINE_DEV: 1 run: | NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native echo "Compiling MacOSX ... " cd $GITHUB_WORKSPACE/templates/mac mkdir -p build-mac/proj @@ -199,7 +199,7 @@ jobs: RES_DIR=$GITHUB_WORKSPACE/templates/mac/build-mac cd build-mac - cmake ../ -GXcode -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT + cmake ../ -GXcode -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$NATIVE_ROOT set +e cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch arm64 retcode=$? @@ -226,7 +226,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings run: | @@ -239,7 +239,7 @@ jobs: run: | set -x NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native echo "Compiling iOS ... " cd $GITHUB_WORKSPACE/templates/ios echo "message(STATUS \"hook before \${CC_TARGET_NAME}\")" >> Pre-Sample.cmake @@ -262,7 +262,7 @@ jobs: -DCMAKE_OSX_SYSROOT=iphoneos \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ -DRES_DIR=$RES_DIR \ - -DCOCOS_X_PATH=$COCOS2DX_ROOT + -DCOCOS_X_PATH=$NATIVE_ROOT set +e #cmake --build . --config Debug -- -quiet -jobs $NUM_OF_CORES -allowProvisioningUpdates CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO cmake --build . --config Debug -- -quiet -jobs $NUM_OF_CORES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO @@ -285,7 +285,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Setup Emscripten run: | @@ -299,8 +299,8 @@ jobs: env: COCOS_ENGINE_DEV: 1 run: | - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native - cd $COCOS2DX_ROOT/cocos/renderer/gfx-wgpu - $COCOS2DX_ROOT/../emsdk/upstream/emscripten/emcmake cmake . - $COCOS2DX_ROOT/../emsdk/upstream/emscripten/emmake make + NATIVE_ROOT=$GITHUB_WORKSPACE/native + cd $NATIVE_ROOT/cocos/renderer/gfx-wgpu + $NATIVE_ROOT/../emsdk/upstream/emscripten/emcmake cmake . + $NATIVE_ROOT/../emsdk/upstream/emscripten/emmake make echo "Compile WGPU by ems on MacOS Done!" diff --git a/.github/workflows/native-linter-android.yml b/.github/workflows/native-linter-android.yml index 81c9de4151..11fd6c6326 100644 --- a/.github/workflows/native-linter-android.yml +++ b/.github/workflows/native-linter-android.yml @@ -26,7 +26,7 @@ jobs: python -m pip install PyYAML==5.4.1 Cheetah3 - name: Download external run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings diff --git a/.github/workflows/native_compile_self.yml b/.github/workflows/native_compile_self.yml index 92bba69961..e130b003f3 100644 --- a/.github/workflows/native_compile_self.yml +++ b/.github/workflows/native_compile_self.yml @@ -15,7 +15,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings @@ -30,7 +30,7 @@ jobs: env: COCOS_ENGINE_DEV: 1 run: | - COCOS2DX_ROOT=$GITHUB_WORKSPACE/native + NATIVE_ROOT=$GITHUB_WORKSPACE/native ANDORID_NDK='/home/tools/android-sdk-linux/ndk-bundle' ANDROID_NDK_HOME='/home/tools/android-sdk-linux/ndk-bundle' ANDROID_SDK_ROOT='/home/tools/android-sdk-linux' @@ -54,7 +54,7 @@ jobs: sed -i "s@^PROP_NDK_PATH.*@PROP_NDK_PATH=$ANDORID_NDK@g" gradle.properties sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties - sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$COCOS2DX_ROOT@g" gradle.properties + sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties sed -i "s@^NATIVE_DIR.*@NATIVE_DIR=$NATIVE_DIR@g" gradle.properties # To speedup CI, compile arm64-v8a only # sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties @@ -73,7 +73,7 @@ jobs: - name: Download external libraries shell: bash run: | - EXT_VERSION=`grep version native/external-config.json |awk -F'"' '{print $4}'` + EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - name: Generate bindings diff --git a/native/.travis.yml b/native/.travis.yml deleted file mode 100644 index 06cc14d3b8..0000000000 --- a/native/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: cpp - -jobs: - include: - - os: linux - name: Android - dist: xenial - sudo: required - env: - - BUILD_TARGET=genbindings - language: cpp - before_install: - - nvm install 12 - - tools/travis-scripts/before-install.sh - -jdk: - - oraclejdk8 -script: - - tools/travis-scripts/run-script.sh -# blocklist -# branches: -# except: -# - develop - -#env: -# global: -# - secure: bUrk522Qw5Mc3SfDXHZtJ/aF9QbLXYDnUVSOJXt1wUB1d8xAQphTcZ1ARNYu7I5m3ZXqRfzTS4POOT58qeS3sYPpJ8urWW18hgX3I/dmsL1WJXmwnOV+0J3xLt6AT3ttqj7/emaf0xxuBvZ0szyRz0rU4wprtWftWMFiUrsF8G1an2Qa/g/f5LhilnDiKAqFdHMkn0ogaggL0PbgliHeHo7SEOfSF2gQaSIBta7jzE/BEZZ3R4AuReB3oNDwxr+1E4BpPaGO1lMLzdr8MAjWBGVLBRlpVDihgFTTmdka8UYasjEWDs6GbSjJRsTZQkluOo+1UylSiLn5o1tnWMqINo5DDaayBSKWRV/x+Sx+KMG221BwHLGFHrhEm8Jwc3g5IBiFrc9Xn/PAoCL3Zi/m0m8Y/TVIlA2nWuU0jeMZYXOb0ALCplAQMrG/Yt7euzgSjZ9iPvO7HO8BkaRkUxafcp6svWyMedNeDczG6liLSquJak+XIbOpWCOW+KVxc2S2Unz37MSOQR/aB9dJ8fKI/4e3LCdYrSKW9MSKAz9BSYA2IK2F8Fgr6zY3IPTANQCi6o8i/N54wsmpY17uvzqNDGuag5m/FkNpFWVQUy/TdONanXV6m1jvREaxtDHucSnP3olmvx6pi1awRspDfRmcILK08yvul+yLol0nQwenlx0= -# - secure: g7YPNjmnfzksSu2OqIAjoU3wyogplkOOnACJF8jOsacs0wvZ/JieNBusnkbsOmWhxk1exdpbP01j+ApeJQiqSACPsEXyImrIP0MaErH8SfzBIYtxJKVGZLO292aKmES0BlJTUeLHBGv3kzLg1uOZAfMiLVFgH00oHWx0dr+T9qpRJ8brmJ6orosV8D55A12IHTz3tJLmvJRNuVidrCFxJar9xK5HSPwT6NgH2PXPQKdLCoRqZe6N/uMtrDXgwqGHzLzkR0w+O0iyai2iK6ACTXhNIk88yh7QkV+oa8KoYNLsajGu+Yab1YAQgKSqBM8FvRMGJdJ8Jk4z8btX9sN1AUyJxjgrVic/kqsWlIu6rsSAUbVQ4O1Rhw74r0GJLObQOXZsUUApYQAcYdwPV/Ln0k3GXLxZ8AdEUnDDIQpklJfPmmsLYDSyaj1qQjrECIX3piS4kFhiNak5izxgweLMScig6HOg/q1gWOSuAgmz0WJ/0IdP7q+CF6B70/sxp5jomERGEcfgtIn/N8He+X4swFVHvYiFWyF5jJ+GpFbZQZbhn3dtFcj9/Yr5UPoR9q2RJD1ayO+3yuN4fbq3VO4ZlXmHY9CAH4b1NIAGdmF1vdIgW9QSX+suc8dBex7wCu3+74N54CnFZWl4KbLX3dq86IIjihimUJtUmSjHPOH8m20= -# - secure: 0OmLJ6Y5zfybz3fnQWb9GI5z4Mljlg9q1JGwN5j6IDdsXc8QKBXoBQSIFMQmDaDvb91NQl/gWRXcG409t4ysKSImOIxtsSE4A5ZLYu2pI7c09xXbGP6pvP9pGKnqvIVH6N7DERYi0R8kZdjCyttCLaLsMgX6DU+OoqlszetSOwct6uQ+L8jhU2xRzVB6oTgZqLUI8PDNMOXH0ftrroWc7vjtTinJQ54xTFKCat5FEXCMK6XX4lfeayJuS1m2dg8vabhW347PDa2pOa/gnVEeoqUM9qSDWUmA2LRUO5Z6vgI/1I3H4xd2uRmYsLaZHmpddS3IG8QvcHP8yTKbEE6USaEBsM8PbKg5Zy8fE301Bmv+Sr7rWFmBJMRjMiiowAQiN08DfUziDLY66uOucXY4W7sGxBi5383KYqzC3/R+yOmsaeCEWHcymcqvsGuuMq4eIPgYIK0G4TG9ubB0oJ+cJYiePdrAMK1PzJ9MqK4GsJBz4W1Lh1c0ofkr8sC0kLZbWJSyB4DArcVwYPgrsMelgwySO5EGbi9OUm5ONHS+7QaNVqczfbwrrR6tmQZruoG2u6HRpYxcqWnYl/TusodnZxBGT+POYaUcKwNBt6lSSq1sJTFb5ysGRBme/1+KUDLjqslX3yx6isC+n65GlEUFxguNeuokoLc9vnL7+npukHk= diff --git a/native/README.md b/native/README.md index 81f7ce85c4..bd07f53aa9 100644 --- a/native/README.md +++ b/native/README.md @@ -1,9 +1,7 @@ engine-native ========================== -Build Status - -It is the native backend of [Cocos Creator](https://www.cocos.com/en/creator). It works on `iOS`, `Android`, `Mac OS` and `Windows`. +It is the native backend of [Cocos Creator](https://www.cocos.com/en/creator). It works on `iOS`, `Android`, `macOS` and `Windows`. Coding format and coding style --------------------------------- @@ -21,10 +19,9 @@ You can refer to [the documentation](https://docs.cocos.com/creator/3.0/manual/e Build Requirements -------------------------------- - macOS 10.14+, Xcode 11.5+ to build mac games -- with iOS 12.0+ to build iOS games +- with iOS 10.0+ to build iOS games - or Windows 7+, Visual Studio 2017 15.7+ / Visual Studio 2019 to build win32 games - NDK 18-21 is required to build Android games (22+ is not supported) -- Python 2.7+ (includes Python 3) is needed to run scripts - Cmake 3.8+ is required Where to get help diff --git a/native/download-deps.py b/native/download-deps.py deleted file mode 100755 index 21964a903e..0000000000 --- a/native/download-deps.py +++ /dev/null @@ -1,349 +0,0 @@ -#!/usr/bin/env python -#coding=utf-8 -# -# ./download-deps.py -# -# Downloads Cocos2D-x 3rd party dependencies from github: -# https://github.com/WenhaiLin/cocos2d-x-lite-external) and extracts the zip -# file -# -# Having the dependencies outside the official cocos2d-x repo helps prevent -# bloating the repo. -# - -"""**************************************************************************** -Copyright (c) 2014 cocos2d-x.org -Copyright (c) 2014-2017 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************""" - -import os.path -import zipfile -import shutil -import sys -import traceback -import distutils -import fileinput -import json - -from optparse import OptionParser -from time import time -from sys import stdout -from distutils.errors import DistutilsError -from distutils.dir_util import copy_tree, remove_tree - - -def delete_folder_except(folder_path, excepts): - """ - Delete a folder excepts some files/subfolders, `excepts` doesn't recursively which means it can not include - `subfoler/file1`. `excepts` is an array. - """ - for file in os.listdir(folder_path): - if (file in excepts): - continue - - full_path = os.path.join(folder_path, file) - if os.path.isdir(full_path): - shutil.rmtree(full_path) - else: - os.remove(full_path) - - -class UnrecognizedFormat: - def __init__(self, prompt): - self._prompt = prompt - - def __str__(self): - return self._prompt - - -class CocosZipInstaller(object): - def __init__(self, workpath, config_path, version_path, remote_version_key=None): - self._workpath = workpath - self._config_path = config_path - self._version_path = version_path - - data = self.load_json_file(config_path) - - self._current_version = data["version"] - self._repo_name = data["from"]["name"] - try: - self._move_dirs = data["move_dirs"] - except: - self._move_dirs = None - self._filename = self._current_version + '.zip' - self._url = "https://github.com/" + data["from"]["owner"] + "/" + self._repo_name + '/archive/' + self._filename - # 'v' letter was swallowed by github, so we need to substring it from the 2nd letter - self._extracted_folder_name = os.path.join(self._workpath, self._repo_name + '-' + self._current_version[1:]) - - try: - data = self.load_json_file(version_path) - if remote_version_key is None: - self._remote_version = data["version"] - else: - self._remote_version = data[remote_version_key] - except: - print("==> version file doesn't exist") - - def get_input_value(self, prompt): - ret = raw_input(prompt) - ret.rstrip(" \t") - return ret - - def download_file(self): - print("==> Ready to download '%s' from '%s'" % (self._filename, self._url)) - import urllib2 - try: - u = urllib2.urlopen(self._url) - except urllib2.HTTPError as e: - if e.code == 404: - print("==> Error: Could not find the file from url: '%s'" % (self._url)) - print("==> Http request failed, error code: " + str(e.code) + ", reason: " + e.read()) - sys.exit(1) - - f = open(self._filename, 'wb') - meta = u.info() - content_len = meta.getheaders("Content-Length") - file_size = 0 - if content_len and len(content_len) > 0: - file_size = int(content_len[0]) - else: - # github server may not reponse a header information which contains `Content-Length`, - # therefore, the size needs to be written hardcode here. While server doesn't return - # `Content-Length`, use it instead - print("==> WARNING: Couldn't grab the file size from remote, use 'zip_file_size' section in '%s'" % self._config_path) - file_size = 0 - - print("==> Start to download, please wait ...") - - file_size_dl = 0 - block_sz = 8192 - block_size_per_second = 0 - old_time = time() - - status = "" - while True: - buffer = u.read(block_sz) - if not buffer: - print("%s%s" % (" " * len(status), "\r")), - break - - file_size_dl += len(buffer) - block_size_per_second += len(buffer) - f.write(buffer) - new_time = time() - if (new_time - old_time) > 1: - speed = block_size_per_second / (new_time - old_time) / 1000.0 - if file_size != 0: - percent = file_size_dl * 100. / file_size - status = r"Downloaded: %6dK / Total: %dK, Percent: %3.2f%%, Speed: %6.2f KB/S " % (file_size_dl / 1000, file_size / 1000, percent, speed) - else: - status = r"Downloaded: %6dK, Speed: %6.2f KB/S " % (file_size_dl / 1000, speed) - print(status), - sys.stdout.flush() - print("\r"), - block_size_per_second = 0 - old_time = new_time - - print("==> Downloading finished!") - f.close() - - def ensure_directory(self, target): - if not os.path.exists(target): - os.mkdir(target) - - def unpack_zipfile(self, extract_dir): - """Unpack zip `filename` to `extract_dir` - - Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined - by ``zipfile.is_zipfile()``). - """ - - if not zipfile.is_zipfile(self._filename): - raise UnrecognizedFormat("%s is not a zip file" % (self._filename)) - - print("==> Extracting files, please wait ...") - z = zipfile.ZipFile(self._filename) - try: - for info in z.infolist(): - name = info.filename - - # don't extract absolute paths or ones with .. in them - if name.startswith('/') or '..' in name: - continue - - target = os.path.join(extract_dir, *name.split('/')) - if not target: - continue - if name.endswith('/'): - # directory - self.ensure_directory(target) - else: - # file - data = z.read(info.filename) - f = open(target, 'wb') - try: - f.write(data) - finally: - f.close() - del data - unix_attributes = info.external_attr >> 16 - if unix_attributes: - os.chmod(target, unix_attributes) - finally: - z.close() - print("==> Extraction done!") - - def ask_to_delete_downloaded_zip_file(self): - ret = self.get_input_value("==> Would you like to save '%s'? So you don't have to download it later. [yes/no]: " % self._filename) - ret = ret.strip() - if ret != 'yes' and ret != 'y' and ret != 'no' and ret != 'n': - print("==> Saving the dependency libraries by default") - return False - else: - return True if ret == 'no' or ret == 'n' else False - - def download_zip_file(self): - if not os.path.isfile(self._filename): - self.download_file() - try: - if not zipfile.is_zipfile(self._filename): - raise UnrecognizedFormat("%s is not a zip file" % (self._filename)) - except UnrecognizedFormat as e: - print("==> Unrecognized zip format from your local '%s' file!" % (self._filename)) - if os.path.isfile(self._filename): - os.remove(self._filename) - print("==> Download it from internet again, please wait...") - self.download_zip_file() - - def need_to_update(self): - if not os.path.isfile(self._version_path): - return True - - with open(self._version_path) as data_file: - data = json.load(data_file) - - if self._remote_version == self._current_version: - return False - return True - - def load_json_file(self, file_path): - if not os.path.isfile(file_path): - raise Exception("Could not find (%s)" % (file_path)) - - with open(file_path) as data_file: - data = json.load(data_file) - return data - - def clean_external_folder(self, external_folder): - print('==> Cleaning native/external folder ...') - # remove files in external directory - delete_folder_except(external_folder, []) - - def run(self, workpath, folder_for_extracting, remove_downloaded, force_update, download_only): - if not force_update and not self.need_to_update(): - print("==> Not need to update!") - return - - if os.path.exists(self._extracted_folder_name): - shutil.rmtree(self._extracted_folder_name) - - self.download_zip_file() - - if not download_only: - self.unpack_zipfile(self._workpath) - - if not os.path.exists(folder_for_extracting): - os.mkdir(folder_for_extracting) - - self.clean_external_folder(folder_for_extracting) - print("==> Copying files...") - distutils.dir_util.copy_tree(self._extracted_folder_name, folder_for_extracting) - if self._move_dirs is not None: - for srcDir in self._move_dirs.keys(): - distDir = os.path.join( os.path.join(workpath, self._move_dirs[srcDir]), srcDir) - if os.path.exists(distDir): - shutil.rmtree(distDir) - shutil.move( os.path.join(folder_for_extracting, srcDir), distDir) - print("==> Cleaning...") - if os.path.exists(self._extracted_folder_name): - shutil.rmtree(self._extracted_folder_name) - if os.path.isfile(self._filename): - if remove_downloaded is not None: - if remove_downloaded == 'yes': - os.remove(self._filename) - elif self.ask_to_delete_downloaded_zip_file(): - os.remove(self._filename) - else: - print("==> Download (%s) finish!" % self._filename) - - -def _check_python_version(): - major_ver = sys.version_info[0] - if major_ver > 2: - print ("The python version is %d.%d. But python 2.x is required. (Version 2.7 is well tested)\n" - "Download it here: https://www.python.org/" % (major_ver, sys.version_info[1])) - return False - - # To make sure TLS 1.2 is supported by python - if sys.version_info < (2, 7, 9): - print ("The python version is %d.%d.%d. Please install 2.7.9 or higher version of python 2.x\n" - "Download it here: https://www.python.org/" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])) - return False - - return True - - -def main(): - workpath = os.path.dirname(os.path.realpath(__file__)) - - if not _check_python_version(): - exit() - - parser = OptionParser() - parser.add_option('-r', '--remove-download', - action="store", type="string", dest='remove_downloaded', default=None, - help="Whether to remove downloaded zip file, 'yes' or 'no'") - - parser.add_option("-f", "--force-update", - action="store_true", dest="force_update", default=False, - help="Whether to force update the third party libraries") - - parser.add_option("-d", "--download-only", - action="store_true", dest="download_only", default=False, - help="Only download zip file of the third party libraries, will not extract it") - - (opts, args) = parser.parse_args() - - print("=======================================================") - print("==> Prepare to download external libraries!") - external_path = os.path.join(workpath, 'external') - installer = CocosZipInstaller(workpath, os.path.join(workpath, 'external-config.json'), os.path.join(workpath, 'external', 'version.json'), "prebuilt_libs_version") - installer.run(workpath, external_path, opts.remove_downloaded, opts.force_update, opts.download_only) - -# -------------- main -------------- -if __name__ == '__main__': - try: - main() - except Exception as e: - traceback.print_exc() - sys.exit(1) diff --git a/native/external-config.json b/native/external-config.json index b17dbb653d..5ba999a011 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -1,5 +1,4 @@ { - "version": "v3d-gfx-116", "from": { "type": "github", "owner": "cocos-creator", diff --git a/native/tools/make-package/README.markdown b/native/tools/make-package/README.markdown deleted file mode 100755 index 36c5366923..0000000000 --- a/native/tools/make-package/README.markdown +++ /dev/null @@ -1,21 +0,0 @@ -Creates archive from the current state using `git ls-files --cached --full-name --no-empty-directory`. Supports for any level of submodules tree. Files from submodules are extracted using the same command. - -*License:* MIT - -*Usage:* `git-archive-all [-v] [--prefix PREFIX] [--no-exclude] [--force-submodules] [--dry-run] OUTPUT_FILE` - -*Options:* - - **--version** Show program's version number and exit. - - **-h, --help** Show this help message and exit. - - **--prefix=PREFIX** Prepend PREFIX to each filename in the archive. OUTPUT_FILE name is used by default to avoid tarbomb. - - **--force-submodules** Force a `git submodule init && git submodule update` at each level before iterating submodules - - **-v, --verbose** Enable verbose mode. - - **--no-exclude** Don't read .gitattributes files for patterns containing export-ignore attributes. - - **--dry-run** Don't actually archive anything, just show what would be done. diff --git a/native/tools/make-package/config.json b/native/tools/make-package/config.json deleted file mode 100755 index dfac85f299..0000000000 --- a/native/tools/make-package/config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extra_zip_files": - [ - { - "zip_config_path": "../../external-config.json", - "zip_file_path": "../../", - "extract_to_zip_path": "external" - }, - { - "zip_config_path": "../cocos2d-console/config.json", - "zip_file_path": "../cocos2d-console", - "extract_to_zip_path": "tools/cocos2d-console" - } - ] -} diff --git a/native/tools/make-package/git-archive-all b/native/tools/make-package/git-archive-all deleted file mode 100755 index 14ff300de2..0000000000 --- a/native/tools/make-package/git-archive-all +++ /dev/null @@ -1,636 +0,0 @@ -#! /usr/bin/env python -# coding=utf-8 - -from __future__ import print_function -from __future__ import unicode_literals - -__version__ = "1.7" - -import sys -import os -import shutil -import traceback - -from os import path, extsep -from subprocess import Popen, PIPE, CalledProcessError - -def os_is_win32(): - return sys.platform == 'win32' - -class UnrecognizedFormat: - def __init__(self, prompt): - self._prompt = prompt - def __str__(self): - return self._prompt - -class GitArchiver(object): - """ - GitArchiver - - Scan a git repository and export all tracked files, and submodules. - Checks for .gitattributes files in each directory and uses 'export-ignore' - pattern entries for ignore files in the archive. - - Automatically detects output format extension: zip, tar, bz2, or gz. - """ - - def __init__(self, prefix='', verbose=False, exclude=True, force_sub=False, extra=None, main_repo_abspath=None): - """ - @type prefix: string - @param prefix: Prefix used to prepend all paths in the resulting archive. - - @type verbose: bool - @param verbose: Determines verbosity of the output (stdout). - - @type exclude: bool - @param exclude: Determines whether archiver should follow rules specified in .gitattributes files. - Defaults to True. - - @type force_sub: bool - @param force_sub: Determines whether submodules are initialized and updated before archiving. - Defaults to False - - @type extra: list - @param extra: List of extra paths to include in the resulting archive. - - @type main_repo_abspath: string - @param main_repo_abspath: Absolute path to the main repository (or one of subdirectories). - If None, current cwd is used. - If given path is path to a subdirectory (but not a submodule directory!) - it will be replaced with abspath to toplevel directory of the repository. - """ - if extra is None: - extra = [] - - if main_repo_abspath is None: - main_repo_abspath = path.abspath('') - elif not path.isabs(main_repo_abspath): - raise ValueError("You MUST pass absolute path to the main git repository.") - - # Raises an exception if there is no repo under main_repo_abspath. - try: - self.run_shell("git rev-parse", main_repo_abspath) - except Exception as e: - raise ValueError("Not a git repository (or any of the parent directories).".format(path=main_repo_abspath)) - - # Detect toplevel directory of the repo. - main_repo_abspath = path.abspath(self.read_git_shell('git rev-parse --show-toplevel', main_repo_abspath).rstrip()) - - self.prefix = prefix - self.verbose = verbose - self.exclude = exclude - self.extra = extra - self.force_sub = force_sub - self.main_repo_abspath = main_repo_abspath - - def load_json_file(self, file_path): - import json - if not path.isfile(file_path): - raise Exception("Could not find (%s)" % (file_path)) - - with open(file_path) as data_file: - data = json.load(data_file) - return data - - def ensure_directory(self, target): - if not os.path.exists(target): - os.mkdir(target) - - def unpack_zipfile(self, zip_file_path, extract_dir): - """Unpack zip `filename` to `extract_dir` - - Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined - by ``zipfile.is_zipfile()``). - """ - - import zipfile - if not zipfile.is_zipfile(zip_file_path): - raise UnrecognizedFormat("%s is not a zip file" % zip_file_path) - - file_paths = [] - print("==> Extracting files, please wait ...") - z = zipfile.ZipFile(zip_file_path) - try: - for info in z.infolist(): - name = info.filename - - # don't extract absolute paths or ones with .. in them - if name.startswith('/') or '..' in name: - continue - - target = os.path.join(extract_dir, *name.split('/')) - if not target: - continue - if name.endswith('/'): - # directory - self.ensure_directory(target) - else: - # file - data = z.read(info.filename) - file_paths.append(target) - f = open(target,'wb') - try: - f.write(data) - finally: - f.close() - del data - unix_attributes = info.external_attr >> 16 - if unix_attributes: - os.chmod(target, unix_attributes) - finally: - z.close() - print("==> Extraction done!") - return file_paths - - def create(self, output_path, dry_run=False, output_format=None): - """ - Creates the archive, written to the given output_file_path - - Type of the archive is determined either by extension of output_file_path or by the format argument. - Supported formats are: gz, zip, bz2, tar, tgz - - @type output_path: string - @param output_path: Output file path. - - @type dry_run: bool - @param dry_run: Determines whether create should do nothing but print what it would archive. - - @type output_format: string - @param output_format: Determines format of the output archive. - If None, format is determined from extension of output_file_path. - """ - if output_format is None: - file_name, file_ext = path.splitext(output_path) - output_format = file_ext[len(extsep):].lower() - - if output_format == 'zip': - from zipfile import ZipFile, ZIP_DEFLATED - - if not dry_run: - archive = ZipFile(path.abspath(output_path), 'w') - add = lambda file_path, file_name: archive.write(file_path, path.join(self.prefix, file_name), ZIP_DEFLATED) - elif output_format in ['tar', 'bz2', 'gz', 'tgz']: - import tarfile - - if output_format == 'tar': - t_mode = 'w' - elif output_format == 'tgz': - t_mode = 'w:gz' - else: - t_mode = 'w:{f}'.format(f=output_format) - - if not dry_run: - archive = tarfile.open(path.abspath(output_path), t_mode) - add = lambda file_path, file_name: archive.add(file_path, path.join(self.prefix, file_name)) - else: - raise RuntimeError("Unknown format: {f}".format(f=output_format)) - - print("Making archive: (%s) , please wait ..." % output_path) - for file_path in self.extra: - if not dry_run: - if self.verbose: - print("Compressing {f} => {a}...".format(f=file_path, - a=path.join(self.prefix, file_path))) - try: - add(file_path, file_path) - except: - print('add %s failed.' % file_path) - pass - else: - print("{f} => {a}".format(f=file_path, - a=path.join(self.prefix, file_path))) - - for file_path in self.list_files(): - if not dry_run: - if self.verbose: - print("Compressing {f} => {a}...".format(f=path.join(self.main_repo_abspath, file_path), - a=path.join(self.prefix, file_path))) - - try: - add(path.join(self.main_repo_abspath, file_path), file_path) - except: - print('add %s failed.' % file_path) - pass - else: - print("{f} => {a}".format(f=path.join(self.main_repo_abspath, file_path), - a=path.join(self.prefix, file_path))) - - - # Execute download-deps.py in root folder - import subprocess - subprocess.call("python %s -d -f" % (path.join(self.main_repo_abspath, "download-deps.py")), shell=True, cwd=self.main_repo_abspath) - - # Execute download-bin.py in cocos2d-console folder - console_path = path.join(self.main_repo_abspath, "tools", "cocos2d-console") - subprocess.call("python %s -d -f" % (path.join(console_path, "download-bin.py")), shell=True, cwd=console_path) - - # Check config.json to insert a zip file content to the final generated zip file - extra_folders = [] - config_path = path.join(self.main_repo_abspath, "tools", "make-package") - config_data = self.load_json_file(path.join(config_path, "config.json")) - - for zip_file in config_data["extra_zip_files"]: - zip_config = self.load_json_file(path.join(config_path, zip_file["zip_config_path"])) - zip_file_name = zip_config["version"] + '.zip' - extra_to_zip_file = zip_file["extract_to_zip_path"] - zip_file_path = os.path.join(zip_file["zip_file_path"], zip_file_name) - zip_config_version = zip_config["version"] - # 'v' letter was swallowed by github, so we need to substring it from the 2nd letter - if zip_config_version[0] == 'v': - zip_config_version = zip_config_version[1:] - extra_folder_name = zip_config["repo_name"] + '-' + zip_config_version - extra_folder_path = os.path.join(self.main_repo_abspath, extra_folder_name) - extra_folders.append(extra_folder_path) - extra_file_paths = self.unpack_zipfile(zip_file_path, self.main_repo_abspath) - - key_move_dirs = "move_dirs" - for file_path in extra_file_paths: - if file_path.find(extra_folder_path) == -1: - raise Exception("Couldn't find extra folder path (%s) in (%s)!" % (extra_folder_path, file_path)) - - path_in_zip = extra_to_zip_file + file_path[(len(extra_folder_path)):] - if key_move_dirs in zip_config: - move_dirs = zip_config[key_move_dirs] - related_path = os.path.relpath(file_path, extra_folder_path) - temp_rel_path = related_path.replace('\\', '/') - for move_dir in move_dirs: - if temp_rel_path.startswith(move_dir): - move_to_dir = move_dirs[move_dir] - path_in_zip = os.path.join(move_to_dir, related_path) - break - - try: - add(file_path, path_in_zip) - except: - print('add %s failed.' % file_path) - pass - - key_extra_dirs = "extra_dirs" - if key_extra_dirs in config_data: - for extra_dir in config_data[key_extra_dirs]: - dir_path = path.join(self.main_repo_abspath, extra_dir) - list_dirs = os.walk(dir_path) - for root,dirs,files in list_dirs: - for f in files: - file_path = path.join(root,f) - path_in_zip = file_path[(len(self.main_repo_abspath)+1):] - try: - add(file_path, path_in_zip) - except: - print('add %s failed.' % file_path) - pass - - if not dry_run: - archive.close() - - for extra_folder in extra_folders: - if os.path.exists(extra_folder): - shutil.rmtree(extra_folder) - - - def get_path_components(self, repo_abspath, abspath): - """ - Splits given abspath into components until repo_abspath is reached. - - E.g. if repo_abspath is '/Documents/Hobby/ParaView/' and abspath is - '/Documents/Hobby/ParaView/Catalyst/Editions/Base/', function will return: - ['.', 'Catalyst', 'Editions', 'Base'] - - First element is always '.' (concrete symbol depends on OS). - - @type repo_abspath: string - @param repo_abspath: Absolute path to the git repository. - - @type abspath: string - @param abspath: Absolute path to within repo_abspath. - - @rtype: list - @return: List of path components. - """ - components = [] - - if os_is_win32(): - abspath = os.path.normpath(abspath) - repo_abspath = os.path.normpath(repo_abspath) - while abspath != repo_abspath: - abspath, tail = path.split(abspath) - - if len(tail): - components.insert(0, tail) - else: - while not path.samefile(abspath, repo_abspath): - abspath, tail = path.split(abspath) - - if len(tail): - components.insert(0, tail) - - components.insert(0, path.relpath(repo_abspath, repo_abspath)) - return components - - def get_exclude_patterns(self, repo_abspath, repo_file_paths): - """ - Returns exclude patterns for a given repo. It looks for .gitattributes files in repo_file_paths. - - Resulting dictionary will contain exclude patterns per path (relative to the repo_abspath). - E.g. {('.', 'Catalyst', 'Editions', 'Base'), ['Foo*', '*Bar']} - - @type repo_abspath: string - @param repo_abspath: Absolute path to the git repository. - - @type repo_file_paths: list - @param repo_file_paths: List of paths relative to the repo_abspath that are under git control. - - @rtype: dict - @return: Dictionary representing exclude patterns. - Keys are tuples of strings. Values are lists of strings. - Returns None if self.exclude is not set. - """ - if not self.exclude: - return None - - def read_attributes(attributes_abspath): - patterns = [] - if path.isfile(attributes_abspath): - attributes = open(attributes_abspath, 'r').readlines() - patterns = [] - for line in attributes: - tokens = line.strip().split() - if "export-ignore" in tokens[1:]: - patterns.append(tokens[0]) - return patterns - - exclude_patterns = {(): []} - - # There may be no gitattributes. - try: - global_attributes_abspath = self.read_shell("git config --get core.attributesfile", repo_abspath).rstrip() - exclude_patterns[()] = read_attributes(global_attributes_abspath) - except: - # And valid to not have them. - pass - - for attributes_abspath in [path.join(repo_abspath, f) for f in repo_file_paths if f.endswith(".gitattributes")]: - # Each .gitattributes affects only files within its directory. - key = tuple(self.get_path_components(repo_abspath, path.dirname(attributes_abspath))) - exclude_patterns[key] = read_attributes(attributes_abspath) - - local_attributes_abspath = path.join(repo_abspath, ".git", "info", "attributes") - key = tuple(self.get_path_components(repo_abspath, repo_abspath)) - - if key in exclude_patterns: - exclude_patterns[key].extend(read_attributes(local_attributes_abspath)) - else: - exclude_patterns[key] = read_attributes(local_attributes_abspath) - - return exclude_patterns - - def is_file_excluded(self, repo_abspath, repo_file_path, exclude_patterns): - """ - Checks whether file at a given path is excluded. - - @type repo_abspath: string - @param repo_abspath: Absolute path to the git repository. - - @type repo_file_path: string - @param repo_file_path: Path to a file within repo_abspath. - - @type exclude_patterns: dict - @param exclude_patterns: Exclude patterns with format specified for get_exclude_patterns. - - @rtype: bool - @return: True if file should be excluded. Otherwise False. - """ - if exclude_patterns is None or not len(exclude_patterns): - return False - - from fnmatch import fnmatch - - file_name = path.basename(repo_file_path) - components = self.get_path_components(repo_abspath, path.join(repo_abspath, path.dirname(repo_file_path))) - - is_excluded = False - # We should check all patterns specified in intermediate directories to the given file. - # At the end we should also check for the global patterns (key '()' or empty tuple). - while not is_excluded: - key = tuple(components) - if key in exclude_patterns: - patterns = exclude_patterns[key] - for p in patterns: - if fnmatch(file_name, p) or fnmatch(repo_file_path, p): - if self.verbose: - print("Exclude pattern matched {pattern}: {path}".format(pattern=p, path=repo_file_path)) - is_excluded = True - - if not len(components): - break - - components.pop() - - return is_excluded - - def list_files(self, repo_path=''): - """ - An iterator method that yields a file path relative to main_repo_abspath - for each file that should be included in the archive. - Skips those that match the exclusion patterns found in - any discovered .gitattributes files along the way. - - Recurs into submodules as well. - - @type repo_path: string - @param repo_path: Path to the git submodule repository within the main git repository. - - @rtype: iterator - @return: Iterator to traverse files under git control relative to main_repo_abspath. - """ - repo_abspath = path.join(self.main_repo_abspath, repo_path) - repo_file_paths = self.read_git_shell("git ls-files --cached --full-name --no-empty-directory", repo_abspath).splitlines() - exclude_patterns = self.get_exclude_patterns(repo_abspath, repo_file_paths) - - for repo_file_path in repo_file_paths: - # Git puts path in quotes if file path has unicode characters. - repo_file_path = repo_file_path.strip('"') # file path relative to current repo - file_name = path.basename(repo_file_path) - - # The symbolic link propertie is lost after extract the zip file - # Loop over files in the link dir and add them to file list - absfilepath = path.join(repo_abspath, repo_file_path) - if path.islink(absfilepath): - if path.isdir(absfilepath): - list_dirs = os.walk(absfilepath) - for root,dirs,files in list_dirs: - for file in files: - main_repo_file_path = os.path.relpath(path.join(root, file), self.main_repo_abspath) - yield main_repo_file_path - continue - # Only list symlinks and files that don't start with git. - elif path.isdir(repo_file_path): - continue - - main_repo_file_path = path.join(repo_path, repo_file_path) # file path relative to the main repo - - if self.is_file_excluded(repo_abspath, repo_file_path, exclude_patterns): - continue - - # Yield both repo_file_path and main_repo_file_path to preserve structure of the repo. - yield main_repo_file_path - - if self.force_sub: - self.run_shell("git submodule init", repo_abspath) - self.run_shell("git submodule update", repo_abspath) - - # List files of every submodule. - for submodule_path in self.read_shell("git submodule --quiet foreach 'pwd'", repo_abspath).splitlines(): - # In order to get output path we need to exclude repository path from submodule_path. - submodule_path = path.relpath(submodule_path, self.main_repo_abspath) - for file_path in self.list_files(submodule_path): - yield file_path - - @staticmethod - def run_shell(cmd, cwd=None): - """ - Runs shell command. - - @type cmd: string - @param cmd: Command to be executed. - - @type cwd: string - @param cwd: Working directory. - - @rtype: int - @return: Return code of the command. - - @raise CalledProcessError: Raises exception if return code of the command is non-zero. - """ - p = Popen(cmd, shell=True, cwd=cwd) - p.wait() - - if p.returncode: - raise CalledProcessError(returncode=p.returncode, cmd=cmd) - - return p.returncode - - @staticmethod - def read_shell(cmd, cwd=None, encoding='utf-8'): - """ - Runs shell command and reads output. - - @type cmd: string - @param cmd: Command to be executed. - - @type cwd: string - @param cwd: Working directory. - - @type encoding: string - @param encoding: Encoding used to decode bytes returned by Popen into string. - - @rtype: string - @return: Output of the command. - - @raise CalledProcessError: Raises exception if return code of the command is non-zero. - """ - p = Popen(cmd, shell=True, stdout=PIPE, cwd=cwd) - output, _ = p.communicate() - output = output.decode(encoding) - - if p.returncode: - raise CalledProcessError(returncode=p.returncode, cmd=cmd, output=output) - - return output - - @staticmethod - def read_git_shell(cmd, cwd=None): - """ - Runs git shell command, reads output and decodes it into unicode string - - @type cmd: string - @param cmd: Command to be executed. - - @type cwd: string - @param cwd: Working directory. - - @rtype: string - @return: Output of the command. - - @raise CalledProcessError: Raises exception if return code of the command is non-zero. - """ - p = Popen(cmd, shell=True, stdout=PIPE, cwd=cwd) - output, _ = p.communicate() - output = output.decode('unicode_escape').encode('raw_unicode_escape').decode('utf-8') - - if p.returncode: - raise CalledProcessError(returncode=p.returncode, cmd=cmd, output=output) - - return output - - -if __name__ == '__main__': - from optparse import OptionParser - - parser = OptionParser(usage="usage: %prog [-v] [--prefix PREFIX] [--no-exclude] [--force-submodules] [--dry-run] OUTPUT_FILE", - version="%prog {version}".format(version=__version__)) - - parser.add_option('--prefix', - type='string', - dest='prefix', - default='', - help="Prepend PREFIX to each filename in the archive. OUTPUT_FILE name is used by default to avoid tarbomb.") - - parser.add_option('-v', '--verbose', - action='store_true', - dest='verbose', - help='Enable verbose mode.') - - parser.add_option('--no-exclude', - action='store_false', - dest='exclude', - default=True, - help="Don't read .gitattributes files for patterns containing export-ignore attrib.") - - parser.add_option('--force-submodules', - action='store_true', - dest='force_sub', - help="Force a git submodule init && git submodule update at each level before iterating submodules.") - - parser.add_option('--extra', - action='append', - dest='extra', - default=[], - help="Any additional files to include in the archive.") - parser.add_option('--dry-run', - action='store_true', - dest='dry_run', - help="Don't actually archive anything, just show what would be done.") - - options, args = parser.parse_args() - - if len(args) != 1: - parser.error("You must specify exactly one output file") - - output_file_path = args[0] - - if path.isdir(output_file_path): - parser.error("You cannot use directory as output") - - # avoid tarbomb - if options.prefix: - options.prefix = path.join(options.prefix, '') - else: - import re - - output_name = path.basename(output_file_path) - output_name = re.sub('(\.zip|\.tar|\.tgz|\.gz|\.bz2|\.tar\.gz|\.tar\.bz2)$', '', output_name) or "Archive" - options.prefix = path.join(output_name, '') - - try: - archiver = GitArchiver(options.prefix, - options.verbose, - options.exclude, - options.force_sub, - options.extra) - archiver.create(output_file_path, options.dry_run) - except Exception as e: - traceback.print_exc() - parser.exit(2, "{exception}\n".format(exception=e)) - - sys.exit(0) diff --git a/native/tools/travis-scripts/before-install.sh b/native/tools/travis-scripts/before-install.sh deleted file mode 100755 index e839979304..0000000000 --- a/native/tools/travis-scripts/before-install.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -set -e - -# If not a pull request, setup for Linux only -if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then - echo "Should run when TRAVIS_PULL_REQUEST == false" - echo "Commit msg: $TRAVIS_COMMIT_MESSAGE" - echo "Stop process for TRAVIS_OS_NAME:$TRAVIS_OS_NAME && TRAVIS_PULL_REQUEST:$TRAVIS_PULL_REQUEST" - exit 0 -fi - - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../.. -HOST_NAME="" -set -x - - -function download_external() -{ - pushd $COCOS2DX_ROOT - #python download-deps.py -r=yes - cd $COCOS2DX_ROOT/external - external_version=`grep version config.json |awk -F'"' '{print $4}'` - external_repo_name=`grep name config.json |awk -F'"' '{print $4}'` - external_repo_parent=`grep owner config.json |awk -F'"' '{print $4}'` - rm * - git clone --branch $external_version --depth 1 https://github.com/$external_repo_parent/$external_repo_name . - #git checkout $external_version - git log --oneline -1 - popd -} - -function install_python_module() -{ - sudo easy_install pip - sudo -H pip install pyyaml - sudo -H pip install Cheetah -} - -#we only use osx for generate bindings - -download_external -install_python_module - -set +x \ No newline at end of file diff --git a/native/tools/travis-scripts/config.gitingore b/native/tools/travis-scripts/config.gitingore deleted file mode 100644 index 227c33f44c..0000000000 --- a/native/tools/travis-scripts/config.gitingore +++ /dev/null @@ -1,147 +0,0 @@ -#This configure file use .gitingore rules. -#So you can config this file like config .gitingore -# - -# Ignore thumbnails created by windows -Thumbs.db -.git - -/node_modules -/tools/make-package/cocos2d-x.zip -/simulator_*.zip -/prebuilt_*.zip - -# ignore copy files which not needed by new project -/lib -/linux-build -/samples -/tests -/plugin/samples -/tools -/utils -/simulator -/build/build -/cocos/bindings/proj.ios_mac/build/cocos2d_js_bindings.build - - -.gitattributes -.gitignore -.gitmodules -.travis.yml -/setup.py -/auto-build-src.bat -/auto-build.bat -/download-deps.py -/gulpfile.js -/package.json -/README.md - -# Ignore files build by Visual Studio -win32-msvc-vs201*-x86 -*.obj -*.exe -*.pdb -*.aps -*.vcproj.*.user -*.vspscc -*_i.c -*.i -*.icf -*_p.c -*.ncb -*.suo -*.tlb -*.tlh -*.bak -*.cache -*.ilk -*.log -[Bb]in -[Dd]ebug/ -[Dd]ebug.win32/ -*.sbr -*.sdf -obj/ -[Rr]elease/ -[Rr]elease.win32/ -_ReSharper*/ -[Tt]est[Rr]esult* -ipch/ -*.opensdf - -# Ignore files build by ndk and eclipse -bin/ -obj/ -gen/ -assets/ -local.properties - -# Ignore python compiled files -*.pyc - -# Ignore files build by airplay and marmalade -build_*_xcode/ -build_*_vc10/ - -# Ignore files build by xcode -*.mode*v* -*.pbxuser -*.xcbkptlist -*.xcscheme -*.xcworkspacedata -*.xcuserstate -*.xccheckout -xcschememanagement.plist -.DS_Store -._.* -xcuserdata/ -DerivedData/ - -# Ignore files built by AppCode -.idea/ - -# Ignore files built by bada -.Simulator-Debug/ -.Target-Debug/ -.Target-Release/ - -# Ignore files built by blackberry -Simulator/ -Device-Debug/ -Device-Release/ - -# Ignore vim swaps -*.swp -*.swo - -# Ignore files created by create_project.py -/projects - -# CTags -tags - -# Ignore web dir -/web - -#include -!/tools/cocos2d-console/console/bin/ -!/plugin-x/plugin-x_ios.xcworkspace/ -!/cocos/2d/platform/android/java/res/ -# Permit plugins to ship third-party libraries. -!/plugin/plugins/*/proj.android/libs/*.jar -!/plugin/plugins/*/proj.android/libs -!/tools/bindings-generator/tools/win32/* -!/cocos/platform/android/java/libs -!/cocos/platform/android/ControllerManualAdapter/libs -!/external/win32/libs/Debug/* - -/*.zip -v*-lua-runtime-*.zip - -# android build tmp files -/cocos/platform/android/libcocos2dx/.gradle -/cocos/platform/android/libcocos2dx/build -/cocos/platform/android/libcocos2dx/libcocos2dx.iml - -# xcode build tmp data -*build/XCBuildData diff --git a/native/tools/travis-scripts/for-each-file-in-dir.sh b/native/tools/travis-scripts/for-each-file-in-dir.sh deleted file mode 100755 index ad63b9062c..0000000000 --- a/native/tools/travis-scripts/for-each-file-in-dir.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# exit this script if any commmand fails -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT="$DIR"/../.. - -shopt -s dotglob - -echo_all_files() { - for file in $1/* - do - if [ -d "$file" ]; then - echo_all_files "$file" - else - relative_path="${file##*${PROJECT_ROOT}/}" - prefix=${relative_path:0:5} - if [ "$prefix"x != ".git/"x ]; then - echo "\"$relative_path\"," - fi - fi - done -} - -echo "[" -echo_all_files ${PROJECT_ROOT} -echo "]" - diff --git a/native/tools/travis-scripts/generate-pr.sh b/native/tools/travis-scripts/generate-pr.sh deleted file mode 100644 index d8a42dec25..0000000000 --- a/native/tools/travis-scripts/generate-pr.sh +++ /dev/null @@ -1,159 +0,0 @@ -#!/bin/bash - -# Generate script bindings for Cocos2D-X-lite -# ... using Android NDK system headers -# ... and push these changes to remote repos - -# Dependencies -# -# For bindings generator: -# (see tools/tojs/genbindings.py for the defaults used if the environment is not customized) -# -# * $PYTHON_BIN -# * $CLANG_ROOT -# * $NDK_ROOT -# - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_ROOT="$DIR/../.." -TRAVIS_ROOT="$PROJECT_ROOT/tools/travis-scripts" -JS_AUTO_GENERATED_DIR="$PROJECT_ROOT/cocos/bindings/auto" -COMMITTAG="[ci skip][AUTO]: updating jsbinding automatically: ${TRAVIS_COMMIT:0:8}" -ELAPSEDSECS=`date +%s` -COCOS_BRANCH="update_js_bindings_$ELAPSEDSECS" -COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x-lite.git" -PULL_REQUEST_REPO="https://api.github.com/repos/cocos-creator/engine-native/pulls" -FETCH_REMOTE_BRANCH=$1 -JS_COMMIT_PATH="cocos/bindings/auto" - -# Exit on error -set -e - -if [ "$TRAVIS_OS_NAME" == "windows" ]; then - export PATH="/c/Python27":$PATH -fi - - -if [ "$TRAVIS_OS_NAME" != "linux" ]; then - exit 0 -fi - -# if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then -# exit 0 -# fi - - -if [ -z "${GH_EMAIL}" ]; then - echo "GH_EMAIL not set" - exit 1 -fi -if [ -z "${GH_USER}" ]; then - echo "GH_USER not set" - exit 1 -fi -if [ -z "${GH_PASSWORD}" ]; then - echo "GH_PASSWORD not set" - exit 1 -fi - -pushd "$PROJECT_ROOT" -#Set git user for cocos2d-js repo -git config user.email ${GH_EMAIL} -git config user.name ${GH_USER} -popd - - -echo -echo Bindings generated successfully -echo - -echo -echo Using "'$COMMITTAG'" in the commit messages -echo - - -echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness - -# 2. In Bindings repo, Check if there are any files that are different from the index - -pushd "$PROJECT_ROOT" - -# Run status to record the output in the log -git status - -echo -echo Comparing with origin HEAD ... -echo - -git fetch origin ${FETCH_REMOTE_BRANCH} - -# Don't exit on non-zero return value -set +e - -git diff FETCH_HEAD --stat --exit-code ${JS_COMMIT_PATH} - -JS_DIFF_RETVAL=$? -if [ $JS_DIFF_RETVAL -eq 0 ] -then - echo - echo "No differences in generated files" - echo "Exiting with success." - echo - exit 0 -else - echo - echo "Generated files differ from HEAD. Continuing." - echo -fi - -# Exit on error -set -e - -set -x - -git add -f --all "$JS_AUTO_GENERATED_DIR" -git checkout -b "$COCOS_BRANCH" -git commit -m "$COMMITTAG" - -#Set remotes -git remote add upstream "$COCOS_ROBOT_REMOTE" 2> /dev/null > /dev/null -if $(git rev-parse --is-shallow-repository); then - git fetch --unshallow -fi -git fetch upstream --no-recurse-submodules - -echo "Pushing to Robot's repo ..." -# git push -fq upstream "$COCOS_BRANCH" 2> /dev/null -git push -fq upstream "$COCOS_BRANCH" - -echo " finish push ..." - -# set +x - -# 7. - -PY_SCRIPT=$(cat << EOF -import json -title='''${COMMITTAG}''' -body='''${TRAVIS_COMMIT_MESSAGE}''' -head='''${GH_USER}:${COCOS_BRANCH}''' -base='${TRAVIS_BRANCH}' - -dict = { - "title": title, - "head": head, - "body": body, - "base": base -} -print(json.dumps(dict)) -EOF -) - -POST_DATA=$(python -c "$PY_SCRIPT") - -echo "Sending Pull Request to base repo ..." -curl -u $GH_USER:$GH_PASSWORD --request POST --data "$POST_DATA" "${PULL_REQUEST_REPO}" # 2> /dev/null > /dev/null - -echo " finish sending PR ..." - -popd diff --git a/native/tools/travis-scripts/run-script.sh b/native/tools/travis-scripts/run-script.sh deleted file mode 100755 index 227daac7d4..0000000000 --- a/native/tools/travis-scripts/run-script.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash -set -e - -# If not a pull request, setup for Linux only -if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then - echo "Should run when TRAVIS_PULL_REQUEST == false" - echo "Stop process for TRAVIS_OS_NAME:$TRAVIS_OS_NAME && TRAVIS_PULL_REQUEST:$TRAVIS_PULL_REQUEST" - exit 0 -fi - - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../.. -TOJS_ROOT=$COCOS2DX_ROOT/tools/tojs - - -# to fix git error: shallow update not allowed -# https://stackoverflow.com/questions/28983842/remote-rejected-shallow-update-not-allowed-after-changing-git-remote-url -#git remote add old https://github.com/cocos-creator/cocos2d-x-lite -#git fetch --unshallow old - -set -x - - -ANDROID_SDK=$COCOS2DX_ROOT/../android/android_sdk -NDK_VERSION=21.3.6528147 -if [ -z "$NDK_ROOT" ]; then - export NDK_ROOT=$ANDROID_SDK/ndk/$NDK_VERSION -fi - -export ANDROID_HOME=$ANDROID_SDK -export ANDROID_NDK=$NDK_ROOT #installed in generate-bindings.sh -export ANDROID_NDK_HOME=$NDK_ROOT - -# Enable treat warning as error in CMakeList.txt -export COCOS_ENGINE_DEV=1 - - -generate_bindings_glue_codes() -{ - echo "Create auto-generated jsbinding glue codes." - pushd $TOJS_ROOT - python -V - python ./genbindings.py - rm userconf.ini - popd -} - - -function setup_linux_andorid_sdk() -{ - echo "Download Android SDK... " - cd $COCOS2DX_ROOT/.. - mkdir -p android - cd android - wget -t 5 -q https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip - unzip *.zip - yes | ./tools/bin/sdkmanager --sdk_root="$ANDROID_SDK" \ - "platforms;android-27" \ - "build-tools;28.0.3" \ - "platform-tools" \ - "tools" \ - "cmake;3.10.2.4988404" \ - "ndk;$NDK_VERSION" - cmake_dir=$ANDROID_SDK/cmake/3.10.2.4988404/bin - export PATH=$cmake_dir:$PATH -} - - - -setup_linux_andorid_sdk - -cd $COCOS2DX_ROOT/tools/travis-scripts -generate_bindings_glue_codes - - -cd $COCOS2DX_ROOT -## revert change -git clean -fdx ../templates -git checkout HEAD ../templates -set +x - -cd $COCOS2DX_ROOT/tools/travis-scripts -bash ./generate-pr.sh $TRAVIS_BRANCH -exit 0