diff options
Diffstat (limited to 'objectivec/DevTools')
-rwxr-xr-x | objectivec/DevTools/check_version_stamps.sh | 67 | ||||
-rwxr-xr-x | objectivec/DevTools/compile_testing_protos.sh | 124 | ||||
-rwxr-xr-x | objectivec/DevTools/full_mac_build.sh | 169 | ||||
-rwxr-xr-x | objectivec/DevTools/pddm.py | 24 | ||||
-rwxr-xr-x | objectivec/DevTools/pddm_tests.py | 6 |
5 files changed, 239 insertions, 151 deletions
diff --git a/objectivec/DevTools/check_version_stamps.sh b/objectivec/DevTools/check_version_stamps.sh index 325b71dd..1acbe2a2 100755 --- a/objectivec/DevTools/check_version_stamps.sh +++ b/objectivec/DevTools/check_version_stamps.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -eu # This script checks that the runtime version number constant in the compiler # source and in the runtime source is the same. @@ -8,8 +8,6 @@ # builds would break. At the same time, we don't want the runtime source # depending on the compiler sources; so two copies of the constant are needed. -set -eu - readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") readonly ProtoRootDir="${ScriptDir}/../.." @@ -18,39 +16,40 @@ die() { exit 1 } -readonly ConstantName=GOOGLE_PROTOBUF_OBJC_GEN_VERSION - -# Collect version from plugin sources. - -readonly PluginSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc" -readonly PluginVersion=$( \ - cat "${PluginSrc}" \ - | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p" -) - -if [[ -z "${PluginVersion}" ]] ; then - die "Failed to find ${ConstantName} in the plugin source (${PluginSrc})." -fi - -# Collect version from runtime sources. - +readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc" readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h" -readonly RuntimeVersion=$( \ - cat "${RuntimeSrc}" \ - | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p" -) - -if [[ -z "${RuntimeVersion}" ]] ; then - die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})." -fi - -# Compare them. -if [[ "${PluginVersion}" != "${RuntimeVersion}" ]] ; then - die "Versions don't match! - Plugin: ${PluginVersion} from ${PluginSrc} - Runtime: ${RuntimeVersion} from ${RuntimeSrc} +check_constant() { + local ConstantName="$1" + + # Collect version from generator sources. + local GeneratorVersion=$( \ + cat "${GeneratorSrc}" \ + | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p" + ) + if [[ -z "${GeneratorVersion}" ]] ; then + die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})." + fi + + # Collect version from runtime sources. + local RuntimeVersion=$( \ + cat "${RuntimeSrc}" \ + | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p" + ) + if [[ -z "${RuntimeVersion}" ]] ; then + die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})." + fi + + # Compare them. + if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then + die "${ConstantName} values don't match! + Generator: ${GeneratorVersion} from ${GeneratorSrc} + Runtime: ${RuntimeVersion} from ${RuntimeSrc} " -fi + fi +} + +# Do the check. +check_constant GOOGLE_PROTOBUF_OBJC_VERSION # Success diff --git a/objectivec/DevTools/compile_testing_protos.sh b/objectivec/DevTools/compile_testing_protos.sh index e9c5fe61..d7f3f605 100755 --- a/objectivec/DevTools/compile_testing_protos.sh +++ b/objectivec/DevTools/compile_testing_protos.sh @@ -1,17 +1,16 @@ -#!/bin/bash - +#!/bin/bash -eu # Invoked by the Xcode projects to build the protos needed for the unittests. -set -eu - readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos" +# ----------------------------------------------------------------------------- # Helper for bailing. die() { echo "Error: $1" exit 2 } +# ----------------------------------------------------------------------------- # What to do. case "${ACTION}" in "") @@ -26,12 +25,19 @@ case "${ACTION}" in ;; esac -# Move to the top of the protobuf directories. -cd "${SRCROOT}/.." +# ----------------------------------------------------------------------------- +# Ensure the output dir exists +mkdir -p "${OUTPUT_DIR}/google/protobuf" +# ----------------------------------------------------------------------------- +# Move to the top of the protobuf directories and ensure there is a protoc +# binary to use. +cd "${SRCROOT}/.." [[ -x src/protoc ]] || \ die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)." +# ----------------------------------------------------------------------------- +# See the compiler or proto files have changed. RUN_PROTOC=no if [[ ! -d "${OUTPUT_DIR}" ]] ; then RUN_PROTOC=yes @@ -50,7 +56,7 @@ else # Find the oldest output file. readonly OldestOutput=$(find \ "${OUTPUT_DIR}" \ - -type f -print0 \ + -type f -name "*pbobjc.[hm]" -print0 \ | xargs -0 stat -f "%m %N" \ | sort -n -r | tail -n1 | cut -f2- -d" ") # If the newest input is newer than the oldest output, regenerate. @@ -64,54 +70,80 @@ if [[ "${RUN_PROTOC}" != "yes" ]] ; then exit 0 fi -# Ensure the output dir exists -mkdir -p "${OUTPUT_DIR}/google/protobuf" +# ----------------------------------------------------------------------------- +# Prune out all the files from previous generations to ensure we only have +# current ones. +find "${OUTPUT_DIR}" \ + -type f -name "*pbobjc.[hm]" -print0 \ + | xargs -0 rm -rf -CORE_PROTO_FILES=( \ - src/google/protobuf/unittest_arena.proto \ - src/google/protobuf/unittest_custom_options.proto \ - src/google/protobuf/unittest_enormous_descriptor.proto \ - src/google/protobuf/unittest_embed_optimize_for.proto \ - src/google/protobuf/unittest_empty.proto \ - src/google/protobuf/unittest_import.proto \ - src/google/protobuf/unittest_import_lite.proto \ - src/google/protobuf/unittest_lite.proto \ - src/google/protobuf/unittest_mset.proto \ - src/google/protobuf/unittest_mset_wire_format.proto \ - src/google/protobuf/unittest_no_arena.proto \ - src/google/protobuf/unittest_no_arena_import.proto \ - src/google/protobuf/unittest_no_generic_services.proto \ - src/google/protobuf/unittest_optimize_for.proto \ - src/google/protobuf/unittest.proto \ - src/google/protobuf/unittest_import_public.proto \ - src/google/protobuf/unittest_import_public_lite.proto \ - src/google/protobuf/unittest_drop_unknown_fields.proto \ - src/google/protobuf/unittest_preserve_unknown_enum.proto \ - src/google/protobuf/map_lite_unittest.proto \ - src/google/protobuf/map_proto2_unittest.proto \ - src/google/protobuf/map_unittest.proto \ -) - -compile_proto() { +# ----------------------------------------------------------------------------- +# Helper to invoke protoc +compile_protos() { src/protoc \ --objc_out="${OUTPUT_DIR}/google/protobuf" \ --proto_path=src/google/protobuf/ \ --proto_path=src \ - $* + "$@" } +# ----------------------------------------------------------------------------- +# Generate most of the proto files that exist in the C++ src tree. Several +# are used in the tests, but the extra don't hurt in that they ensure ObjC +# sources can be generated from them. + +CORE_PROTO_FILES=( + src/google/protobuf/any_test.proto + src/google/protobuf/unittest_arena.proto + src/google/protobuf/unittest_custom_options.proto + src/google/protobuf/unittest_enormous_descriptor.proto + src/google/protobuf/unittest_embed_optimize_for.proto + src/google/protobuf/unittest_empty.proto + src/google/protobuf/unittest_import.proto + src/google/protobuf/unittest_import_lite.proto + src/google/protobuf/unittest_lite.proto + src/google/protobuf/unittest_mset.proto + src/google/protobuf/unittest_mset_wire_format.proto + src/google/protobuf/unittest_no_arena.proto + src/google/protobuf/unittest_no_arena_import.proto + src/google/protobuf/unittest_no_generic_services.proto + src/google/protobuf/unittest_optimize_for.proto + src/google/protobuf/unittest.proto + src/google/protobuf/unittest_import_public.proto + src/google/protobuf/unittest_import_public_lite.proto + src/google/protobuf/unittest_drop_unknown_fields.proto + src/google/protobuf/unittest_preserve_unknown_enum.proto + src/google/protobuf/map_lite_unittest.proto + src/google/protobuf/map_proto2_unittest.proto + src/google/protobuf/map_unittest.proto + # The unittest_custom_options.proto extends the messages in descriptor.proto + # so we build it in to test extending in general. The library doesn't provide + # a descriptor as it doesn't use the classes/enums. + src/google/protobuf/descriptor.proto +) + +# Note: there is overlap in package.Message names between some of the test +# files, so they can't be generated all at once. This works because the overlap +# isn't linked into a single binary. for a_proto in "${CORE_PROTO_FILES[@]}" ; do - compile_proto "${a_proto}" + compile_protos "${a_proto}" done -OBJC_PROTO_FILES=( \ - objectivec/Tests/unittest_cycle.proto \ +# ----------------------------------------------------------------------------- +# Generate the Objective C specific testing protos. +compile_protos \ + --proto_path="objectivec/Tests" \ + objectivec/Tests/unittest_cycle.proto \ + objectivec/Tests/unittest_deprecated.proto \ + objectivec/Tests/unittest_deprecated_file.proto \ + objectivec/Tests/unittest_extension_chain_a.proto \ + objectivec/Tests/unittest_extension_chain_b.proto \ + objectivec/Tests/unittest_extension_chain_c.proto \ + objectivec/Tests/unittest_extension_chain_d.proto \ + objectivec/Tests/unittest_extension_chain_e.proto \ + objectivec/Tests/unittest_extension_chain_f.proto \ + objectivec/Tests/unittest_extension_chain_g.proto \ objectivec/Tests/unittest_runtime_proto2.proto \ objectivec/Tests/unittest_runtime_proto3.proto \ - objectivec/Tests/unittest_objc.proto \ - objectivec/Tests/unittest_objc_startup.proto \ -) - -for a_proto in "${OBJC_PROTO_FILES[@]}" ; do - compile_proto --proto_path="objectivec/Tests" "${a_proto}" -done + objectivec/Tests/unittest_objc.proto \ + objectivec/Tests/unittest_objc_startup.proto diff --git a/objectivec/DevTools/full_mac_build.sh b/objectivec/DevTools/full_mac_build.sh index c8681e26..c673fcba 100755 --- a/objectivec/DevTools/full_mac_build.sh +++ b/objectivec/DevTools/full_mac_build.sh @@ -26,8 +26,9 @@ OPTIONS: Issue a clean before the normal build. -a, --autogen Start by rerunning autogen & configure. - -r, --regenerate-cpp-descriptors - The descriptor.proto is checked in generated, cause it to regenerate. + -r, --regenerate-descriptors + Run generate_descriptor_proto.sh to regenerate all the checked in + proto sources. -j #, --jobs # Force the number of parallel jobs (useful for debugging build issues). --core-only @@ -36,10 +37,16 @@ OPTIONS: Skip the invoke of Xcode to test the runtime on both iOS and OS X. --skip-xcode-ios Skip the invoke of Xcode to test the runtime on iOS. + --skip-xcode-debug + Skip the Xcode Debug configuration. + --skip-xcode-release + Skip the Xcode Release configuration. --skip-xcode-osx Skip the invoke of Xcode to test the runtime on OS X. --skip-objc-conformance Skip the Objective C conformance tests (run on OS X). + --xcode-quiet + Pass -quiet to xcodebuild. EOF } @@ -65,17 +72,20 @@ wrapped_make() { } NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu) -if [[ "${NUM_MAKE_JOBS}" -lt 4 ]] ; then - NUM_MAKE_JOBS=4 +if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then + NUM_MAKE_JOBS=2 fi DO_AUTOGEN=no DO_CLEAN=no -REGEN_CPP_DESCRIPTORS=no +REGEN_DESCRIPTORS=no CORE_ONLY=no DO_XCODE_IOS_TESTS=yes DO_XCODE_OSX_TESTS=yes +DO_XCODE_DEBUG=yes +DO_XCODE_RELEASE=yes DO_OBJC_CONFORMANCE_TESTS=yes +XCODE_QUIET=no while [[ $# != 0 ]]; do case "${1}" in -h | --help ) @@ -88,8 +98,8 @@ while [[ $# != 0 ]]; do -a | --autogen ) DO_AUTOGEN=yes ;; - -r | --regenerate-cpp-descriptors ) - REGEN_CPP_DESCRIPTORS=yes + -r | --regenerate-descriptors ) + REGEN_DESCRIPTORS=yes ;; -j | --jobs ) shift @@ -108,9 +118,18 @@ while [[ $# != 0 ]]; do --skip-xcode-osx ) DO_XCODE_OSX_TESTS=no ;; + --skip-xcode-debug ) + DO_XCODE_DEBUG=no + ;; + --skip-xcode-release ) + DO_XCODE_RELEASE=no + ;; --skip-objc-conformance ) DO_OBJC_CONFORMANCE_TESTS=no ;; + --xcode-quiet ) + XCODE_QUIET=yes + ;; -*) echo "ERROR: Unknown option: ${1}" 1>&2 printUsage @@ -150,8 +169,12 @@ if [[ "${DO_CLEAN}" == "yes" ]] ; then -project objectivec/ProtocolBuffers_iOS.xcodeproj -scheme ProtocolBuffers ) - "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean - "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean + if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then + "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean + fi + if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then + "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean + fi fi if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then XCODEBUILD_CLEAN_BASE_OSX=( @@ -159,13 +182,17 @@ if [[ "${DO_CLEAN}" == "yes" ]] ; then -project objectivec/ProtocolBuffers_OSX.xcodeproj -scheme ProtocolBuffers ) - "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean - "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean + if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then + "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean + fi + if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then + "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean + fi fi fi -if [[ "${REGEN_CPP_DESCRIPTORS}" == "yes" ]] ; then - header "Regenerating the C++ descriptor sources." +if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then + header "Regenerating the descriptor sources." ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}" fi @@ -184,29 +211,8 @@ else cd .. fi -header "Ensuring the ObjC descriptors are current." -# Find the newest input file (protos, compiler, and the generator script). -# (these patterns catch some extra stuff, but better to over sample than under) -readonly NewestInput=$(find \ - src/google/protobuf/*.proto \ - src/.libs src/*.la src/protoc \ - objectivec/generate_descriptors_proto.sh \ - -type f -print0 \ - | xargs -0 stat -f "%m %N" \ - | sort -n | tail -n1 | cut -f2- -d" ") -# Find the oldest output file. -readonly OldestOutput=$(find \ - "${ProtoRootDir}/objectivec/google" \ - -type f -print0 \ - | xargs -0 stat -f "%m %N" \ - | sort -n -r | tail -n1 | cut -f2- -d" ") -# If the newest input is newer than the oldest output, regenerate. -if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then - echo ">> Newest input is newer than oldest output, regenerating." - objectivec/generate_descriptors_proto.sh -j "${NUM_MAKE_JOBS}" -else - echo ">> Newest input is older than oldest output, no need to regenerating." -fi +# Ensure the WKT sources checked in are current. +objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}" header "Checking on the ObjC Runtime Code" objectivec/DevTools/pddm_tests.py @@ -217,50 +223,78 @@ if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*. exit 1 fi +readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )" +readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix. + if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then XCODEBUILD_TEST_BASE_IOS=( xcodebuild -project objectivec/ProtocolBuffers_iOS.xcodeproj -scheme ProtocolBuffers ) + if [[ "${XCODE_QUIET}" == "yes" ]] ; then + XCODEBUILD_TEST_BASE_IOS+=( -quiet ) + fi # Don't need to worry about form factors or retina/non retina; # just pick a mix of OS Versions and 32/64 bit. # NOTE: Different Xcode have different simulated hardware/os support. - readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )" - readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix. - IOS_SIMULATOR_NAME="Simulator" case "${XCODE_VERSION}" in 6.* ) - echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 7.0 or higher." 1>&2 + echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2 exit 10 ;; - 7.1* ) + 7.* ) + echo "ERROR: Xcode 7.x no longer supported for building, please use 8.0 or higher." 1>&2 + exit 11 + ;; + 8.0* ) + # The 8.* device seem to hang and never start under Xcode 8. + XCODEBUILD_TEST_BASE_IOS+=( + -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=10.0" # 64bit + ) + ;; + 8.[1-3]* ) XCODEBUILD_TEST_BASE_IOS+=( -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPhone 6,OS=9.0" # 64bit - -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPad Air,OS=9.0" # 64bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit ) ;; - 7.* ) + 9.[0-2]* ) XCODEBUILD_TEST_BASE_IOS+=( -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit - -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit + # 9.0-9.2 all seem to often fail running destinations in parallel + -disable-concurrent-testing + ) + ;; + 9.3* ) + XCODEBUILD_TEST_BASE_IOS+=( + # Xcode 9.3 chokes targeting iOS 8.x - http://www.openradar.me/39335367 + -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit + # 9.3 also seems to often fail running destinations in parallel + -disable-concurrent-testing ) ;; * ) - echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}" + echo "" + echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}" + echo "" + echo "Build aborted!" exit 2 ;; esac - header "Doing Xcode iOS build/tests - Debug" - "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test - header "Doing Xcode iOS build/tests - Release" - "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test + if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then + header "Doing Xcode iOS build/tests - Debug" + "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test + fi + if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then + header "Doing Xcode iOS build/tests - Release" + "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test + fi # Don't leave the simulator in the developer's face. - killall "${IOS_SIMULATOR_NAME}" + killall Simulator 2> /dev/null || true fi if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then XCODEBUILD_TEST_BASE_OSX=( @@ -270,13 +304,32 @@ if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported. -destination "platform=OS X,arch=x86_64" # 64bit ) - header "Doing Xcode OS X build/tests - Debug" - "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test - header "Doing Xcode OS X build/tests - Release" - "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test + if [[ "${XCODE_QUIET}" == "yes" ]] ; then + XCODEBUILD_TEST_BASE_OSX+=( -quiet ) + fi + case "${XCODE_VERSION}" in + 6.* ) + echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2 + exit 10 + ;; + 7.* ) + echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2 + echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2 + exit 11 + ;; + esac + if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then + header "Doing Xcode OS X build/tests - Debug" + "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test + fi + if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then + header "Doing Xcode OS X build/tests - Release" + "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test + fi fi if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then + header "Running ObjC Conformance Tests" cd conformance wrapped_make -j "${NUM_MAKE_JOBS}" test_objc cd .. diff --git a/objectivec/DevTools/pddm.py b/objectivec/DevTools/pddm.py index 9a11fec4..0b5b7b40 100755 --- a/objectivec/DevTools/pddm.py +++ b/objectivec/DevTools/pddm.py @@ -124,6 +124,7 @@ def _MacroRefRe(macro_names): return re.compile(r'\b(?P<macro_ref>(?P<name>(%s))\((?P<args>.*?)\))' % '|'.join(macro_names)) + def _MacroArgRefRe(macro_arg_names): # Takes in a list of macro arg names and makes a regex that will match # uses of those args. @@ -318,25 +319,26 @@ class MacroCollection(object): return macro.body assert len(arg_values) == len(macro.args) args = dict(zip(macro.args, arg_values)) + def _lookupArg(match): val = args[match.group('name')] opt = match.group('option') if opt: - if opt == 'S': # Spaces for the length + if opt == 'S': # Spaces for the length return ' ' * len(val) - elif opt == 'l': # Lowercase first character + elif opt == 'l': # Lowercase first character if val: return val[0].lower() + val[1:] else: return val - elif opt == 'L': # All Lowercase + elif opt == 'L': # All Lowercase return val.lower() - elif opt == 'u': # Uppercase first character + elif opt == 'u': # Uppercase first character if val: return val[0].upper() + val[1:] else: return val - elif opt == 'U': # All Uppercase + elif opt == 'U': # All Uppercase return val.upper() else: raise PDDMError('Unknown arg option "%s$%s" while expanding "%s".%s' @@ -350,6 +352,7 @@ class MacroCollection(object): def _EvalMacrosRefs(self, text, macro_stack): macro_ref_re = _MacroRefRe(self._macros.keys()) + def _resolveMacro(match): return self._Expand(match, macro_stack) return macro_ref_re.sub(_resolveMacro, text) @@ -496,9 +499,10 @@ class SourceFile(object): # Add the ending marker. if len(captured_lines) == 1: result.append('//%%PDDM-EXPAND-END %s' % - captured_lines[0][directive_len:].strip()) + captured_lines[0][directive_len:].strip()) else: - result.append('//%%PDDM-EXPAND-END (%s expansions)' % len(captured_lines)) + result.append('//%%PDDM-EXPAND-END (%s expansions)' % + len(captured_lines)) return result @@ -669,15 +673,15 @@ def main(args): if src_file.processed_content != src_file.original_content: if not opts.dry_run: - print 'Updating for "%s".' % a_path + print('Updating for "%s".' % a_path) with open(a_path, 'w') as f: f.write(src_file.processed_content) else: # Special result to indicate things need updating. - print 'Update needed for "%s".' % a_path + print('Update needed for "%s".' % a_path) result = 1 elif opts.verbose: - print 'No update for "%s".' % a_path + print('No update for "%s".' % a_path) return result diff --git a/objectivec/DevTools/pddm_tests.py b/objectivec/DevTools/pddm_tests.py index 8a73b842..9ac6a855 100755 --- a/objectivec/DevTools/pddm_tests.py +++ b/objectivec/DevTools/pddm_tests.py @@ -311,7 +311,7 @@ foo(x, y) mc = pddm.MacroCollection(f) try: result = mc.Expand('foo(A,B)') - self.fail('Should throw exception, entry %d' % idx) + self.fail('Should throw exception! Test failed to catch recursion.') except pddm.PDDMError as e: self.assertEqual(e.message, 'Found macro recusion, invoking "foo(1, A)":\n...while expanding "bar(1, A)".\n...while expanding "foo(A,B)".') @@ -483,7 +483,7 @@ foo sf = pddm.SourceFile(f) try: sf.ProcessContent() - self.fail('Should throw exception, entry %d' % idx) + self.fail('Should throw exception! Test failed to catch macro parsing error.') except pddm.PDDMError as e: self.assertEqual(e.message, 'Attempt to redefine macro: "PDDM-DEFINE mumble(x_)"\n' @@ -503,7 +503,7 @@ foo sf = pddm.SourceFile(f) try: sf.ProcessContent() - self.fail('Should throw exception, entry %d' % idx) + self.fail('Should throw exception! Test failed to catch expand error.') except pddm.PDDMError as e: self.assertEqual(e.message, 'No macro named "foobar".\n' |