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

Add go:build tags #3185

Merged
merged 5 commits into from
Sep 2, 2021
Merged

Commits on Aug 31, 2021

  1. *: rm redundant linux build tag

    For files that end with _linux.go or _linux_test.go, there is no need to
    specify linux build tag, as it is assumed from the file name.
    
    In addition, rename libcontainer/notify_linux_v2.go -> libcontainer/notify_v2_linux.go
    for the file name to make sense.
    
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    kolyshkin committed Aug 31, 2021
    Configuration menu
    Copy the full SHA
    9ff64c3 View commit details
    Browse the repository at this point in the history
  2. Rm build tags from main pkg

    This was added by commit 5aa82c9 back in the day when we thought
    runc is going to be cross-platform. It's very clear now it's Linux-only
    package.
    
    While at it, further clarify it in README that we're Linux only.
    
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    kolyshkin committed Aug 31, 2021
    Configuration menu
    Copy the full SHA
    c5b0be7 View commit details
    Browse the repository at this point in the history
  3. libct/*: remove linux build tag from some pkgs

    Only some libcontainer packages can be built on non-linux platforms
    (not that it make sense, but at least go build succeeds). Let's call
    these "good" packages.
    
    For all other packages (i.e. ones that fail to build with GOOS other
    than linux), it does not make sense to have linux build tag (as they
    are broken already, and thus are not and can not be used on anything
    other than Linux).
    
    Remove linux build tag for all non-"good" packages.
    
    This was mostly done by the following script, with just a few manual
    fixes on top.
    
    function list_good_pkgs() {
    	for pkg in $(find . -type d -print); do
    		GOOS=freebsd go build $pkg 2>/dev/null \
    		&& GOOS=solaris go build $pkg 2>/dev/null \
    		&& echo $pkg
    	done | sed -e 's|^./||' | tr '\n' '|' | sed -e 's/|$//'
    }
    
    function remove_tag() {
    	sed -i -e '\|^// +build linux$|d' $1
    	go fmt $1
    }
    
    SKIP="^("$(list_good_pkgs)")"
    for f in $(git ls-files . | grep .go$); do
    	if echo $f | grep -qE "$SKIP"; then
    		echo skip $f
    		continue
    	fi
    	echo proc $f
    	remove_tag $f
    done
    
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    kolyshkin committed Aug 31, 2021
    Configuration menu
    Copy the full SHA
    dbb9fc0 View commit details
    Browse the repository at this point in the history
  4. libct/cg: rm "unsupported.go" files

    These are not needed as these packages (libcontainer/cgroups,
    libcontainer/cgroups/fs, and libcontainer/cgroups/systemd) can
    not be built under non-linux anyway (for various reasons).
    
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    kolyshkin committed Aug 31, 2021
    Configuration menu
    Copy the full SHA
    1b17ec9 View commit details
    Browse the repository at this point in the history
  5. *: add go-1.17+ go:build tags

    Go 1.17 introduce this new (and better) way to specify build tags.
    For more info, see https://golang.org/design/draft-gobuild.
    
    As a way to seamlessly switch from old to new build tags, gofmt (and
    gopls) from go 1.17 adds the new tags along with the old ones.
    
    Later, when go < 1.17 is no longer supported, the old build tags
    can be removed.
    
    Now, as I started to use latest gopls (v0.7.1), it adds these tags
    while I edit. Rather than to randomly add new build tags, I guess
    it is better to do it once for all files.
    
    Mind that previous commits removed some tags that were useless,
    so this one only touches packages that can at least be built
    on non-linux.
    
    Brought to you by
    
            go1.17 fmt ./...
    
    Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
    kolyshkin committed Aug 31, 2021
    Configuration menu
    Copy the full SHA
    d8da003 View commit details
    Browse the repository at this point in the history