Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial playground #2

Merged
merged 51 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
478afc1
Initial playground
thorstendb-ARM Sep 18, 2023
c49b69d
Update TPIP report
invalid-email-address Sep 18, 2023
633e4d1
added:
thorstendb-ARM Sep 20, 2023
bd8b8a5
Update TPIP report
invalid-email-address Sep 20, 2023
32df2dd
calling stm32CubeMX with JRE
thorstendb-ARM Sep 22, 2023
fdfec35
reading .mxproject ini file
thorstendb-ARM Sep 22, 2023
c645881
backup
thorstendb-ARM Sep 22, 2023
7219aad
added: cgen.yml output generator
thorstendb-ARM Sep 25, 2023
7435d3b
implemented workflow for single core
thorstendb-ARM Sep 26, 2023
87985c5
changed structure
thorstendb-ARM Sep 27, 2023
435c954
Added issues template, copyright checker and workflow improvments
soumeh01 Sep 18, 2023
843d37f
Added release workflow
soumeh01 Sep 20, 2023
7c256a4
Update TPIP run strategy
soumeh01 Sep 21, 2023
873bba6
Update TPIP report
soumeh01 Sep 21, 2023
57dd625
Update TPIP report
soumeh01 Sep 24, 2023
a13972d
Update TPIP schedule
soumeh01 Sep 22, 2023
630a4f8
Update TPIP report
invalid-email-address Sep 18, 2023
db15035
Update TPIP report
invalid-email-address Sep 20, 2023
e6e1a6b
updated copyright notes
thorstendb-ARM Sep 27, 2023
0282577
Merge branch 'main' into cmdLine
thorstendb-ARM Sep 27, 2023
78e7361
Updated go.mod and go.sum files
soumeh01 Sep 27, 2023
ece3622
ran "go mod tidy"
thorstendb-ARM Sep 27, 2023
fde29aa
linter
thorstendb-ARM Sep 27, 2023
b4c128b
linter
thorstendb-ARM Sep 27, 2023
b7f1024
linter
thorstendb-ARM Sep 27, 2023
74c0616
linter
thorstendb-ARM Sep 27, 2023
acde0b9
linter
thorstendb-ARM Sep 27, 2023
5518667
linter
thorstendb-ARM Sep 27, 2023
35d8d56
linter
thorstendb-ARM Sep 27, 2023
8e836f4
fixed procect path for STM32CubeMX (project.script file) in Windows, …
thorstendb-ARM Sep 29, 2023
1931f7e
filtered "Templates" files (which seem to be not present and moved in…
thorstendb-ARM Sep 29, 2023
289446f
cleanup
thorstendb-ARM Sep 29, 2023
7c00384
added "output" path from main layer cgen-idx file
thorstendb-ARM Sep 29, 2023
0c1428e
added: writing output file per su-file (from idx.yml)
thorstendb-ARM Sep 29, 2023
1fb4507
prepared for CPU filtering in .mxproject
thorstendb-ARM Sep 29, 2023
9eb4231
added Multicore and Trustzone support
thorstendb-ARM Oct 4, 2023
a3c5ab4
multi-core support
thorstendb-ARM Oct 5, 2023
ce508ed
fixed
thorstendb-ARM Oct 5, 2023
d68fd27
store Reference project for TZ-NS
thorstendb-ARM Oct 5, 2023
8e69128
fixed noTZ project
thorstendb-ARM Oct 5, 2023
38ab0d4
fixed noTZ with Core
thorstendb-ARM Oct 5, 2023
6da5ed3
added tests
thorstendb-ARM Nov 8, 2023
d5ebc2d
changed:
thorstendb-ARM Nov 8, 2023
0564d10
changed:
thorstendb-ARM Nov 9, 2023
41737b4
Linter, removed test which runs in "Debug" but not in "Run"
thorstendb-ARM Nov 13, 2023
f5f5849
Updated to go 1.21
thorstendb-ARM Nov 13, 2023
a0dc41d
Updated to go 1.21
thorstendb-ARM Nov 13, 2023
f601f22
checked return value (Linter)
thorstendb-ARM Nov 13, 2023
d2a166d
Merge branch 'main' into cmdLine
soumeh01 Nov 13, 2023
3223a41
fixed "copyright"
thorstendb-ARM Nov 13, 2023
ba7de17
upper/lower case
thorstendb-ARM Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .devcontainer/ubuntu-22.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:23.04

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get -y install \
build-essential \
curl \
less \
git \
golang \
gopls \
delve \
go-staticcheck

RUN go install honnef.co/go/tools/cmd/staticcheck@latest

CMD ["/bin/bash"]
13 changes: 13 additions & 0 deletions .devcontainer/ubuntu-22.04/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Ubuntu-23.04",
"build": { "dockerfile": "Dockerfile" },

"customizations": {
"vscode": {
"extensions": [
"golang.go",
"ms-azuretools.vscode-docker"
]
}
}
}
141 changes: 141 additions & 0 deletions cmd/commands/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright (c) 2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package commands

import (
"errors"
"fmt"
"io"
"strings"

readfile "github.com/open-cmsis-pack/generator-bridge/internal/readFile"
stm32cubemx "github.com/open-cmsis-pack/generator-bridge/internal/stm32CubeMX"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// AllCommands contains all available commands for generator-bridge
var AllCommands = []*cobra.Command{}

var rootCommand *cobra.Command = nil

func GetConfig() *pflag.FlagSet {
return rootCommand.PersistentFlags()
}

// configureInstaller configures generator-bridge installer for adding or removing pack/pdsc
func configureGlobalCmd(cmd *cobra.Command, args []string) error {
verbosiness, _ := GetConfig().GetBool("verbose")
quiet, _ := GetConfig().GetBool("quiet")
if quiet && verbosiness {
return errors.New("both \"-q\" and \"-v\" were specified, please pick only one verboseness option")
}

log.SetLevel(log.InfoLevel)
log.SetOutput(cmd.OutOrStdout())

if quiet {
log.SetLevel(log.ErrorLevel)
}

if verbosiness {
log.SetLevel(log.DebugLevel)
}

return nil
}

var flags struct {
version bool
help bool
inFile string
inFile2 string
thorstendb-ARM marked this conversation as resolved.
Show resolved Hide resolved
outPath string
}

var Version string
var Copyright string

func printVersionAndLicense(file io.Writer) {
fmt.Fprintf(file, "generator-bridge version %v %s\n", strings.ReplaceAll(Version, "v", ""), Copyright)
}

// UsageTemplate returns usage template for the command.
var usageTemplate = `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if gt (len .Aliases) 0}}

Aliases:
{{.NameAndAliases}}{{end}}{{if .HasExample}}

Examples:
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}

Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}

Flags:
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}

Global Flags:
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}

Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}

Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`

func NewCli() *cobra.Command {
rootCmd := &cobra.Command{
Use: "generator-bridge [command] [flags]",
Short: "This utility is a bridge to Vendor tools, e.g. STCube",
Long: "Please refer to the upstream repository for further information: https://github.com/Open-CMSIS-Pack/generator-bridge.",
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: configureGlobalCmd,
RunE: func(cmd *cobra.Command, args []string) error {
if flags.version {
printVersionAndLicense(cmd.OutOrStdout())
return nil
}

if flags.help {
return cmd.Help()
}

if flags.inFile != "" {
return readfile.Process(flags.inFile, flags.inFile2, flags.outPath)
}

if len(args) == 1 {
cbuildYmlPath := args[0]
return stm32cubemx.Process(cbuildYmlPath, flags.outPath, "", "", true)
}

return cmd.Help()
},
}

rootCmd.SetUsageTemplate(usageTemplate)

rootCmd.Flags().BoolVarP(&flags.version, "version", "V", false, "Prints the version number of generator-bridge and exit")
rootCmd.Flags().BoolVarP(&flags.help, "help", "h", false, "Show help")
rootCmd.Flags().StringVarP(&flags.inFile, "read", "r", "", "Reads an input file, type is auto determined")
rootCmd.Flags().StringVarP(&flags.inFile2, "file", "f", "", "Additional input file, type is auto determined")
rootCmd.Flags().StringVarP(&flags.outPath, "out", "o", "", "Output path for generated files")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Run silently, printing only error messages")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Sets verboseness level: None (Errors + Info + Warnings), -v (all + Debugging). Specify \"-q\" for no messages")

for _, cmd := range AllCommands {
rootCmd.AddCommand(cmd)
}

rootCommand = rootCmd

return rootCmd
}
7 changes: 7 additions & 0 deletions cmd/commands/commands_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package commands_test
41 changes: 41 additions & 0 deletions cmd/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package errors

import (
"errors"
)

// Is returns true if err is equals to target
func Is(err, target error) bool {
return err == target
}

var (
// Errors related to file system
ErrFailedCreatingFile = errors.New("failed to create a local file")
ErrFailedWrittingToLocalFile = errors.New("failed writing HTTP stream to local file")
ErrFailedDecompressingFile = errors.New("fail to decompress file")
ErrFailedInflatingFile = errors.New("fail to inflate file")
ErrFailedCreatingDirectory = errors.New("fail to create directory")
ErrFileNotFound = errors.New("file not found")
ErrDirectoryNotFound = errors.New("directory not found")
ErrPathAlreadyExists = errors.New("path already exists")
ErrCopyingEqualPaths = errors.New("failed copying files: source is the same as destination")
ErrMovingEqualPaths = errors.New("failed moving files: source is the same as destination")

// Security errors
ErrInsecureZipFileName = errors.New("zip file contains insecure characters: ../")
ErrFileTooBig = errors.New("files cannot be over 20G")
ErrIndexPathNotSafe = errors.New("index url path does not start with HTTPS")

// Cmdline errors
ErrIncorrectCmdArgs = errors.New("incorrect setup of command line arguments")

// Error/Flag to detect when a user has requested early termination
ErrTerminatedByUser = errors.New("terminated by user request")
)
24 changes: 24 additions & 0 deletions cmd/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package main

import (
"fmt"
"strings"

log "github.com/sirupsen/logrus"
)

// LogFormatter is generator-bridge's basic log formatter
type LogFormatter struct{}

// Format prints out logs like "I: some message", where the first letter indicates (I)NFO, (D)EBUG, (W)ARNING or (E)RROR
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
level := strings.ToUpper(entry.Level.String())
msg := fmt.Sprintf("%s: %s\n", level[0:1], entry.Message)
return []byte(msg), nil
}
29 changes: 22 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@
package main

import (
"fmt"
"strings"
"os"
"time"

"github.com/google/uuid"
"github.com/open-cmsis-pack/generator-bridge/cmd/commands"
"github.com/open-cmsis-pack/generator-bridge/internal/utils"
log "github.com/sirupsen/logrus"
)

func main() {
uuidWithHyphen, _ := uuid.NewRandom()
uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
fmt.Println(uuid)
fmt.Println("Hello, World!")
log.SetFormatter(new(LogFormatter))
log.SetOutput(os.Stdout)

utils.StartSignalWatcher()
start := time.Now()

commands.Version = version
commands.Copyright = copyright
cmd := commands.NewCli()
err := cmd.Execute()
if err != nil {
log.Errorf("Error : %v", err)
os.Exit(-1)
}

log.Debugf("Took %v", time.Since(start))
utils.StopSignalWatcher()
}
11 changes: 11 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2023 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package main

var version string

const copyright = "(C) 2023 Arm Ltd."
24 changes: 21 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
module cmd
module github.com/open-cmsis-pack/generator-bridge

go 1.20
go 1.21

require github.com/google/uuid v1.3.1
require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
41 changes: 39 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading