diff --git a/core/chaincode/platforms/golang/platform.go b/core/chaincode/platforms/golang/platform.go index cbe905fe2b3..f8e9be55526 100644 --- a/core/chaincode/platforms/golang/platform.go +++ b/core/chaincode/platforms/golang/platform.go @@ -239,18 +239,29 @@ func (goPlatform *Platform) GetDeploymentPayload(spec *pb.ChaincodeSpec) ([]byte }) // -------------------------------------------------------------------------------------- - // Assemble the fully resolved list of transitive dependencies from the imports that remain + // Assemble the fully resolved list of direct and transitive dependencies based on the + // imports that remain after filtering // -------------------------------------------------------------------------------------- deps := make(map[string]bool) for _, pkg := range imports { - _deps, err := listDeps(env, pkg) + // ------------------------------------------------------------------------------ + // Resolve direct import's transitives + // ------------------------------------------------------------------------------ + transitives, err := listDeps(env, pkg) if err != nil { return nil, fmt.Errorf("Error obtaining dependencies for %s: %s", pkg, err) } - // Merge with our top list - for _, dep := range _deps { + // ------------------------------------------------------------------------------ + // Merge all results with our top list + // ------------------------------------------------------------------------------ + + // Merge direct dependency... + deps[pkg] = true + + // .. and then all transitives + for _, dep := range transitives { deps[dep] = true } } diff --git a/core/chaincode/platforms/golang/platform_test.go b/core/chaincode/platforms/golang/platform_test.go index 7aac06f7ca2..21d9519c4af 100644 --- a/core/chaincode/platforms/golang/platform_test.go +++ b/core/chaincode/platforms/golang/platform_test.go @@ -260,6 +260,7 @@ func TestGenerateDockerBuild(t *testing.T) { specs = append(specs, spec{CCName: "NoCode", Path: "path/to/nowhere", File: "/bin/warez", Mode: 0100400, SuccessExpected: false}) specs = append(specs, spec{CCName: "invalidhttp", Path: "https://not/a/valid/path", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100400, SuccessExpected: false, RealGen: true}) specs = append(specs, spec{CCName: "map", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100400, SuccessExpected: true, RealGen: true}) + specs = append(specs, spec{CCName: "AutoVendor", Path: "github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode", File: "/src/github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go", Mode: 0100400, SuccessExpected: true, RealGen: true}) specs = append(specs, spec{CCName: "mapBadPath", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/bad/path/to/map.go", Mode: 0100400, SuccessExpected: false}) specs = append(specs, spec{CCName: "mapBadMode", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map", File: "/src/github.com/hyperledger/fabric/examples/chaincode/go/map/map.go", Mode: 0100555, SuccessExpected: false}) diff --git a/test/chaincodes/AutoVendor/chaincode/main.go b/test/chaincodes/AutoVendor/chaincode/main.go new file mode 100644 index 00000000000..dedc926a1aa --- /dev/null +++ b/test/chaincodes/AutoVendor/chaincode/main.go @@ -0,0 +1,43 @@ +/* + * Copyright Greg Haskins All Rights Reserved + * + * SPDX-License-Identifier: Apache-2.0 + * + * The purpose of this test code is to prove that the system properly packages + * up dependencies. We therefore synthesize the scenario where a chaincode + * imports non-standard dependencies both directly and indirectly and then + * expect a unit-test to verify that the package includes everything needed + * and ultimately builds properly. + * + */ + +package main + +import ( + "fmt" + + "github.com/hyperledger/fabric/core/chaincode/shim" + pb "github.com/hyperledger/fabric/protos/peer" + "github.com/hyperledger/fabric/test/chaincodes/AutoVendor/directdep" +) + +// SimpleChaincode example simple Chaincode implementation +type SimpleChaincode struct { +} + +func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { + return shim.Error("NOT IMPL") +} + +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { + return shim.Error("NOT IMPL") +} + +func main() { + directdep.PointlessFunction() + + err := shim.Start(new(SimpleChaincode)) + if err != nil { + fmt.Printf("Error starting Simple chaincode: %s", err) + } +} diff --git a/test/chaincodes/AutoVendor/directdep/core.go b/test/chaincodes/AutoVendor/directdep/core.go new file mode 100644 index 00000000000..a19928a14bd --- /dev/null +++ b/test/chaincodes/AutoVendor/directdep/core.go @@ -0,0 +1,17 @@ +/* + * Copyright Greg Haskins All Rights Reserved + * + * SPDX-License-Identifier: Apache-2.0 + * + * See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details + */ +package directdep + +import ( + "github.com/hyperledger/fabric/test/chaincodes/AutoVendor/indirectdep" +) + +func PointlessFunction() { + // delegate to our indirect dependency + indirectdep.PointlessFunction() +} diff --git a/test/chaincodes/AutoVendor/indirectdep/core.go b/test/chaincodes/AutoVendor/indirectdep/core.go new file mode 100644 index 00000000000..4a3fa9d3ee6 --- /dev/null +++ b/test/chaincodes/AutoVendor/indirectdep/core.go @@ -0,0 +1,14 @@ +/* + * Copyright Greg Haskins All Rights Reserved + * + * SPDX-License-Identifier: Apache-2.0 + * + * See github.com/hyperledger/fabric/test/chaincodes/AutoVendor/chaincode/main.go for details + */ +package indirectdep + +import "fmt" + +func PointlessFunction() { + fmt.Printf("Successfully invoked pointless function\n") +}