From 58cdf07a35923070bfcfce529c170e3072459456 Mon Sep 17 00:00:00 2001 From: chuanweizhang2013 Date: Wed, 5 Mar 2014 18:31:31 +0800 Subject: [PATCH 01/10] add --- templates/cocos2dx_files.json.REMOVED.git-id | 1 - 1 file changed, 1 deletion(-) delete mode 100644 templates/cocos2dx_files.json.REMOVED.git-id diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id deleted file mode 100644 index 80626e1cff..0000000000 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -1283277b97cce107c19ac971a0648a5720e341c5 \ No newline at end of file From 4453e6e7fcdfd11a73dfad59eafa955372c7c5f4 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 6 Mar 2014 11:51:50 +0800 Subject: [PATCH 02/10] setup improve --- setup.py | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index e0bceedfed..707cda33cf 100755 --- a/setup.py +++ b/setup.py @@ -35,9 +35,9 @@ And it will read only one of them. So we will add environment variable in the sa Which means that * add environment variables into ~/.bash_profile if it exists * otherwise it will the add environment variables into ~/.bash_login if it exists -* otherwise it will the add environment variable sinto ~/.profile if it exists +* otherwise it will the add environment variables into ~/.profile if it exists -Will create ~/.bash_profile when none of them exist, and add environment variable into it. +Will create ~/.bash_profile when none of them exist, and add environment variables into it. ''' @@ -56,7 +56,6 @@ class SetEnvVar(object): self.ndk_root = ndk # whether the value of "ndk_root" is passed or not self.ndk_root_passed = False - self.file_to_write_environment = None self.file_used_for_setup = '' self.variable_found_in_env = False @@ -89,7 +88,7 @@ class SetEnvVar(object): else: file_to_write = os.path.join(home, '.bash_profile') - self.file_to_write_environment = file_to_write + self.file_used_for_setup = file_to_write file = open(file_to_write, 'a') if self.ndk_root_passed and self._find_string_in_file('export '.join(key), file_to_write): @@ -121,10 +120,7 @@ class SetEnvVar(object): try: result = os.environ[var] self.variable_found_in_env = true - if result: - return True - else: - return False + return True except Exception: string_to_search = 'export %s' % var home = os.path.expanduser('~') @@ -134,6 +130,7 @@ class SetEnvVar(object): if os.path.exists(path): if self._find_string_in_file(string_to_search, path): self.file_used_for_setup = path + self.variable_found_in_env = True return True # search it in ~/.bash_login @@ -141,6 +138,7 @@ class SetEnvVar(object): if os.path.exists(path): if self._find_string_in_file(string_to_search, path): self.file_used_for_setup = path + self.variable_found_in_env = True return True # search it in ~/.profile @@ -148,7 +146,10 @@ class SetEnvVar(object): if os.path.exists(path): if self._find_string_in_file(string_to_search, path): self.file_used_for_setup = path + self.variable_found_in_env = True return True + + self.variable_found_in_env = False return False def _get_ndk_root(self): @@ -164,21 +165,28 @@ class SetEnvVar(object): import tkFileDialog root = Tkinter.Tk() - self._center(root) def callback(): self.ndk_root = tkFileDialog.askdirectory() root.destroy() - frame = Tkinter.Frame(root) - Tkinter.Label(frame, text='Select path for NDK_ROOT:').pack(side=Tkinter.LEFT) - Tkinter.Button(frame, text='...', command=callback).pack(side=Tkinter.LEFT) - frame.pack() + label_content = """ +Please select path for NDK_ROOT. NDK is needed to develop Android native application. +More information of NDK please refer to https://developer.android.com/tools/sdk/ndk/index.html. +You can skip to it now without problem. But you will need it later to build the game for Android. + """ + + Tkinter.Label(root, text=label_content).pack() + Tkinter.Button(root, text='select ndk_root', command=callback).pack() + self._center(root) root.mainloop() - return True - - return False + if self.ndk_root: + return True + else: + return False + else: + return False # display a window in center and put it on top def _center(self, win): @@ -193,23 +201,25 @@ class SetEnvVar(object): def set_ndk_root(self, value): print '-> Adding NDK_ROOT environment variable...', - self.ndk_root_updated = False + ndk_root_updated = False if value: self.ndk_root = value - ndk_root_updated = True else: - ndk_root_updated = self._get_ndk_root() + ndk_root_selected = self._get_ndk_root() if self.ndk_root: os.environ[NDK_ROOT] = self.ndk_root self._set_environment_variable(NDK_ROOT, self.ndk_root) ndk_root_updated = True + print 'OK' else: ndk_root_updated = False + if not ndk_root_selected: + print 'SKIPPED' + else: + print 'ALREADY ADDED' - if ndk_root_updated: - print 'OK' return ndk_root_updated def set_console_root(self): @@ -246,9 +256,9 @@ class SetEnvVar(object): if console_updated or ndk_root_updated: result_string = '\nSet up successful:\n' if console_updated: - result_string += '\tCOCOS_CONSOLE_ROOT was added into %s.\n' % self.file_to_write_environment + result_string += '\tCOCOS_CONSOLE_ROOT was added into %s.\n' % self.file_used_for_setup if ndk_root_updated: - result_string += '\tNDK_ROOT was added into %s.\n' % self.file_to_write_environment + result_string += '\tNDK_ROOT was added into %s.\n' % self.file_used_for_setup print result_string else: From dfdb6c4158b80c6aa4dc12db9776044035d2a88b Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Mar 2014 13:54:24 +0800 Subject: [PATCH 03/10] [travis ci] Adds 'for-each-file-in-dir.sh' for generating file list in cocos2d. CocosRobot will send a PR for that change. --- .travis.yml | 1 + tools/travis-scripts/for-each-file-in-dir.sh | 29 ++++++++++++++++++++ tools/travis-scripts/generate-cocosfiles.sh | 14 ++++------ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100755 tools/travis-scripts/for-each-file-in-dir.sh diff --git a/.travis.yml b/.travis.yml index 2b2dceb5fb..4c07791079 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: cpp env: matrix: + - GEN_COCOS_FILES=YES - PLATFORM=linux DEBUG=1 CC_COMPILER=gcc CXX_COMPILER=g++ - PLATFORM=linux DEBUG=1 CC_COMPILER=clang CXX_COMPILER=clang++ # Since switching to C++11 only the ARM version of the nactive client diff --git a/tools/travis-scripts/for-each-file-in-dir.sh b/tools/travis-scripts/for-each-file-in-dir.sh new file mode 100755 index 0000000000..ad63b9062c --- /dev/null +++ b/tools/travis-scripts/for-each-file-in-dir.sh @@ -0,0 +1,29 @@ +#!/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/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 606f28fff7..2974ae325a 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -1,8 +1,8 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../.. -COCOSFILES_CREATOR_ROOT=$COCOS2DX_ROOT/tools/project-creator/config-create +PROJECT_ROOT="$DIR"/../.. + COMMITTAG="[AUTO][ci skip]" # Exit on error @@ -11,9 +11,7 @@ set -e generate_cocosfiles_json() { echo "Updates cocos_files.json" - pushd "$COCOSFILES_CREATOR_ROOT" - ./create_config.py - popd + ./for-each-file-in-dir.sh > ${PROJECT_ROOT}/templates/cocos2dx_files.json } if [ "$GEN_COCOS_FILES"x != "YES"x ]; then @@ -21,7 +19,7 @@ if [ "$GEN_COCOS_FILES"x != "YES"x ]; then exit 0 fi -pushd "$COCOS2DX_ROOT" +pushd "$PROJECT_ROOT" #Set git user for cocos2d-x repo git config user.email ${GH_EMAIL} git config user.name ${GH_USER} @@ -51,7 +49,7 @@ echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness # 2. Check if there are any files that are different from the index -pushd "$COCOS2DX_ROOT" +pushd "$PROJECT_ROOT" # Run status to record the output in the log git status @@ -88,7 +86,7 @@ COCOS_BRANCH=update_cocosfiles_"$ELAPSEDSECS" pushd "${DIR}" # 3. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings -cd "${COCOS2DX_ROOT}" +cd "${PROJECT_ROOT}" git add . git checkout -b "$COCOS_BRANCH" git commit -m "$COMMITTAG : updating tools/project-creator/module/cocos_files.json" From c206384eddd096669bd74b8554d881f51504816b Mon Sep 17 00:00:00 2001 From: lihex Date: Thu, 6 Mar 2014 13:56:18 +0800 Subject: [PATCH 04/10] rename template config file --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index cef397668e..c788443bab 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit cef397668e1220f2b9b4262ee18fcffedb8347ca +Subproject commit c788443babb3505c4668cb7079f0c9a0e450c6e0 From 738a4f5debdc7067d5cd98f368e211e6be78719a Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Mar 2014 14:00:48 +0800 Subject: [PATCH 05/10] Uncomments '.generate-cocosfiles.sh'. --- tools/travis-scripts/run-script.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index f3760f5da2..c51e52e067 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -32,14 +32,14 @@ if [ "$GEN_COCOS_FILES"x = "YES"x ]; then fi cd $COCOS2DX_ROOT/tools/travis-scripts - # ./generate-cocosfiles.sh + ./generate-cocosfiles.sh elif [ "$PLATFORM"x = "android"x ]; then export NDK_ROOT=$HOME/bin/android-ndk # Generate binding glue codes echo "Generating bindings glue codes ..." cd $COCOS2DX_ROOT/tools/travis-scripts - # ./generate-cocosfiles.sh + ./generate-cocosfiles.sh cd $COCOS2DX_ROOT @@ -66,7 +66,7 @@ elif [ "$PLATFORM"x = "linux"x ]; then # Generate binding glue codes echo "Generating bindings glue codes ..." cd $COCOS2DX_ROOT/tools/travis-scripts - # ./generate-cocosfiles.sh + ./generate-cocosfiles.sh echo "Building cocos2d-x" cd $COCOS2DX_ROOT/build @@ -79,7 +79,7 @@ elif [ "$PLATFORM"x = "emscripten"x ]; then # Generate binding glue codes echo "Generating bindings glue codes ..." cd $COCOS2DX_ROOT/tools/travis-scripts - # ./generate-cocosfiles.sh + ./generate-cocosfiles.sh cd $COCOS2DX_ROOT/build export PYTHON=/usr/bin/python @@ -88,7 +88,7 @@ elif [ "$PLATFORM"x = "emscripten"x ]; then EMCC_DEBUG=1 make PLATFORM=emscripten -j 8 elif [ "$PLATFORM"x = "ios"x ]; then cd $COCOS2DX_ROOT/tools/travis-scripts - # ./generate-cocosfiles.sh + ./generate-cocosfiles.sh cd $COCOS2DX_ROOT xctool/xctool.sh -project samples/Cpp/HelloCpp/proj.ios/HelloCpp.xcodeproj -scheme HelloCpp test From 5490e441922c47b5a4eb7fd2c59e96342bf154d1 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 6 Mar 2014 06:09:07 +0000 Subject: [PATCH 06/10] [AUTO][ci skip] : updating tools/project-creator/module/cocos_files.json --- templates/cocos2dx_files.json.REMOVED.git-id | 1 + 1 file changed, 1 insertion(+) create mode 100644 templates/cocos2dx_files.json.REMOVED.git-id diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id new file mode 100644 index 0000000000..1a8a41cef2 --- /dev/null +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -0,0 +1 @@ +c95c8696018ed9dbb68d20bb12242bfc8de6c273 \ No newline at end of file From 5ca25d854f6c5935ecc2762952b4a1d774de8b56 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Mar 2014 14:10:50 +0800 Subject: [PATCH 07/10] [travis ci] Updates generate-cocosfiles.sh. --- tools/travis-scripts/generate-cocosfiles.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 2974ae325a..55869cac59 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -3,7 +3,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_ROOT="$DIR"/../.. -COMMITTAG="[AUTO][ci skip]" +COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" +PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" +OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" + # Exit on error set -e @@ -11,7 +14,7 @@ set -e generate_cocosfiles_json() { echo "Updates cocos_files.json" - ./for-each-file-in-dir.sh > ${PROJECT_ROOT}/templates/cocos2dx_files.json + ./for-each-file-in-dir.sh > "${OUTPUT_FILE_PATH}" } if [ "$GEN_COCOS_FILES"x != "YES"x ]; then @@ -33,12 +36,6 @@ echo echo cocos_files.json was generated successfully echo - -if [ -z "${COMMITTAG+aaa}" ]; then -# ... if COMMITTAG is not set, use this machine's hostname - COMMITTAG=`hostname -s` -fi - echo echo Using "'$COMMITTAG'" in the commit messages echo @@ -85,11 +82,10 @@ COCOS_BRANCH=update_cocosfiles_"$ELAPSEDSECS" pushd "${DIR}" -# 3. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings cd "${PROJECT_ROOT}" git add . git checkout -b "$COCOS_BRANCH" -git commit -m "$COMMITTAG : updating tools/project-creator/module/cocos_files.json" +git commit -m "$COMMITTAG" #Set remotes git remote add upstream https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git 2> /dev/null > /dev/null # 4. In Cocos2D-X repo, Push the commit to cocos2d-x repository @@ -99,6 +95,6 @@ git push -fq upstream "$COCOS_BRANCH" 2> /dev/null # 5. echo "Sending Pull Request to base repo ..." -curl --user "${GH_USER}:${GH_PASSWORD}" --request POST --data "{ \"title\": \"$COMMITTAG : updating tools/project-creator/module/cocos_files.json\", \"body\": \"\", \"head\": \"${GH_USER}:${COCOS_BRANCH}\", \"base\": \"${TRAVIS_BRANCH}\"}" https://api.github.com/repos/cocos2d/cocos2d-x/pulls 2> /dev/null > /dev/null +curl --user "${GH_USER}:${GH_PASSWORD}" --request POST --data "{ \"title\": \"$COMMITTAG\", \"body\": \"\", \"head\": \"${GH_USER}:${COCOS_BRANCH}\", \"base\": \"${TRAVIS_BRANCH}\"}" "${PUSH_REPO}" 2> /dev/null > /dev/null popd From 56ceb4b6d55c12b2865fcaeeadaf67b15f5e2189 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 6 Mar 2014 14:44:33 +0800 Subject: [PATCH 08/10] update readme and release note --- README.md | 10 ++++++---- docs/RELEASE_NOTES.md | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7036f82ffb..2d27574bc5 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,15 @@ How to start a new game ----------------------- 1. Download the code from [cocos2d download site][4] -2. Enter `tools/project-creator` -3. Run the `create_project.py` script +2. Run `setup.py` +3. Run the `cocos` script Example: - $ cd cocos2d-x/tools/project-creator - $ ./create_project.py -n mygame -k com.your_company.mygame -l cpp -p /home/mygame + $ cd cocos2d-x + $ ./setup.py + $ source FILE_TO_SAVE_SYSTEM_VARIABLE + $ cocos new mygame -p com.your_company.mygame -l cpp -d /home/mygame $ cd /home/mygame ### Build new project for android ### diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.md index af6e495c10..5be76be356 100644 --- a/docs/RELEASE_NOTES.md +++ b/docs/RELEASE_NOTES.md @@ -76,7 +76,7 @@ * gcc 4.7 for Linux or Android. For Android ndk-r9 or newer is required. * Visual Studio 2012 (for Windows) -## Run samples +## How to run TestCpp ### Mac OSX & iOS @@ -94,7 +94,7 @@ Can run sample on Android in two ways: **By commnad** $ cd cocos2d-x - $ ./install.py + $ ./setup.py $ cd build $ ./android-build.py -p 10 $ adb install cocos2d-x/tests/proj.android/bin/TestDemo-debug.apk @@ -104,7 +104,7 @@ Then click item on Android device to run tests. Available value of `-p` is the A **Using Eclipse** $ cd cocos2d-x - $ ./install.py + $ ./setup.py $ cd build $ ./android-build.py @@ -139,6 +139,16 @@ Run $ cd bin/testcpp $ ./testcpp +## How to start a new game + + $ cd cocos2d-x + $ ./setup.py + $ source FILE_TO_RECORD_SYSTEM_VARIABLE +`FILE_TO_RECORD_SYSTEM_VARIABLE` may be `~/.bash_profile`, `~/.bash_login` or `~./.profile` + + $ cocos new MyGame -p com.MyCompany.MyGame -l cpp -d directory_to_save +Because `cocos run` command is not ready, so you should do it manually as running `TestCpp`. After `cocos run` command is finished, can just run `cocos run` to run the new game on demand target. + # Highlights of v3.0 From c2cd349da5dfdea8a5138566d0655b481de609eb Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 6 Mar 2014 14:56:22 +0800 Subject: [PATCH 09/10] Uses 'generate-tempate-files.py' to generate cocos2dx_files.json --- tools/travis-scripts/config.gitingore | 112 +++++++++++++ tools/travis-scripts/generate-cocosfiles.sh | 3 +- .../travis-scripts/generate-template-files.py | 149 ++++++++++++++++++ 3 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 tools/travis-scripts/config.gitingore create mode 100755 tools/travis-scripts/generate-template-files.py diff --git a/tools/travis-scripts/config.gitingore b/tools/travis-scripts/config.gitingore new file mode 100644 index 0000000000..e16be3535a --- /dev/null +++ b/tools/travis-scripts/config.gitingore @@ -0,0 +1,112 @@ +#This configure file use .gitingore rules. +#So you can config this file like config .gitingore +# + +# Ignore thumbnails created by windows +Thumbs.db +.git + +# ignore copy files +/lib +/linux-build +/samples +/templates +/tests +/plugin/samples +/tools + +.gitattributes +.gitignore +.gitmodules +.travis.yml +setup.py + +# 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 +libs/ +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 + +#include +!/tools/cocos2d-console/console/bin/ +!/plugin-x/plugin-x_ios.xcworkspace/ + diff --git a/tools/travis-scripts/generate-cocosfiles.sh b/tools/travis-scripts/generate-cocosfiles.sh index 55869cac59..1014bc303e 100755 --- a/tools/travis-scripts/generate-cocosfiles.sh +++ b/tools/travis-scripts/generate-cocosfiles.sh @@ -7,14 +7,13 @@ COMMITTAG="[AUTO][ci skip]: updating cocos2dx_files.json" PUSH_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls" OUTPUT_FILE_PATH="${PROJECT_ROOT}/templates/cocos2dx_files.json" - # Exit on error set -e generate_cocosfiles_json() { echo "Updates cocos_files.json" - ./for-each-file-in-dir.sh > "${OUTPUT_FILE_PATH}" + ./generate-template-files.py } if [ "$GEN_COCOS_FILES"x != "YES"x ]; then diff --git a/tools/travis-scripts/generate-template-files.py b/tools/travis-scripts/generate-template-files.py new file mode 100755 index 0000000000..ee974866be --- /dev/null +++ b/tools/travis-scripts/generate-template-files.py @@ -0,0 +1,149 @@ +#!/usr/bin/python +#coding=utf-8 +"""**************************************************************************** +Copyright (c) 2013 cocos2d-x.org + +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 +import sys +import re + +class CocosFileList: + """ + Function: + List cocos engine's files and save to "../module/cocos_file_list.json". + config "config.gitingore" file can set exclude or include files. + """ + + def __init__(self): + self.excludeConfig=[] + self.inludeConfig=[] + self.rootDir = "" + self.fileList=[] + + def readIngoreFile(self, fileName): + """ + Read configure file which use ".gitingore"'s rules. + """ + pfile = "" + try: + pfile = open(fileName, 'r') + except IOError: + return + + for line in pfile: + line = line.strip() + if not line or line[0] == "#": + continue + + #convert .gitingore regular expression to python's regular expression + line=line.replace('.', '\\.') + line=line.replace('*', '.*') + line="%s$" %line + if line[0] == "!": + self.inludeConfig.append(line[1:]) + else: + self.excludeConfig.append(line) + pfile.close() + + def parseFileList(self, rootDir): + self.rootDir = os.path.abspath(rootDir) + self.__parseFileList(rootDir) + + def __parseFileList(self, folderdir): + """ + """ + for item in os.listdir(folderdir): + path = os.path.join(folderdir, item) + relativePath = path[len(self.rootDir)+1:len(path)] + relativePath = relativePath.replace('\\', '/') + if os.path.isdir(path): + if ( + self.__bInclude("/%s" %relativePath) or + self.__bInclude("/%s/" %relativePath) or + self.__bInclude(item) or + self.__bInclude("%s/" %item) + ): + self.fileList.append("%s/" %relativePath) + continue + if ( + self.__bExclude("/%s" %relativePath) or + self.__bExclude("/%s/" %relativePath) or + self.__bExclude(item) or + self.__bExclude("%s/" %item) + ): + continue + self.__parseFileList(path) + else: + if ( + not self.__bInclude("/%s" %relativePath) and + not self.__bInclude(item) + ): + if ( + self.__bExclude("/%s" %relativePath) or + self.__bExclude(item) + ): + continue + # print(relativePath) + self.fileList.append(relativePath) + + def __bExclude(self, item): + bexclude = False + for index in range(len(self.excludeConfig)): + if re.match(self.excludeConfig[index], item): + bexclude = True + break + return bexclude + + def __bInclude(self, item): + binclude = False + for index in range(len(self.inludeConfig)): + if re.match(self.inludeConfig[index], item): + binclude = True + break + return binclude + + def writeFileList(self,fileName): + """ + Save content to file with json format. + """ + f = open(fileName,"w") + self.fileList.sort() + content = "[\n\"%s\"\n]" % ("\",\n\"".join(self.fileList)) + f.write(content) + f.close() + return True + +# ------------ main -------------- +if __name__ == '__main__': + + cocos_root =os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + cocos_file_path =os.path.abspath(os.path.join(cocos_root, "templates", "cocos2dx_files.json")) + cocos_file_ingore =os.path.abspath(os.path.join(os.path.dirname(__file__), "config.gitingore")) + # print ("begin list files") + cocosObj = CocosFileList() + cocosObj.readIngoreFile(cocos_file_ingore) + cocosObj.parseFileList(cocos_root) + cocosObj.writeFileList(cocos_file_path) + # print ("had list files to cocos_file_list.json") + From e95ce5ab3da6f3afcadaaa50695f3a5b571862f3 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 6 Mar 2014 06:59:49 +0000 Subject: [PATCH 10/10] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cocos2dx_files.json.REMOVED.git-id b/templates/cocos2dx_files.json.REMOVED.git-id index 1a8a41cef2..43b9fbd38c 100644 --- a/templates/cocos2dx_files.json.REMOVED.git-id +++ b/templates/cocos2dx_files.json.REMOVED.git-id @@ -1 +1 @@ -c95c8696018ed9dbb68d20bb12242bfc8de6c273 \ No newline at end of file +b8e377ea1413a393a14914cae394a4d6a414b2c4 \ No newline at end of file