Skip to content

Commit

Permalink
[FABG-924] Simplify upstream patching
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Likic <[email protected]>
  • Loading branch information
Aleksandar Likic committed Dec 7, 2019
1 parent 648507b commit fe2f155
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 1,698 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,11 @@ endif
.PHONY: thirdparty-pin
thirdparty-pin:
@echo "Pinning third party packages ..."
@UPSTREAM_COMMIT=$(THIRDPARTY_FABRIC_COMMIT) UPSTREAM_BRANCH=$(THIRDPARTY_FABRIC_BRANCH) scripts/third_party_pins/fabric/apply_upstream.sh
@UPSTREAM_COMMIT=$(THIRDPARTY_FABRIC_CA_COMMIT) UPSTREAM_BRANCH=$(THIRDPARTY_FABRIC_CA_BRANCH) scripts/third_party_pins/fabric-ca/apply_upstream.sh
@THIRDPARTY_FABRIC_COMMIT=$(THIRDPARTY_FABRIC_COMMIT) \
THIRDPARTY_FABRIC_BRANCH=$(THIRDPARTY_FABRIC_BRANCH) \
THIRDPARTY_FABRIC_CA_COMMIT=$(THIRDPARTY_FABRIC_CA_COMMIT) \
THIRDPARTY_FABRIC_CA_BRANCH=$(THIRDPARTY_FABRIC_CA_BRANCH) \
scripts/third_party_pins/apply_thirdparty_pins.sh

.PHONY: populate
populate: populate-vendor populate-fixtures-stable
Expand Down
40 changes: 40 additions & 0 deletions scripts/third_party_pins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Fabric-sdk-go reuses fabric and fabric-ca code by first copying
desired files from upstream repos and then patching them to work
locally. The process of patching is a simple git merge which
replays changes from the last successful patch. For this to work,
the two steps (pulling files from upstream and patching) must
always be maintained in their own separate commits each time we
pull in the new upstream version.

Note that replaying changes from old commits using a simple
'git am' doesn't work well because a git patch created with
'git format-patch' doesn't have a knowledge of the common
ancestor of the master and the commit we want to replay,
so we end up with many unexpected conflicts.

Here are full steps for pulling code from upstream and patching:
```
> make thirdparty-pin
```
We must now commit upstream files first. This will keep the
subsequent patch in its own clean commit so we can use it in the
future.
```
> git add .
> git commit --signoff -m "Apply upstream"
```
Now we need to replay changes from the last correct patch.
We do it using git, with the help of a temporary branch where we
first copy the changes we want to replay. This example assumes
that the last correct patch was committed as ```5678```, and its
parent is the commit ```1234```.
```
> git format-patch --stdout 1234..5678 > ~/last.patch
> git checkout -b fix 1234
> git am ~/last.patch
> git checkout master
> git merge fix
```
If necessary, fix any conflicts and commit

Amend as required, and push all commits.
27 changes: 27 additions & 0 deletions scripts/third_party_pins/apply_thirdparty_pins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# Copyright SecureKey Technologies Inc. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

# This script fetches code originating from other upstream projects
# These files are checked into internal paths.

set -e

if output=$(git status --porcelain) && [ -z "$output" ]
then
echo "Working directory clean, proceeding with upstream patching"
else
echo "ERROR: git status must be clean before applying upstream patches"
exit 1
fi

export UPSTREAM_COMMIT="${THIRDPARTY_FABRIC_COMMIT}"
export UPSTREAM_BRANCH="${THIRDPARTY_FABRIC_BRANCH}"
scripts/third_party_pins/fabric/apply_upstream.sh

export UPSTREAM_COMMIT="${THIRDPARTY_FABRIC_CA_COMMIT}"
export UPSTREAM_BRANCH="${THIRDPARTY_FABRIC_CA_BRANCH}"
scripts/third_party_pins/fabric-ca/apply_upstream.sh
25 changes: 11 additions & 14 deletions scripts/third_party_pins/common/apply_header_notice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

set -e

FILES=($FILES)
FILE=$1
NOTICE=$'Notice: This file has been modified for Hyperledger Fabric SDK Go usage.\nPlease review third_party pinning scripts and patches for more details.'
SPDX_LICENSE_ID="SPDX-License-Identifier: Apache-2.0"
OLD_APACHE_LICENSE_ID="http://www.apache.org/licenses/LICENSE-2.0"
Expand All @@ -18,16 +18,13 @@ if [ -z $WORKING_DIR ]; then
WORKING_DIR=`pwd`
fi

for i in "${FILES[@]}"
do
if APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${i} "$NOTICE" "$SPDX_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${i}
elif APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${i} "$NOTICE" "$OLD_APACHE_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${i}
elif [ "$ALLOW_NONE_LICENSE_ID" == "true" ] && APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${i} "$NOTICE" "$NONE_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${i}
else
echo "Failed to apply notice to ${WORKING_DIR}/${i}"
exit 1
fi
done
if APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$SPDX_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${FILE}
elif APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$OLD_APACHE_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${FILE}
elif [ "$ALLOW_NONE_LICENSE_ID" == "true" ] && APPLIED=`scripts/third_party_pins/common/insert_header_notice.sh ${WORKING_DIR}/${FILE} "$NOTICE" "$NONE_LICENSE_ID"`; then
echo "$APPLIED" > ${WORKING_DIR}/${FILE}
else
echo "Failed to apply notice to ${WORKING_DIR}/${FILE}"
exit 1
fi
25 changes: 0 additions & 25 deletions scripts/third_party_pins/common/apply_import_patching.sh

This file was deleted.

Loading

0 comments on commit fe2f155

Please sign in to comment.