pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Cleaned up and refactored code.
details: https://anonhg.NetBSD.org/pkgsrc/rev/4b70aa45ccf8
branches: trunk
changeset: 356506:4b70aa45ccf8
user: rillig <rillig%pkgsrc.org@localhost>
date: Sun Jan 01 15:15:47 2017 +0000
description:
Cleaned up and refactored code.
The getopt and pkgver code have been extracted to separate packages to make
them reusable.
Several other functions have been moved to make the structure easier to
understand:
* dir.go and main.go have been moved to pkglint.go
* utility functions from pkglint.go have been moved to mkline.go
Now pkglint.go contains only high-level code.
diffstat:
pkgtools/pkglint/Makefile | 19 +-
pkgtools/pkglint/files/buildlink3.go | 3 +-
pkgtools/pkglint/files/category_test.go | 2 +-
pkgtools/pkglint/files/dir.go | 49 ---
pkgtools/pkglint/files/dir_test.go | 39 --
pkgtools/pkglint/files/files.go | 16 +-
pkgtools/pkglint/files/getopt.go | 232 -----------------
pkgtools/pkglint/files/getopt/getopt.go | 236 +++++++++++++++++
pkgtools/pkglint/files/getopt/getopt_test.go | 107 +++++++
pkgtools/pkglint/files/getopt_test.go | 99 -------
pkgtools/pkglint/files/globaldata.go | 2 +-
pkgtools/pkglint/files/licenses.go | 2 +-
pkgtools/pkglint/files/line.go | 4 +-
pkgtools/pkglint/files/main.go | 174 ------------
pkgtools/pkglint/files/main_test.go | 40 --
pkgtools/pkglint/files/mkline.go | 144 ++++++++++-
pkgtools/pkglint/files/mkline_test.go | 53 +++-
pkgtools/pkglint/files/mklines.go | 2 +-
pkgtools/pkglint/files/mkshparser_test.go | 4 +-
pkgtools/pkglint/files/package.go | 36 ++-
pkgtools/pkglint/files/parser.go | 9 +
pkgtools/pkglint/files/patches.go | 2 +-
pkgtools/pkglint/files/patches_test.go | 4 +-
pkgtools/pkglint/files/pkglint.go | 368 +++++++++++++++-----------
pkgtools/pkglint/files/pkglint_test.go | 104 +++++--
pkgtools/pkglint/files/pkgver/vercmp.go | 105 +++++++
pkgtools/pkglint/files/pkgver/vercmp_test.go | 72 +++++
pkgtools/pkglint/files/plist.go | 2 +-
pkgtools/pkglint/files/shell_test.go | 2 +-
pkgtools/pkglint/files/shtokenizer_test.go | 4 +-
pkgtools/pkglint/files/toplevel_test.go | 2 +-
pkgtools/pkglint/files/util.go | 9 +-
pkgtools/pkglint/files/vartype.go | 6 +-
pkgtools/pkglint/files/vartypecheck.go | 2 +-
pkgtools/pkglint/files/vercmp.go | 105 -------
pkgtools/pkglint/files/vercmp_test.go | 64 ----
36 files changed, 1070 insertions(+), 1053 deletions(-)
diffs (truncated from 2718 to 300 lines):
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Jan 01 15:06:24 2017 +0000
+++ b/pkgtools/pkglint/Makefile Sun Jan 01 15:15:47 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.505 2017/01/01 14:47:45 rillig Exp $
+# $NetBSD: Makefile,v 1.506 2017/01/01 15:15:47 rillig Exp $
PKGNAME= pkglint-5.4.14
DISTFILES= # none
@@ -10,7 +10,6 @@
LICENSE= 2-clause-bsd
CONFLICTS+= pkglint4-[0-9]*
-WRKSRC= ${WRKDIR}/netbsd.org/pkglint
NO_CHECKSUM= yes
USE_LANGUAGES= c
USE_TOOLS+= pax
@@ -19,35 +18,37 @@
SUBST_CLASSES+= pkglint
SUBST_STAGE.pkglint= post-configure
-SUBST_FILES.pkglint+= main.go package_test.go
+SUBST_FILES.pkglint+= pkglint.go package_test.go
SUBST_SED.pkglint+= -e s\|@VERSION@\|${PKGNAME:S/pkglint-//}\|g
SUBST_SED.pkglint+= -e s\|@BMAKE@\|${MAKE:Q}\|g
do-extract:
- ${RUN} mkdir -p ${WRKDIR}/pkglint/plist-clash
- ${RUN} cd ${FILESDIR} && ${PAX} -rw *.go *.y */*.go pkglint.[01] ${WRKDIR}/pkglint
+ ${RUN} cd ${FILESDIR} && ${PAX} -rw . ${WRKDIR}/pkglint
pre-build:
${RUN} env GOPATH=${WRKDIR}:${BUILDLINK_DIR}/gopkg go generate ${GO_BUILD_PATTERN}
+pre-install:
+ ${RUN} rm -rf ${WRKDIR}/pkg
+
do-install: do-install-man
.include "../../mk/bsd.prefs.mk"
do-install-man: .PHONY
-.if !empty(MANINSTALL:Mcatinstall)
-. if defined(CATMAN_SECTION_SUFFIX) && !empty(CATMAN_SECTION_SUFFIX:M[Yy][Ee][Ss])
+.if ${MANINSTALL:Mcatinstall}
+. if ${CATMAN_SECTION_SUFFIX:M[Yy][Ee][Ss]}
${INSTALL_MAN} ${WRKSRC}/pkglint.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1/pkglint.1
. else
${INSTALL_MAN} ${WRKSRC}/pkglint.0 ${DESTDIR}${PREFIX}/${PKGMANDIR}/cat1
. endif
.endif
-.if !empty(MANINSTALL:Mmaninstall)
+.if ${MANINSTALL:Mmaninstall}
${INSTALL_MAN} ${WRKSRC}/pkglint.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
.endif
.include "../../lang/go/go-package.mk"
.if !empty(PKGSRC_RUN_TEST:M[yY][eE][sS])
-.include "../../devel/go-check/buildlink3.mk"
+. include "../../devel/go-check/buildlink3.mk"
.endif
.include "../../mk/bsd.pkg.mk"
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/buildlink3.go
--- a/pkgtools/pkglint/files/buildlink3.go Sun Jan 01 15:06:24 2017 +0000
+++ b/pkgtools/pkglint/files/buildlink3.go Sun Jan 01 15:15:47 2017 +0000
@@ -1,6 +1,7 @@
package main
import (
+ "netbsd.org/pkglint/pkgver"
"strings"
)
@@ -139,7 +140,7 @@
if doCheck {
if abi != nil && abi.lower != "" && !containsVarRef(abi.lower) {
if api != nil && api.lower != "" && !containsVarRef(api.lower) {
- if pkgverCmp(abi.lower, api.lower) < 0 {
+ if pkgver.Compare(abi.lower, api.lower) < 0 {
abiLine.Warnf("ABI version %q should be at least API version %q (see %s).",
abi.lower, api.lower, apiLine.ReferenceFrom(abiLine))
}
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go Sun Jan 01 15:06:24 2017 +0000
+++ b/pkgtools/pkglint/files/category_test.go Sun Jan 01 15:15:47 2017 +0000
@@ -11,7 +11,7 @@
"# $\n"+
"SUBDIR+=pkg1\n"+
"SUBDIR+=\u0020aaaaa\n"+
- "SUBDIR-=unknown #doesnâ??t work\n"+
+ "SUBDIR-=unknown #doesn\u2019t work\n"+
"\n"+
".include \"../mk/category.mk\"\n")
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/dir.go
--- a/pkgtools/pkglint/files/dir.go Sun Jan 01 15:06:24 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-package main
-
-import (
- "os"
- "path"
-)
-
-func CheckDirent(fname string) {
- if G.opts.Debug {
- defer tracecall1(fname)()
- }
-
- st, err := os.Lstat(fname)
- if err != nil || !st.Mode().IsDir() && !st.Mode().IsRegular() {
- NewLineWhole(fname).Errorf("No such file or directory.")
- return
- }
- isDir := st.Mode().IsDir()
- isReg := st.Mode().IsRegular()
-
- G.CurrentDir = ifelseStr(isReg, path.Dir(fname), fname)
- absCurrentDir := abspath(G.CurrentDir)
- G.Wip = !G.opts.Import && matches(absCurrentDir, `/wip/|/wip$`)
- G.Infrastructure = matches(absCurrentDir, `/mk/|/mk$`)
- G.CurPkgsrcdir = findPkgsrcTopdir(G.CurrentDir)
- if G.CurPkgsrcdir == "" {
- NewLineWhole(fname).Errorf("Cannot determine the pkgsrc root directory for %q.", G.CurrentDir)
- return
- }
-
- switch {
- case isDir && isEmptyDir(fname):
- return
- case isReg:
- Checkfile(fname)
- return
- }
-
- switch G.CurPkgsrcdir {
- case "../..":
- checkdirPackage(relpath(G.globalData.Pkgsrcdir, G.CurrentDir))
- case "..":
- CheckdirCategory()
- case ".":
- CheckdirToplevel()
- default:
- NewLineWhole(fname).Errorf("Cannot check directories outside a pkgsrc tree.")
- }
-}
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/dir_test.go
--- a/pkgtools/pkglint/files/dir_test.go Sun Jan 01 15:06:24 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-package main
-
-import (
- check "gopkg.in/check.v1"
-)
-
-func (s *Suite) Test_CheckDirent_outside(c *check.C) {
- s.Init(c)
- s.CreateTmpFile("empty", "")
-
- CheckDirent(s.tmpdir)
-
- c.Check(s.Output(), equals, "ERROR: ~: Cannot determine the pkgsrc root directory for \"~\".\n")
-}
-
-func (s *Suite) Test_CheckDirent(c *check.C) {
- s.Init(c)
- s.CreateTmpFile("mk/bsd.pkg.mk", "")
- s.CreateTmpFile("category/package/Makefile", "")
- s.CreateTmpFile("category/Makefile", "")
- s.CreateTmpFile("Makefile", "")
- G.globalData.Pkgsrcdir = s.tmpdir
-
- CheckDirent(s.tmpdir)
-
- c.Check(s.Output(), equals, "ERROR: ~/Makefile: Must not be empty.\n")
-
- CheckDirent(s.tmpdir + "/category")
-
- c.Check(s.Output(), equals, "ERROR: ~/category/Makefile: Must not be empty.\n")
-
- CheckDirent(s.tmpdir + "/category/package")
-
- c.Check(s.Output(), equals, "ERROR: ~/category/package/Makefile: Must not be empty.\n")
-
- CheckDirent(s.tmpdir + "/category/package/nonexistent")
-
- c.Check(s.Output(), equals, "ERROR: ~/category/package/nonexistent: No such file or directory.\n")
-}
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/files.go
--- a/pkgtools/pkglint/files/files.go Sun Jan 01 15:06:24 2017 +0000
+++ b/pkgtools/pkglint/files/files.go Sun Jan 01 15:15:47 2017 +0000
@@ -6,8 +6,8 @@
"strings"
)
-func LoadNonemptyLines(fname string, joinContinuationLines bool) []*Line {
- lines, err := readLines(fname, joinContinuationLines)
+func LoadNonemptyLines(fname string, joinBackslashLines bool) []*Line {
+ lines, err := readLines(fname, joinBackslashLines)
if err != nil {
NewLineWhole(fname).Errorf("Cannot be read.")
return nil
@@ -19,8 +19,8 @@
return lines
}
-func LoadExistingLines(fname string, foldBackslashLines bool) []*Line {
- lines, err := readLines(fname, foldBackslashLines)
+func LoadExistingLines(fname string, joinBackslashLines bool) []*Line {
+ lines, err := readLines(fname, joinBackslashLines)
if err != nil {
NewLineWhole(fname).Fatalf("Cannot be read.")
}
@@ -101,16 +101,16 @@
return
}
-func readLines(fname string, joinContinuationLines bool) ([]*Line, error) {
+func readLines(fname string, joinBackslashLines bool) ([]*Line, error) {
rawText, err := ioutil.ReadFile(fname)
if err != nil {
return nil, err
}
- return convertToLogicalLines(fname, string(rawText), joinContinuationLines), nil
+ return convertToLogicalLines(fname, string(rawText), joinBackslashLines), nil
}
-func convertToLogicalLines(fname string, rawText string, joinContinuationLines bool) []*Line {
+func convertToLogicalLines(fname string, rawText string, joinBackslashLines bool) []*Line {
var rawLines []*RawLine
for lineno, rawLine := range strings.SplitAfter(rawText, "\n") {
if rawLine != "" {
@@ -119,7 +119,7 @@
}
var loglines []*Line
- if joinContinuationLines {
+ if joinBackslashLines {
for lineno := 0; lineno < len(rawLines); {
loglines = append(loglines, getLogicalLine(fname, rawLines, &lineno))
}
diff -r 26e8fced05c3 -r 4b70aa45ccf8 pkgtools/pkglint/files/getopt.go
--- a/pkgtools/pkglint/files/getopt.go Sun Jan 01 15:06:24 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,232 +0,0 @@
-package main
-
-// Self-written getopt to support multi-argument options.
-
-import (
- "fmt"
- "io"
- "strings"
- "text/tabwriter"
- "unicode/utf8"
-)
-
-type Options struct {
- options []*option
-}
-
-func NewOptions() *Options {
- return new(Options)
-}
-
-func (o *Options) AddFlagGroup(shortName rune, longName, argDescription, description string) *FlagGroup {
- grp := new(FlagGroup)
- opt := &option{shortName, longName, argDescription, description, grp}
- o.options = append(o.options, opt)
- return grp
-}
-
-func (o *Options) AddFlagVar(shortName rune, longName string, pflag *bool, defval bool, description string) {
- *pflag = defval
- opt := &option{shortName, longName, "", description, pflag}
- o.options = append(o.options, opt)
-}
-
-func (o *Options) Parse(args []string) (remainingArgs []string, err error) {
- var skip int
- for i := 1; i < len(args) && err == nil; i++ {
- arg := args[i]
- switch {
- case arg == "--":
- remainingArgs = append(remainingArgs, args[i+1:]...)
- return
- case hasPrefix(arg, "--"):
- skip, err = o.parseLongOption(args, i, arg[2:])
- i += skip
- case hasPrefix(arg, "-"):
- skip, err = o.parseShortOptions(args, i, arg[1:])
- i += skip
- default:
- remainingArgs = append(remainingArgs, arg)
- }
- }
- if err != nil {
Home |
Main Index |
Thread Index |
Old Index