This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: Generate enums and constants during build and add CI notification
- Loading branch information
Gabriel Schulhof
committed
Nov 10, 2015
1 parent
b7c6d8f
commit 8ae6a5a
Showing
12 changed files
with
281 additions
and
602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Code that's common between looking for enums and looking for constants | ||
# Assumes the command line consists of OCTBSTACK_CFLAGS | ||
|
||
find_include_paths() { | ||
echo "$OCTBSTACK_CFLAGS" | awk '{ | ||
for ( idx = 1 ; idx <= NF ; idx++ ) { | ||
if ( substr( $idx, 1, 2 ) == "-I" ) { | ||
if ( length( $idx ) == 2 ) { | ||
print( $(idx + 1) ); | ||
} else { | ||
print( substr( $idx, 3 ) ); | ||
} | ||
} | ||
} | ||
}' | ||
} | ||
|
||
# The command line consists of the CFLAGS | ||
OCTBSTACK_CFLAGS="$@" | ||
|
||
INCLUDE_PATHS=$( find_include_paths ) | ||
|
||
for ONE_PATH in $INCLUDE_PATHS; do | ||
if test -f "${ONE_PATH}/octypes.h"; then | ||
OCTYPES_H="${ONE_PATH}/octypes.h" | ||
fi | ||
if test -f "${ONE_PATH}/ocpresence.h"; then | ||
OCPRESENCE_H="${ONE_PATH}/ocpresence.h" | ||
fi | ||
if test -f "${ONE_PATH}/ocstackconfig.h"; then | ||
OCSTACKCONFIG_H="${ONE_PATH}/ocstackconfig.h" | ||
fi | ||
if test -f "${ONE_PATH}/ocrandom.h"; then | ||
OCRANDOM_H="${ONE_PATH}/ocrandom.h" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
# Update constants in generated/constants.cc. The command line arguments for this script are used to | ||
# construct the value of the OCTBSTACK_CFLAGS variable, which, in turn, is used for determining | ||
# where the include files are located. | ||
# | ||
# generated/constants.cc.in contains the comment "// The rest of this file is generated". This script | ||
# preserves the file up to and including the comment, and appends generated contents after that. It | ||
# then appends to generated/constants.cc the constant definitions from octypes.h and ocstackconfig.h. | ||
# | ||
# The script also generates the function InitConstants() which the file is expected to export. | ||
|
||
. ./constants-and-enums.common.sh | ||
|
||
# generated/constants.cc | ||
|
||
# Parse header file, extracting constants | ||
parseFileForConstants() { # $1: filename | ||
grep '^#define' < "$1" | \ | ||
awk '{ | ||
if ( NF > 2 ) { | ||
print( "SET_CONSTANT_" ( ( substr($3, 1, 1) == "\"" ) ? "STRING": "NUMBER" ) " " $2 ); | ||
} | ||
}' | \ | ||
sort -u | \ | ||
awk '{ | ||
print( "#ifdef " $2 ); | ||
print( " " $1 "(exports, " $2 ");" ); | ||
print( "#endif /* def " $2 "*/" ); | ||
}' | ||
} | ||
|
||
mkdir -p generated | ||
|
||
# Copy the boilerplate from the starter file | ||
cat src/constants.cc.in > generated/constants.cc.new || ( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Add the function header | ||
echo 'void InitConstants(Handle<Object> exports) {' >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Parse ocstackconfig.h and append to the generated file | ||
echo ' // ocstackconfig.h: Stack configuration' >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
parseFileForConstants "${OCSTACKCONFIG_H}" >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Separate the two sections with a newline | ||
echo '' >> generated/constants.cc.new || ( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Parse octypes.h and append to the generated file | ||
echo ' // octypes.h: Definitions' >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
parseFileForConstants "${OCTYPES_H}" >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Separate the two sections with a newline | ||
echo '' >> generated/constants.cc.new || ( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Parse octypes.h and append to the generated file | ||
echo ' // ocrandom.h: Definitions' >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
parseFileForConstants "${OCRANDOM_H}" >> generated/constants.cc.new || \ | ||
( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Close the function | ||
echo '}' >> generated/constants.cc.new || ( rm -f generated/constants.cc.new && exit 1 ) | ||
|
||
# Replace the original file with the generated file | ||
mv -f generated/constants.cc.new generated/constants.cc || ( rm -f generated/constants.cc.new && exit 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# Update enums in generated/enums.cc. The command line arguments for this script are used to construct | ||
# the value of the OCTBSTACK_CFLAGS variable, which, in turn, is used for determining where the | ||
# include files are located. | ||
# | ||
# generated/enums.cc contains the comment "// The rest of this file is generated". This script | ||
# preserves the file up to and including the comment, and discards the rest of the file. It then | ||
# appends to generated/enums.cc the enum definitions from octypes.h | ||
# | ||
# The script also generates the function InitEnums() which the file is expected to export. | ||
|
||
. ./constants-and-enums.common.sh | ||
|
||
# enums.cc | ||
|
||
mkdir -p generated | ||
|
||
# Copy the boilerplate from the existing file | ||
cat src/enums.cc.in > generated/enums.cc.new || ( rm -f generated/enums.cc.new && exit 1 ) | ||
|
||
# Parse header for enums | ||
cat "${OCTYPES_H}" "${OCRANDOM_H}" "${OCPRESENCE_H}" | \ | ||
grep -v '^$' | \ | ||
awk -v PRINT=0 -v OUTPUT="" -v ENUM_LIST="" '{ | ||
if ( $0 == "typedef enum" ) PRINT=1; | ||
if ( PRINT == 1 ) { | ||
if ( !( $1 ~ /^[{}]/ ) && $1 != "typedef" ) { | ||
if ( $1 ~ /^[A-Z]/ ) { | ||
OUTPUT = OUTPUT " SET_CONSTANT_NUMBER(returnValue, " $1 ");\n"; | ||
} else if ( $1 ~ /^#(if|endif)/ ) { | ||
OUTPUT = OUTPUT $0 "\n"; | ||
} | ||
} else if ( $1 ~ /^}/ ) { | ||
ENUM_NAME = $0; | ||
gsub( /^} */, "", ENUM_NAME ); | ||
gsub( / *;.*$/, "", ENUM_NAME ); | ||
ENUM_LIST = ENUM_LIST " SET_ENUM(exports, " ENUM_NAME ");\n"; | ||
print("static Local<Object> bind_" ENUM_NAME "() {\n Local<Object> returnValue = Nan::New<Object>();\n" ); | ||
} | ||
else if ( $1 != "typedef" && $1 != "{" ) { | ||
print; | ||
} | ||
if ( $0 ~ /;$/ ) { | ||
PRINT=0; | ||
print( OUTPUT "\n return returnValue;\n}\n" ); | ||
OUTPUT=""; | ||
} | ||
} | ||
} | ||
END { | ||
print( "void InitEnums(Handle<Object> exports) {\n" ENUM_LIST "}" ); | ||
}' | \ | ||
sed 's/[,=]);$/);/' >> generated/enums.cc.new || ( rm -f generated/enums.cc.new && exit 1 ) | ||
|
||
# Replace the original file with the generated file | ||
mv -f generated/enums.cc.new generated/enums.cc || ( rm -f generated/enums.cc.new && exit 1 ) |
Oops, something went wrong.