Skip to content

Commit

Permalink
[FABG-849] Cleanup scripts
Browse files Browse the repository at this point in the history
This change cleans up the third_party scripts to seperate common
utilities from third_party only.

Change-Id: Ieecc98b02d2d806ae041be15dca04e4d16a6b4cb
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Apr 11, 2019
1 parent 3e09cdf commit 5a9a0e7
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 42 deletions.
99 changes: 99 additions & 0 deletions scripts/third_party_pins/fabric/apply_fabric_common_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# This script pins from Hyperledger Fabric into the SDK
# Note: This script must be adjusted as upstream makes adjustments

set -e

IMPORT_SUBSTS=($IMPORT_SUBSTS)

GOIMPORTS_CMD=goimports
GOFILTER_CMD="go run scripts/_go/src/gofilter/cmd/gofilter/gofilter.go"

# Create and populate patching directory.
declare TMP=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
declare PATCH_PROJECT_PATH=$TMP/src/$UPSTREAM_PROJECT
cp -R ${TMP_PROJECT_PATH} ${PATCH_PROJECT_PATH}
declare TMP_PROJECT_PATH=${PATCH_PROJECT_PATH}

declare -a PKGS=(
"common/cauthdsl"
"core/common/ccprovider"
"core/ledger/kvledger/txmgmt/rwsetutil"
"core/ledger/util"
)

declare -a FILES=(
"common/cauthdsl/cauthdsl_builder.go"
"common/cauthdsl/policyparser.go"
"core/common/ccprovider/ccprovider.go"
"core/common/ccprovider/cdspackage.go"
"core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go"
"core/ledger/util/txvalidationflags.go"
)

# Create directory structure for packages
for i in "${PKGS[@]}"
do
mkdir -p $INTERNAL_PATH/${i}
done

# Apply fine-grained patching
gofilter() {
echo "Filtering: ${FILTER_FILENAME}"
cp ${TMP_PROJECT_PATH}/${FILTER_FILENAME} ${TMP_PROJECT_PATH}/${FILTER_FILENAME}.bak
$GOFILTER_CMD -filename "${TMP_PROJECT_PATH}/${FILTER_FILENAME}.bak" \
-filters "$FILTERS_ENABLED" -fn "$FILTER_FN" -gen "$FILTER_GEN" -type "$FILTER_TYPE" \
> "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"
}

echo "Filtering Go sources for allowed functions ..."
FILTERS_ENABLED="fn"

FILTER_FILENAME="core/common/ccprovider/ccprovider.go"
FILTER_FN=Reset,String,ProtoMessage
gofilter
sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"

FILTER_FILENAME="core/common/ccprovider/cdspackage.go"
FILTER_FN=Reset,String,ProtoMessage
gofilter
sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"

FILTER_FILENAME="core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go"
FILTER_FN="NewHeight,ToProtoBytes,FromProtoBytes,toProtoMsg,TxRwSetFromProtoMsg,TxPvtRwSetFromProtoMsg,nsRwSetFromProtoMsg,nsPvtRwSetFromProtoMsg"
FILTER_FN+=",collHashedRwSetFromProtoMsg,collPvtRwSetFromProtoMsg"
gofilter

FILTER_FILENAME="core/ledger/util/txvalidationflags.go"
FILTER_FN="IsValid,IsInvalid,Flag,IsSetTo,NewTxValidationFlags,newTxValidationFlagsSetValue"
gofilter

echo "Filtering Go sources for allowed declarations ..."
FILTER_FILENAME="core/common/ccprovider/ccprovider.go"
FILTERS_ENABLED="gen,type"
FILTER_TYPE="IMPORT,CONST"
FILTER_GEN="CCPackage,ChaincodeData"
gofilter

# Apply patching
echo "Patching import paths on upstream project ..."
WORKING_DIR=$TMP_PROJECT_PATH FILES="${FILES[@]}" IMPORT_SUBSTS="${IMPORT_SUBSTS[@]}" scripts/third_party_pins/common/apply_import_patching.sh

echo "Inserting modification notice ..."
WORKING_DIR=$TMP_PROJECT_PATH FILES="${FILES[@]}" scripts/third_party_pins/common/apply_header_notice.sh

# Copy patched project into internal paths
echo "Copying patched upstream project into working directory ..."
for i in "${FILES[@]}"
do
TARGET_PATH=`dirname $INTERNAL_PATH/${i}`
cp $TMP_PROJECT_PATH/${i} $TARGET_PATH
done

rm -Rf ${TMP_PROJECT_PATH}
39 changes: 1 addition & 38 deletions scripts/third_party_pins/fabric/apply_fabric_external_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# SPDX-License-Identifier: Apache-2.0
#

# This script pins the BCCSP package family from Hyperledger Fabric into the SDK
# These files are checked into internal paths.
# This script pins from Hyperledger Fabric into the SDK
# Note: This script must be adjusted as upstream makes adjustments

set -e
Expand All @@ -23,20 +22,10 @@ cp -R ${TMP_PROJECT_PATH} ${PATCH_PROJECT_PATH}
declare TMP_PROJECT_PATH=${PATCH_PROJECT_PATH}

declare -a PKGS=(
"common/cauthdsl"
"core/common/ccprovider"
"core/ledger/kvledger/txmgmt/rwsetutil"
"core/ledger/util"
"internal/protoutil"
)

declare -a FILES=(
"common/cauthdsl/cauthdsl_builder.go"
"common/cauthdsl/policyparser.go"
"core/common/ccprovider/ccprovider.go"
"core/common/ccprovider/cdspackage.go"
"core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go"
"core/ledger/util/txvalidationflags.go"
"internal/protoutil/commonutils.go"
)

Expand All @@ -62,32 +51,6 @@ FILTER_FILENAME="internal/protoutil/commonutils.go"
FILTER_FN="MarshalOrPanic"
gofilter

FILTER_FILENAME="core/common/ccprovider/ccprovider.go"
FILTER_FN=Reset,String,ProtoMessage
gofilter
sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"

FILTER_FILENAME="core/common/ccprovider/cdspackage.go"
FILTER_FN=Reset,String,ProtoMessage
gofilter
sed -i'' -e 's/var ccInfoCache = NewCCInfoCache(ccInfoFSProvider)//g' "${TMP_PROJECT_PATH}/${FILTER_FILENAME}"

FILTER_FILENAME="core/ledger/kvledger/txmgmt/rwsetutil/rwset_proto_util.go"
FILTER_FN="NewHeight,ToProtoBytes,FromProtoBytes,toProtoMsg,TxRwSetFromProtoMsg,TxPvtRwSetFromProtoMsg,nsRwSetFromProtoMsg,nsPvtRwSetFromProtoMsg"
FILTER_FN+=",collHashedRwSetFromProtoMsg,collPvtRwSetFromProtoMsg"
gofilter

FILTER_FILENAME="core/ledger/util/txvalidationflags.go"
FILTER_FN="IsValid,IsInvalid,Flag,IsSetTo,NewTxValidationFlags,newTxValidationFlagsSetValue"
gofilter

echo "Filtering Go sources for allowed declarations ..."
FILTER_FILENAME="core/common/ccprovider/ccprovider.go"
FILTERS_ENABLED="gen,type"
FILTER_TYPE="IMPORT,CONST"
FILTER_GEN="CCPackage,ChaincodeData"
gofilter

# Apply patching
echo "Patching import paths on upstream project ..."
WORKING_DIR=$TMP_PROJECT_PATH FILES="${FILES[@]}" IMPORT_SUBSTS="${IMPORT_SUBSTS[@]}" scripts/third_party_pins/common/apply_import_patching.sh
Expand Down
5 changes: 2 additions & 3 deletions scripts/third_party_pins/fabric/apply_upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ declare -a CLIENT_UTILS_IMPORT_SUBSTS=(
)

INTERNAL_PATH=$THIRDPARTY_INTERNAL_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS="${CLIENT_UTILS_IMPORT_SUBSTS[*]}" $SCRIPTS_PATH/apply_fabric_client_utils.sh

INTERNAL_PATH=$THIRDPARTY_INTERNAL_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS="${CLIENT_UTILS_IMPORT_SUBSTS[*]}" $SCRIPTS_PATH/apply_fabric_external_utils.sh
rm -Rf ${THIRDPARTY_INTERNAL_FABRIC_PATH}/internal/protoutil/
INTERNAL_PATH=$THIRDPARTY_INTERNAL_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS="${CLIENT_UTILS_IMPORT_SUBSTS[*]}" $SCRIPTS_PATH/apply_fabric_common_utils.sh

# external utils
echo "Pinning and patching fabric external utils ..."
Expand All @@ -79,6 +77,7 @@ declare -a EXTERNAL_UTILS_IMPORT_SUBSTS=(
's/\"github.com\/hyperledger\/fabric\//\"github.com\/hyperledger\/fabric-sdk-go\/third_party\/github.com\/hyperledger\/fabric\//g'
)
INTERNAL_PATH=$THIRDPARTY_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS="${EXTERNAL_UTILS_IMPORT_SUBSTS[*]}" $SCRIPTS_PATH/apply_fabric_external_utils.sh
INTERNAL_PATH=$THIRDPARTY_FABRIC_PATH TMP_PROJECT_PATH=$TMP_PROJECT_PATH IMPORT_SUBSTS="${EXTERNAL_UTILS_IMPORT_SUBSTS[*]}" $SCRIPTS_PATH/apply_fabric_common_utils.sh

# protos
echo "Pinning and patching protos (fabric common)..."
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ echo "Running" $(basename "$0")
# Packages to include in test run
PWD_ORIG=$(pwd)
cd "${MODULE_PATH}"
pwd

PKGS=($(${GO_CMD} list ${PROJECT_MODULE}/test/integration/... 2> /dev/null | \
grep -v ^${PROJECT_MODULE}/test/integration/e2e/pkcs11 | \
grep -v ^${PROJECT_MODULE}/test/integration/negative | \
Expand Down

0 comments on commit 5a9a0e7

Please sign in to comment.