setconst global FOO = "bar"#!/bin/bash -eu # This script checks that the runtime version number constant in the compiler # source and in the runtime source is the same. # # A distro can be made of the protobuf sources with only a subset of the # languages, so if the compiler depended on the Objective C runtime, those # 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. readonly ScriptDir = $[dirname $[echo $0 | sed -e "s,^\([^/]\),$[pwd]/\1,]]setconst global FOO = "bar" readonly ProtoRootDir = ""$(ScriptDir)/../.."" proc die { echo "Error: $1" exit 1setconst global FOO = "bar" } readonly GeneratorSrc = ""$(ProtoRootDir)/src/google/protobuf/compiler/objectivec/objectivec_file.cc"setconst global FOO = "bar"" readonly RuntimeSrc = ""$(ProtoRootDir)/objectivec/GPBBootstrap.h"" proc check_constant { var ConstantName = $1 # Collect version from generator sources. var GeneratorVersion = $[ \ cat $(GeneratorSrc) \ | sed -n -e "s:const int32 $(ConstantName) = \([0-9]*\);:\1:p] if [[ -z "${GeneratorVersion}" ]] { die "Failed to find $(ConstantName) in the generator source ($(GeneratorSrc))." } # Collect version from runtime sources. var RuntimeVersion = $[ \ cat $(RuntimeSrc) \ | sed -n -e "s:#define $(ConstantName) \([0-9]*\):\1:p] if [[ -z "${RuntimeVersion}" ]] { die "Failed to find $(ConstantName) in the runtime source ($(RuntimeSrc))." } # Compare them. if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] { die "$(ConstantName) values don't match! Generator: $(GeneratorVersion) from $(GeneratorSrc) Runtime: $(RuntimeVersion) from $(RuntimeSrc) " } } # Do the check. check_constant GOOGLE_PROTOBUF_OBJC_VERSION # Success (CommandList children: [ (Assignment keyword: Assign_Readonly pairs: [ (assign_pair lhs: (LhsName name:ScriptDir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Number "$0")}) (C {(sed)} {(-e)} { (DQ ("s,^") (EscapedLiteralPart token: ) ("[^/]") (EscapedLiteralPart token:) (",") (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [50 52] ) (/) (EscapedLiteralPart token:) (",") ) } ) ] negated: False ) ] ) left_token: spids: [33 57] ) ) } ) ] ) left_token: spids: [29 59] ) } spids: [28] ) ] spids: [26] ) (Assignment keyword: Assign_Readonly pairs: [ (assign_pair lhs: (LhsName name:ProtoRootDir) op: Equal rhs: {(DQ (${ VSub_Name ScriptDir) (/../..))} spids: [63] ) ] spids: [61] ) (FuncDef name: die body: (BraceGroup children: [(C {(echo)} {(DQ ("Error: ") ($ VSub_Number "$1"))}) (C {(exit)} {(1)})] spids: [76] ) spids: [72 75] ) (Assignment keyword: Assign_Readonly pairs: [ (assign_pair lhs: (LhsName name:GeneratorSrc) op: Equal rhs: { (DQ (${ VSub_Name ProtoRootDir) (/src/google/protobuf/compiler/objectivec/objectivec_file.cc) ) } spids: [96] ) ] spids: [94] ) (Assignment keyword: Assign_Readonly pairs: [ (assign_pair lhs: (LhsName name:RuntimeSrc) op: Equal rhs: {(DQ (${ VSub_Name ProtoRootDir) (/objectivec/GPBBootstrap.h))} spids: [106] ) ] spids: [104] ) (FuncDef name: check_constant body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:ConstantName) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [124] ) ] spids: [122] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:GeneratorVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(cat)} {(DQ (${ VSub_Name GeneratorSrc))}) (C {(sed)} {(-n)} {(-e)} { (DQ ("s:const int32 ") (${ VSub_Name ConstantName) (" = ") (EscapedLiteralPart token: ) ("[0-9]*") (EscapedLiteralPart token:) (";:") (EscapedLiteralPart token: ) (":p") ) } ) ] negated: False ) ] ) left_token: spids: [138 175] ) } spids: [137] ) ] spids: [135] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: {(DQ (${ VSub_Name GeneratorVersion))} ) ) terminator: ) ] action: [ (C {(die)} { (DQ ("Failed to find ") (${ VSub_Name ConstantName) (" in the generator source (") (${ VSub_Name GeneratorSrc) (").") ) } ) ] spids: [-1 194] ) ] spids: [-1 212] ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:RuntimeVersion) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(cat)} {(DQ (${ VSub_Name RuntimeSrc))}) (C {(sed)} {(-n)} {(-e)} { (DQ ("s:#define ") (${ VSub_Name ConstantName) (" ") (EscapedLiteralPart token: ) ("[0-9]*") (EscapedLiteralPart token:) (":") (EscapedLiteralPart token: ) (":p") ) } ) ] negated: False ) ] ) left_token: spids: [223 260] ) } spids: [222] ) ] spids: [220] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{(DQ (${ VSub_Name RuntimeVersion))}) ) terminator: ) ] action: [ (C {(die)} { (DQ ("Failed to find ") (${ VSub_Name ConstantName) (" in the runtime source (") (${ VSub_Name RuntimeSrc) (").") ) } ) ] spids: [-1 279] ) ] spids: [-1 297] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {(DQ (${ VSub_Name GeneratorVersion))} right: {(DQ (${ VSub_Name RuntimeVersion))} ) ) terminator: ) ] action: [ (C {(die)} { (DQ (${ VSub_Name ConstantName) (" values don't match!\n") (" Generator: ") (${ VSub_Name GeneratorVersion) (" from ") (${ VSub_Name GeneratorSrc) ("\n") (" Runtime: ") (${ VSub_Name RuntimeVersion) (" from ") (${ VSub_Name RuntimeSrc) ("\n") ) } ) ] spids: [-1 327] ) ] spids: [-1 358] ) ] spids: [119] ) spids: [115 118] ) (C {(check_constant)} {(GOOGLE_PROTOBUF_OBJC_VERSION)}) ] )