Skip to content

Commit

Permalink
added flags to generate_code.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaileychess committed Oct 6, 2021
1 parent 1aab5af commit f0b19b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Expand Up @@ -114,6 +114,7 @@ jobs:
- name: cmake
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release . && make -j4
- name: Generate
run: scripts/check_generate_code.py
run: bash scripts/check-grpc-generated-code.sh

build-java:
Expand Down
13 changes: 8 additions & 5 deletions CMakeLists.txt
Expand Up @@ -483,22 +483,25 @@ endfunction()
# Look if we have python 3 installed so that we can run the generate code python
# script after flatc is built.
find_package(PythonInterp 3)
if(PYTHONINTERP_FOUND AND
# Skip doing this if the MSVC version is below VS 12.
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
(WIN32 AND MSVC_VERSION GREATER 1800))
if(PYTHONINTERP_FOUND)
if(WIN32)
set(GENERATION_SCRIPT py scripts/generate_code.py)
if(MSVC_VERSION LESS 1700)
# Need to set --cpp-std c++-0x option for older MSVC compilers.
set(GENERATION_SCRIPT "${GENERATION_SCRIPT}" --cpp-0x)
endif()
else()
set(GENERATION_SCRIPT scripts/generate_code.py)
endif()
add_custom_command(
TARGET flatc
POST_BUILD
COMMAND ${GENERATION_SCRIPT} "${FLATBUFFERS_FLATC_EXECUTABLE}"
COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating code..."
VERBATIM)
else()
message("No Python3 interpreter found! Unable to generate files automatically.")
endif()

if(FLATBUFFERS_BUILD_TESTS)
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Expand Up @@ -16,7 +16,7 @@ environment:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_VS_VERSION: "10 2010"
CMAKE_OPTIONS: "-DFLATBUFFERS_BUILD_LEGACY=1"
CPP_TEST_OPTIONS: "--std-cpp c++0x"
CPP_TEST_OPTIONS: "--cpp-0x"
MONSTER_EXTRA: "skip"

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
Expand Down Expand Up @@ -54,7 +54,7 @@ install:
- ps: Install-Product node $env:nodejs_version

test_script:
- call py scripts/check_generate_code.py
- call py scripts/check_generate_code.py "%CPP_TEST_OPTIONS%"
- "cd tests"
- 7z a GeneratedMyGameCode.zip MyGame\
- rem "---------------- C++ -----------------"
Expand Down
16 changes: 13 additions & 3 deletions scripts/generate_code.py
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import filecmp
import glob
import platform
Expand All @@ -22,6 +23,14 @@
import sys
from pathlib import Path

parser = argparse.ArgumentParser()
parser.add_argument(
"--flatc",
help="path of the Flat C compiler relative to the root directory",
)
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
args = parser.parse_args()

# Get the path where this script is located so we can invoke the script from
# any directory and have the paths work correctly.
script_path = Path(__file__).parent.resolve()
Expand All @@ -33,8 +42,8 @@
# argument or defaulting to default names.
flatc_exe = Path(
("flatc" if not platform.system() == "Windows" else "flatc.exe")
if len(sys.argv) <= 1
else sys.argv[1]
if not args.flatc
else args.flatc
)

# Find and assert flatc compiler is present.
Expand Down Expand Up @@ -79,7 +88,8 @@ def glob(path, pattern):
"--gen-compare",
"--cpp-ptr-type",
"flatbuffers::unique_ptr",
]
] + (["--cpp-std", "c++0x"] if args.cpp_0x else [])

CPP_17_OPTS = NO_INCL_OPTS + [
"--cpp",
"--cpp-std",
Expand Down

0 comments on commit f0b19b1

Please sign in to comment.