diff --git a/cmd/init.go b/cmd/init.go index c39ff25d..4155ab14 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -69,7 +69,7 @@ var initCmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { // Generate build script - err := tpl.ExecuteMake(initCmdSrc, initCmdTrg, initCmdExtensions, makefile, initCmdMode, os.Getwd, true) + err := tpl.ExecuteMake(initCmdSrc, initCmdTrg, initCmdExtensions, makefile, initCmdMode, os.Getwd, true, buildCmdStrict) logError(err) }, } diff --git a/cmd/mtad.go b/cmd/mtad.go index 01da1c08..4a45251c 100644 --- a/cmd/mtad.go +++ b/cmd/mtad.go @@ -21,7 +21,7 @@ var mtadGenCmd = &cobra.Command{ Long: "Generates a deployment descriptor ('mtad.yaml') file from the 'mta.yaml' file", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - err := artifacts.ExecuteMtadGen(mtadGenCmdSrc, mtadGenCmdTrg, mtadGenCmdExtensions, mtadGenCmdPlatform, os.Getwd) + err := artifacts.ExecuteMtadGen(mtadGenCmdSrc, mtadGenCmdTrg, mtadGenCmdExtensions, mtadGenCmdPlatform, os.Getwd, buildCmdStrict) logError(err) return err }, @@ -39,5 +39,7 @@ func init() { "The MTA extension descriptors") mtadGenCmd.Flags().StringVarP(&mtadGenCmdPlatform, "platform", "p", "cf", `The deployment platform; supported platforms: "cf", "xsa", "neo"`) + mtadGenCmd.Flags().BoolVarP(&buildCmdStrict, "strict", "", true, + `If set to true, duplicated fields and fields not defined in the "mta.yaml" schema are reported as errors; if set to false, they are reported as warnings`) mtadGenCmd.Flags().BoolP("help", "h", false, `Displays detailed information about the 'mtad gen' command`) } diff --git a/go.mod b/go.mod index 39183539..ee39b2d2 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/SAP/cloud-mta-build-tool go 1.13 require ( - github.com/SAP/cloud-mta v1.0.6 + github.com/SAP/cloud-mta v1.0.8 github.com/deckarep/golang-set v1.7.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mattn/goveralls v0.0.11 // indirect @@ -17,4 +17,4 @@ require ( github.com/x-cray/logrus-prefixed-formatter v0.5.2 golang.org/x/sys v0.0.0-20220222200937-f2425489ef4c // indirect gopkg.in/yaml.v2 v2.4.0 -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index 07438b01..67f21956 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/SAP/cloud-mta v1.0.6 h1:LKCeqiAevPwAnMkuHyK/2JhL3RM7FpRs3mF1hmQwHGY= -github.com/SAP/cloud-mta v1.0.6/go.mod h1:raToVpkWBCajEnid35ewX0BNsrGpZgZ62m70MGhai1M= +github.com/SAP/cloud-mta v1.0.8 h1:b3/kN4vmcfH8CHoyVQ27no/lcncWTnQ35hDEunuqXHw= +github.com/SAP/cloud-mta v1.0.8/go.mod h1:raToVpkWBCajEnid35ewX0BNsrGpZgZ62m70MGhai1M= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= diff --git a/internal/archive/module_location.go b/internal/archive/module_location.go index d9836d69..5759043b 100644 --- a/internal/archive/module_location.go +++ b/internal/archive/module_location.go @@ -1,8 +1,9 @@ package dir import ( - "github.com/SAP/cloud-mta/mta" "path/filepath" + + "github.com/SAP/cloud-mta/mta" ) // ModuleLoc - module location type that provides services for stand alone module build command @@ -47,6 +48,10 @@ func (ep *ModuleLoc) ParseFile() (*mta.MTA, error) { return ep.loc.ParseFile() } +func (ep *ModuleLoc) SetStrictParmeter(strick bool) bool { + return ep.loc.SetStrictParmeter(strick) +} + // ModuleLocation - provides target location of stand alone MTA module build result func ModuleLocation(loc *Loc, targetPathDefined bool) *ModuleLoc { return &ModuleLoc{loc: loc, targetPathDefined: targetPathDefined} diff --git a/internal/archive/module_location_test.go b/internal/archive/module_location_test.go index 868a29a9..28f9639b 100644 --- a/internal/archive/module_location_test.go +++ b/internal/archive/module_location_test.go @@ -1,9 +1,10 @@ package dir import ( + "os" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "os" ) var _ = Describe("ModuleLocation", func() { @@ -68,6 +69,13 @@ var _ = Describe("ModuleLocation", func() { Ω(module2.Parameters["memory"]).Should(Equal("256M")) }) + It("SetStrictParmeter", func() { + projectLoc, err := Location(getPath("testdata"), getPath("testdata"), Dev, []string{}, os.Getwd) + Ω(err).Should(Succeed()) + moduleLoc := ModuleLocation(projectLoc, false) + Ω(moduleLoc.SetStrictParmeter(true)).Should(Equal(true)) + }) + It("ModuleLocation", func() { target := getPath("testdata", "result") projectLoc, err := Location(getPath("testdata"), target, Dev, []string{}, os.Getwd) diff --git a/internal/archive/mta_location.go b/internal/archive/mta_location.go index 235f1030..a531a665 100644 --- a/internal/archive/mta_location.go +++ b/internal/archive/mta_location.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" + "github.com/SAP/cloud-mta-build-tool/internal/logs" "github.com/SAP/cloud-mta/mta" ) @@ -25,9 +26,12 @@ const ( SBomTempFolderSuffix = "_mta_sbom_tmp" ) +var strict bool = true + // IMtaParser - MTA Parser interface type IMtaParser interface { ParseFile() (*mta.MTA, error) + SetStrictParmeter(bStrict bool) bool } // IDescriptor - descriptor interface @@ -234,10 +238,23 @@ func (ep *Loc) IsDeploymentDescriptor() bool { return ep.Descriptor == Dep } +func (ep *Loc) SetStrictParmeter(bStrict bool) bool { + strict = bStrict + return strict +} + // ParseFile returns a reference to the MTA object resulting from the given mta.yaml file merged with the extension descriptors. func (ep *Loc) ParseFile() (*mta.MTA, error) { - mtaFile, _, err := mta.GetMtaFromFile(ep.GetMtaYamlPath(), ep.GetExtensionFilePaths(), true) - return mtaFile, err + if strict == true { + mtaFile, _, err := mta.GetMtaFromFile(ep.GetMtaYamlPath(), ep.GetExtensionFilePaths(), true) + return mtaFile, err + } else { + mtaFile, msg, err := mta.GetMtaFromFileWithStrict(ep.GetMtaYamlPath(), ep.GetExtensionFilePaths(), true, strict) + if msg != nil { + logs.Logger.Warning(msg) + } + return mtaFile, err + } } // GetExtensionFilePaths returns the MTA extension descriptor full paths diff --git a/internal/archive/mta_location_test.go b/internal/archive/mta_location_test.go index 20d5c25f..37aa714b 100644 --- a/internal/archive/mta_location_test.go +++ b/internal/archive/mta_location_test.go @@ -182,6 +182,8 @@ var _ = Describe("ParseFile", func() { It("Parse the mta.yaml file and returns it when there are no extension files", func() { ep := Loc{SourcePath: filepath.Join(wd, "testdata", "testext")} + Ω(ep.SetStrictParmeter(true)).Should(Equal(true)) + mta, err := ep.ParseFile() Ω(mta).ShouldNot(BeNil()) Ω(err).Should(Succeed()) diff --git a/internal/artifacts/meta.go b/internal/artifacts/meta.go index f840fdaf..543a617a 100644 --- a/internal/artifacts/meta.go +++ b/internal/artifacts/meta.go @@ -2,14 +2,15 @@ package artifacts import ( "fmt" - "gopkg.in/yaml.v2" "io/ioutil" "os" "path/filepath" + "gopkg.in/yaml.v2" + "github.com/pkg/errors" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/logs" "github.com/SAP/cloud-mta-build-tool/internal/platform" "github.com/SAP/cloud-mta/mta" @@ -22,10 +23,10 @@ func ExecuteGenMeta(source, target, desc string, extensions []string, platform s if err != nil { return errors.Wrap(err, "failed to generate metadata when initializing the location") } - return executeGenMetaByLocation(loc, loc, platform, true, true) + return executeGenMetaByLocation(loc, loc, platform, true, true, true) } -func executeGenMetaByLocation(loc *dir.Loc, targetArtifacts dir.ITargetArtifacts, platform string, createMetaInf bool, validatePaths bool) error { +func executeGenMetaByLocation(loc *dir.Loc, targetArtifacts dir.ITargetArtifacts, platform string, createMetaInf bool, validatePaths bool, strict bool) error { // validate platform platform, err := validatePlatform(platform) if err != nil { @@ -37,14 +38,15 @@ func executeGenMetaByLocation(loc *dir.Loc, targetArtifacts dir.ITargetArtifacts return err } - err = generateMeta(loc, targetArtifacts, loc.IsDeploymentDescriptor(), platform, createMetaInf, validatePaths) + err = generateMeta(loc, targetArtifacts, loc.IsDeploymentDescriptor(), platform, createMetaInf, validatePaths, strict) return err } // generateMeta - generate metadata artifacts -func generateMeta(loc *dir.Loc, targetArtifacts dir.ITargetArtifacts, deploymentDescriptor bool, platform string, createMetaInf bool, validatePaths bool) error { +func generateMeta(loc *dir.Loc, targetArtifacts dir.ITargetArtifacts, deploymentDescriptor bool, platform string, createMetaInf bool, validatePaths bool, strict bool) error { // parse MTA file + loc.SetStrictParmeter(strict) m, err := loc.ParseFile() if err != nil { return errors.Wrapf(err, genMetaMsg) diff --git a/internal/artifacts/meta_test.go b/internal/artifacts/meta_test.go index 06ce3f90..a5b2ddc2 100644 --- a/internal/artifacts/meta_test.go +++ b/internal/artifacts/meta_test.go @@ -138,7 +138,7 @@ cli_version:["x"] It("Generate Meta", func() { createMtahtml5TmpFolder() ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()} - Ω(generateMeta(&ep, &ep, false, "cf", true, true)).Should(Succeed()) + Ω(generateMeta(&ep, &ep, false, "cf", true, true, true)).Should(Succeed()) Ω(readFileContent(&dir.Loc{SourcePath: getFullPathInTmpFolder("mtahtml5", "META-INF"), Descriptor: "dep"})). Should(Equal(readFileContent(&dir.Loc{SourcePath: getTestPath("golden"), Descriptor: "dep"}))) }) @@ -146,13 +146,13 @@ cli_version:["x"] It("Generate Meta - fails on missing module path in temporary folder", func() { createMtahtml5WithMissingModuleTmpFolder() ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()} - Ω(generateMeta(&ep, &ep, false, "cf", false, true)).Should(HaveOccurred()) + Ω(generateMeta(&ep, &ep, false, "cf", false, true, true)).Should(HaveOccurred()) }) It("Generate Meta - doesn't fail on missing module path in temporary folder because module configured as no-source", func() { createMtahtml5WithMissingModuleTmpFolder() ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath(), MtaFilename: "mtaWithNoSource.yaml"} - Ω(generateMeta(&ep, &ep, false, "cf", true, true)).Should(Succeed()) + Ω(generateMeta(&ep, &ep, false, "cf", true, true, true)).Should(Succeed()) Ω(readFileContent(&dir.Loc{SourcePath: getFullPathInTmpFolder("mtahtml5", "META-INF"), Descriptor: "dep"})). Should(Equal(readFileContent(&dir.Loc{SourcePath: getTestPath("goldenNoSource"), Descriptor: "dep"}))) }) @@ -160,7 +160,7 @@ cli_version:["x"] It("Generate Meta - mta not exists", func() { ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath(), MtaFilename: "mtaNotExists.yaml"} - err := generateMeta(&ep, &ep, false, "cf", true, true) + err := generateMeta(&ep, &ep, false, "cf", true, true, true) checkError(err, ep.GetMtaYamlPath()) }) @@ -180,7 +180,7 @@ cli_version:["x"] It("Generate Meta fails on platform parsing", func() { createMtahtml5TmpFolder() ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()} - err := generateMeta(&ep, &ep, false, "cf", true, true) + err := generateMeta(&ep, &ep, false, "cf", true, true, true) Ω(err).Should(HaveOccurred()) Ω(err.Error()).Should(ContainSubstring(fmt.Sprintf(genMTADTypeTypeCnvMsg, "cf"))) Ω(err.Error()).Should(ContainSubstring(platform.UnmarshalFailedMsg)) @@ -190,7 +190,7 @@ cli_version:["x"] It("Generate Mtar", func() { createMtahtml5TmpFolder() ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()} - err := generateMeta(&ep, &ep, false, "cf", true, true) + err := generateMeta(&ep, &ep, false, "cf", true, true, true) Ω(err).Should(Succeed()) mtarPath, err := generateMtar(&ep, &ep, &ep, true, "") Ω(err).Should(Succeed()) diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 57b40eb4..591f9732 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -13,7 +13,7 @@ import ( "github.com/SAP/cloud-mta/mta" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/logs" ) @@ -39,14 +39,14 @@ func (loc *mtadLoc) GetMtarDir(targetProvided bool) string { } // ExecuteMtadGen - generates MTAD from MTA -func ExecuteMtadGen(source, target string, extensions []string, platform string, wdGetter func() (string, error)) error { +func ExecuteMtadGen(source, target string, extensions []string, platform string, wdGetter func() (string, error), strict bool) error { logs.Logger.Info("generating the MTAD file...") loc, err := dir.Location(source, target, dir.Dev, extensions, wdGetter) if err != nil { return errors.Wrap(err, "generation of the MTAD file failed when initializing the location") } - return executeGenMetaByLocation(loc, &mtadLoc{target}, platform, false, false) + return executeGenMetaByLocation(loc, &mtadLoc{target}, platform, false, false, strict) } func validatePlatform(platform string) (string, error) { diff --git a/internal/artifacts/mtad_test.go b/internal/artifacts/mtad_test.go index 100b5ea5..142abbd3 100644 --- a/internal/artifacts/mtad_test.go +++ b/internal/artifacts/mtad_test.go @@ -9,7 +9,7 @@ import ( "github.com/pkg/errors" "gopkg.in/yaml.v2" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/platform" "github.com/SAP/cloud-mta/mta" @@ -27,7 +27,7 @@ var _ = Describe("Mtad", func() { var _ = Describe("ExecuteMtadGen", func() { It("Sanity", func() { - Ω(ExecuteMtadGen(getTestPath("mta"), getTestPath("result"), nil, "cf", os.Getwd)).Should(Succeed()) + Ω(ExecuteMtadGen(getTestPath("mta"), getTestPath("result"), nil, "cf", os.Getwd, true)).Should(Succeed()) Ω(getTestPath("result", "mtad.yaml")).Should(BeAnExistingFile()) }) It("Fails on creating META-INF folder", func() { @@ -35,28 +35,28 @@ var _ = Describe("Mtad", func() { file, err := os.Create(getFullPathInTmpFolder("mta", "META-INF")) Ω(err).Should(Succeed()) Ω(file.Close()).Should(Succeed()) - Ω(ExecuteMtadGen(getTestPath("mta", "META-INF"), getTestPath("result"), nil, "cf", os.Getwd)).Should(HaveOccurred()) + Ω(ExecuteMtadGen(getTestPath("mta", "META-INF"), getTestPath("result"), nil, "cf", os.Getwd, true)).Should(HaveOccurred()) }) It("Fails on location initialization", func() { Ω(ExecuteMtadGen("", getTestPath("result"), nil, "cf", func() (string, error) { return "", errors.New("err") - })).Should(HaveOccurred()) + }, true)).Should(HaveOccurred()) }) It("Fails on platform validation", func() { Ω(ExecuteMtadGen(getTestPath("mta"), getTestPath("result"), nil, "ab", func() (string, error) { return "", errors.New("err") - })).Should(HaveOccurred()) + }, true)).Should(HaveOccurred()) }) It("Fails on broken extension file - parse ext fails", func() { - Ω(ExecuteMtadGen(getTestPath("mtaWithBrokenExt"), getTestPath("result"), []string{"cf-mtaext.yaml"}, "cf", os.Getwd)).Should(HaveOccurred()) + Ω(ExecuteMtadGen(getTestPath("mtaWithBrokenExt"), getTestPath("result"), []string{"cf-mtaext.yaml"}, "cf", os.Getwd, true)).Should(HaveOccurred()) }) It("Fails on wrong source path - parse fails", func() { - Ω(ExecuteMtadGen(getTestPath("mtax"), getTestPath("result"), nil, "cf", os.Getwd)).Should(HaveOccurred()) + Ω(ExecuteMtadGen(getTestPath("mtax"), getTestPath("result"), nil, "cf", os.Getwd, true)).Should(HaveOccurred()) }) It("Fails on broken platforms configuration", func() { cfg := platform.PlatformConfig platform.PlatformConfig = []byte("abc abc") - Ω(ExecuteMtadGen(getTestPath("mta"), getTestPath("result"), nil, "cf", os.Getwd)).Should(HaveOccurred()) + Ω(ExecuteMtadGen(getTestPath("mta"), getTestPath("result"), nil, "cf", os.Getwd, true)).Should(HaveOccurred()) platform.PlatformConfig = cfg }) }) diff --git a/internal/artifacts/mtar_test.go b/internal/artifacts/mtar_test.go index 4140ce82..af523f76 100644 --- a/internal/artifacts/mtar_test.go +++ b/internal/artifacts/mtar_test.go @@ -8,7 +8,7 @@ import ( . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta/mta" ) @@ -48,7 +48,7 @@ var _ = Describe("Mtar", func() { It("Generate Mtar - Sanity", func() { ep := dir.Loc{SourcePath: getTestPath("mtahtml5"), TargetPath: getResultPath()} createMtahtml5TmpFolder() - Ω(generateMeta(&ep, &ep, false, "cf", true, true)).Should(Succeed()) + Ω(generateMeta(&ep, &ep, false, "cf", true, true, true)).Should(Succeed()) mtarPath, err := generateMtar(&ep, &ep, &ep, true, "") Ω(err).Should(Succeed()) Ω(mtarPath).Should(BeAnExistingFile()) diff --git a/internal/artifacts/project.go b/internal/artifacts/project.go index 7cdc9812..71a90c89 100644 --- a/internal/artifacts/project.go +++ b/internal/artifacts/project.go @@ -34,7 +34,7 @@ func ExecBuild(makefileTmp, source, target string, extensions []string, mode, mt } // (1) generate build script - err = tpl.ExecuteMake(source, "", extensions, makefileTmp, mode, wdGetter, useDefaultMbt) + err = tpl.ExecuteMake(source, "", extensions, makefileTmp, mode, wdGetter, useDefaultMbt, strict) if err != nil { return err } diff --git a/internal/tpl/makefile.go b/internal/tpl/makefile.go index a61a1a5f..6d266d0f 100644 --- a/internal/tpl/makefile.go +++ b/internal/tpl/makefile.go @@ -10,7 +10,7 @@ import ( "github.com/kballard/go-shellquote" "github.com/pkg/errors" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/commands" "github.com/SAP/cloud-mta-build-tool/internal/logs" @@ -27,13 +27,13 @@ type tplCfg struct { } // ExecuteMake - generate makefile -func ExecuteMake(source, target string, extensions []string, name, mode string, wdGetter func() (string, error), useDefaultMbt bool) error { +func ExecuteMake(source, target string, extensions []string, name, mode string, wdGetter func() (string, error), useDefaultMbt bool, strict bool) error { logs.Logger.Infof(`generating the "%s" file...`, name) loc, err := dir.Location(source, target, dir.Dev, extensions, wdGetter) if err != nil { return errors.Wrapf(err, genFailedOnInitLocMsg, name) } - err = genMakefile(loc, loc, loc, loc, loc.GetExtensionFilePaths(), name, mode, useDefaultMbt) + err = genMakefile(loc, loc, loc, loc, loc.GetExtensionFilePaths(), name, mode, useDefaultMbt, strict) if err != nil { return err } @@ -42,14 +42,14 @@ func ExecuteMake(source, target string, extensions []string, name, mode string, } // genMakefile - Generate the makefile -func genMakefile(mtaParser dir.IMtaParser, loc dir.ITargetPath, srcLoc dir.ISourceModule, desc dir.IDescriptor, extensionFilePaths []string, makeFilename, mode string, useDefaultMbt bool) error { +func genMakefile(mtaParser dir.IMtaParser, loc dir.ITargetPath, srcLoc dir.ISourceModule, desc dir.IDescriptor, extensionFilePaths []string, makeFilename, mode string, useDefaultMbt bool, strict bool) error { tpl, err := getTplCfg(mode, desc.IsDeploymentDescriptor()) if err != nil { return err } if err == nil { tpl.depDesc = desc.GetDescriptor() - err = makeFile(mtaParser, loc, srcLoc, extensionFilePaths, makeFilename, &tpl, useDefaultMbt) + err = makeFile(mtaParser, loc, srcLoc, extensionFilePaths, makeFilename, &tpl, useDefaultMbt, strict) } return err } @@ -112,7 +112,7 @@ func (data templateData) GetPathArgument(innerPath string) string { } // makeFile - generate makefile form templates -func makeFile(mtaParser dir.IMtaParser, loc dir.ITargetPath, srcLoc dir.ISourceModule, extensionFilePaths []string, makeFilename string, tpl *tplCfg, useDefaultMbt bool) (e error) { +func makeFile(mtaParser dir.IMtaParser, loc dir.ITargetPath, srcLoc dir.ISourceModule, extensionFilePaths []string, makeFilename string, tpl *tplCfg, useDefaultMbt bool, strict bool) (e error) { // template data data := templateData{} @@ -123,6 +123,7 @@ func makeFile(mtaParser dir.IMtaParser, loc dir.ITargetPath, srcLoc dir.ISourceM } // ParseFile file + mtaParser.SetStrictParmeter(strict) m, err := mtaParser.ParseFile() if err != nil { return errors.Wrapf(err, genFailedMsg, makeFilename) diff --git a/internal/tpl/makefile_test.go b/internal/tpl/makefile_test.go index 3c63452a..c9efe3e9 100644 --- a/internal/tpl/makefile_test.go +++ b/internal/tpl/makefile_test.go @@ -12,7 +12,7 @@ import ( . "github.com/onsi/gomega" "github.com/pkg/errors" - "github.com/SAP/cloud-mta-build-tool/internal/archive" + dir "github.com/SAP/cloud-mta-build-tool/internal/archive" "github.com/SAP/cloud-mta-build-tool/internal/logs" "github.com/SAP/cloud-mta-build-tool/internal/version" "github.com/SAP/cloud-mta/mta" @@ -70,16 +70,16 @@ makefile_version: 0.0.0 Ω(os.RemoveAll(filepath.Join(wd, "testdata", "Makefile.mta"))).Should(Succeed()) }) It("Sanity", func() { - Ω(ExecuteMake(filepath.Join(wd, "testdata"), filepath.Join(wd, "testdata"), nil, makefile, "", os.Getwd, true)).Should(Succeed()) + Ω(ExecuteMake(filepath.Join(wd, "testdata"), filepath.Join(wd, "testdata"), nil, makefile, "", os.Getwd, true, true)).Should(Succeed()) Ω(filepath.Join(wd, "testdata", "Makefile.mta")).Should(BeAnExistingFile()) }) It("Fails on location initialization", func() { Ω(ExecuteMake("", filepath.Join(wd, "testdata"), nil, makefile, "", func() (string, error) { return "", errors.New("err") - }, true)).Should(HaveOccurred()) + }, true, true)).Should(HaveOccurred()) }) It("Fails on wrong mode", func() { - Ω(ExecuteMake(filepath.Join(wd, "testdata"), filepath.Join(wd, "testdata"), nil, makefile, "wrong", os.Getwd, true)).Should(HaveOccurred()) + Ω(ExecuteMake(filepath.Join(wd, "testdata"), filepath.Join(wd, "testdata"), nil, makefile, "wrong", os.Getwd, true, true)).Should(HaveOccurred()) }) }) @@ -94,33 +94,33 @@ makefile_version: 0.0.0 }) It("Sanity", func() { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata"), Descriptor: "dev"} - Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true)).Should(Succeed()) + Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true, true)).Should(Succeed()) Ω(makeFileFullPath).Should(BeAnExistingFile()) Ω(getMakeFileContent(makeFileFullPath)).Should(Equal(expectedMakeFileContent)) }) It("Create make file in folder that does not exist", func() { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata", "someFolder"), Descriptor: "dev"} - Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true)).Should(Succeed()) + Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true, true)).Should(Succeed()) filename := filepath.Join(ep.GetTarget(), makeFileName) Ω(filename).Should(BeAnExistingFile()) Ω(getMakeFileContent(filename)).Should(Equal(expectedMakeFileContent)) }) It("genMakefile testing with wrong mta yaml file", func() { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata"), MtaFilename: "xxx.yaml"} - Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "", true)).Should(HaveOccurred()) + Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "", true, true)).Should(HaveOccurred()) }) It("genMakefile testing with wrong target folder (file path)", func() { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata", "mta.yaml"), MtaFilename: "xxx.yaml"} - Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "", true)).Should(HaveOccurred()) + Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "", true, true)).Should(HaveOccurred()) }) It("genMakefile testing with wrong mode", func() { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata")} - Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "wrongMode", true)).Should(HaveOccurred()) + Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, "wrongMode", true, true)).Should(HaveOccurred()) }) DescribeTable("genMakefile should fail when there is a circular build dependency between modules", func(mode string) { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata"), MtaFilename: "circular.yaml"} - Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, mode, true)).Should(HaveOccurred()) + Ω(genMakefile(&ep, &ep, &ep, &ep, nil, makefile, mode, true, true)).Should(HaveOccurred()) }, Entry("in default mode", ""), Entry("in verbose mode", "verbose"), @@ -128,7 +128,7 @@ makefile_version: 0.0.0 DescribeTable("generate module build in verbose make file", func(mtaFileName, moduleName, expectedModuleCommandsGen string) { ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata", "modulegen"), TargetPath: filepath.Join(wd, "testdata"), Descriptor: "dev", MtaFilename: mtaFileName} - Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true)).Should(Succeed()) + Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true, true)).Should(Succeed()) Ω(makeFileFullPath).Should(BeAnExistingFile()) makefileContent := getMakeFileContent(makeFileFullPath) @@ -153,7 +153,7 @@ makefile_version: 0.0.0 modulegen := filepath.Join(wd, "testdata", "modulegen") DescribeTable("generate module build with dependencies in verbose make file", func(mtaFileName, moduleName, modulePath, expectedModuleDepNames string, expectedModuleDepCopyCommands string) { ep := dir.Loc{SourcePath: modulegen, TargetPath: filepath.Join(wd, "testdata"), Descriptor: "dev", MtaFilename: mtaFileName} - Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true)).Should(Succeed()) + Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tpl, true, true)).Should(Succeed()) Ω(makeFileFullPath).Should(BeAnExistingFile()) makefileContent := getMakeFileContent(makeFileFullPath) @@ -183,7 +183,7 @@ makefile_version: 0.0.0 wd, _ := os.Getwd() testTemplate, _ := ioutil.ReadFile(filepath.Join(wd, "testdata", testTemplateFilename)) ep := dir.Loc{SourcePath: filepath.Join(wd, "testdata"), TargetPath: filepath.Join(wd, "testdata")} - Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tplCfg{relPath: testPath, tplContent: testTemplate, preContent: basePreVerbose, postContent: basePost, depDesc: "dev"}, true)).Should(HaveOccurred()) + Ω(makeFile(&ep, &ep, &ep, nil, makeFileName, &tplCfg{relPath: testPath, tplContent: testTemplate, preContent: basePreVerbose, postContent: basePost, depDesc: "dev"}, true, true)).Should(HaveOccurred()) }, Entry("Wrong Template", "testdata", filepath.Join("testdata", "WrongMakeTmpl.txt")), Entry("Yaml not exists", "testdata1", "make_default.txt"),