@@ -11,14 +11,12 @@ import (
1111 "bytes"
1212 "context"
1313 "fmt"
14- "io"
1514 "os"
1615 "os/exec"
1716 "path/filepath"
1817 "runtime"
1918 "strconv"
2019 "strings"
21- "sync"
2220 "time"
2321
2422 "github.com/hashicorp/go-multierror"
@@ -30,8 +28,6 @@ import (
3028
3129 devtools "github.com/elastic/elastic-agent/dev-tools/mage"
3230
33- devtoolslibs "github.com/elastic/elastic-agent-libs/dev-tools/mage"
34-
3531 // mage:import
3632 "github.com/elastic/elastic-agent/dev-tools/mage/target/common"
3733
@@ -95,77 +91,6 @@ type Demo mg.Namespace
9591// Dev runs package and build for dev purposes.
9692type Dev mg.Namespace
9793
98- // Notice regenerates the NOTICE.txt file.
99- func Notice () error {
100- fmt .Println (">> Generating NOTICE" )
101- fmt .Println (">> fmt - go mod tidy" )
102- err := sh .RunV ("go" , "mod" , "tidy" , "-v" )
103- if err != nil {
104- return errors .Wrap (err , "failed running go mod tidy, please fix the issues reported" )
105- }
106- fmt .Println (">> fmt - go mod download" )
107- err = sh .RunV ("go" , "mod" , "download" )
108- if err != nil {
109- return errors .Wrap (err , "failed running go mod download, please fix the issues reported" )
110- }
111- fmt .Println (">> fmt - go list" )
112- str , err := sh .Output ("go" , "list" , "-m" , "-json" , "all" )
113- if err != nil {
114- return errors .Wrap (err , "failed running go list, please fix the issues reported" )
115- }
116- fmt .Println (">> fmt - go run" )
117- goLicenceDetectorCMD := []string {"go" ,
118- "run" ,
119- "go.elastic.co/go-licence-detector" ,
120- "-includeIndirect" ,
121- "-rules" ,
122- "dev-tools/notice/rules.json" ,
123- "-overrides" ,
124- "dev-tools/notice/overrides.json" ,
125- "-noticeTemplate" ,
126- "dev-tools/notice/NOTICE.txt.tmpl" ,
127- "-noticeOut" ,
128- "NOTICE.txt" ,
129- }
130- printCMD (goLicenceDetectorCMD )
131- cmd := exec .Command (goLicenceDetectorCMD [0 ], goLicenceDetectorCMD [1 :]... )
132- stdin , err := cmd .StdinPipe ()
133- if err != nil {
134- return errors .Wrap (err , "failed running go run, please fix the issues reported" )
135- }
136- var wg sync.WaitGroup
137- wg .Add (1 )
138- go func () {
139- defer stdin .Close ()
140- defer wg .Done ()
141- if _ , err := io .WriteString (stdin , str ); err != nil {
142- fmt .Println (err )
143- }
144- }()
145- out , err := cmd .CombinedOutput ()
146- wg .Wait ()
147- if err != nil {
148- return fmt .Errorf ("calling go-licence-detector returned an error: '%w'. Its output is: '%s'" , err , string (out ))
149- }
150-
151- noticeFile , err := os .OpenFile ("NOTICE.txt" , os .O_APPEND | os .O_WRONLY , 0644 )
152- if err != nil {
153- return fmt .Errorf ("cannot open NOTICE.txt for appending: %w" , err )
154- }
155- defer noticeFile .Close ()
156-
157- toAppendNotice , err := os .ReadFile (filepath .Join ("dev-tools" , "notice" , "NOTICE.txt.append" ))
158- if err != nil {
159- return fmt .Errorf ("cannot read notice file to be appended: %w" , err )
160- }
161-
162- if _ , err := noticeFile .Write (toAppendNotice ); err != nil {
163- return fmt .Errorf ("cannot append data to NOTICE.txt: %w" , err )
164- }
165-
166- return nil
167- }
168-
16994func CheckNoChanges () error {
17095 fmt .Println (">> fmt - go run" )
17196 err := sh .RunV ("go" , "mod" , "tidy" , "-v" )
@@ -975,12 +900,3 @@ func printCMD(cmd []string) {
975900
976901 fmt .Println (buff .String ())
977902}
978-
979- // Notice generates a NOTICE.txt file for the module.
980- func NoticeLib () error {
981- return devtoolslibs .GenerateNotice (
982- filepath .Join ("dev-tools" , "notice" , "overrides.json" ),
983- filepath .Join ("dev-tools" , "notice" , "rules.json" ),
984- filepath .Join ("dev-tools" , "notice" , "NOTICE.txt.tmpl" ),
985- )
986- }
0 commit comments