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

fix license header test #1492

Merged
merged 5 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions LICENSE.header

This file was deleted.

6 changes: 3 additions & 3 deletions ipcs/socket/socket_unix.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !windows && !plan9 && !js
// +build !windows,!plan9,!js

Comment on lines 1 to +6
Copy link
Contributor Author

@dhrubabasu dhrubabasu May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/cmd/go#hdr-Build_constraints

Constraints may appear in any kind of source file (not just Go), but they must appear near the top of the file, preceded only by blank lines and other line comments. These rules mean that in Go files a build constraint must appear before the package clause.

To distinguish build constraints from package documentation, a build constraint should be followed by a blank line.

package socket

import (
Expand Down
6 changes: 3 additions & 3 deletions ipcs/socket/socket_windows.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build windows
// +build windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build windows
// +build windows

package socket

import (
Expand Down
4 changes: 4 additions & 0 deletions license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
header: |
// Copyright (C) 2019-{{YEAR}}, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

22 changes: 7 additions & 15 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,17 @@ function test_golangci_lint {
golangci-lint run --config .golangci.yml
}

# find_go_files [package]
# all go files except generated ones
function find_go_files {
local target="${1}"
go fmt -n "${target}" | grep -Eo "([^ ]*)$" | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)"
}

# automatically checks license headers
# to modify the file headers (if missing), remove "--check" flag
# TESTS='license_header' ADDLICENSE_FLAGS="-v" ./scripts/lint.sh
_addlicense_flags=${ADDLICENSE_FLAGS:-"--check -v"}
# to modify the file headers (if missing), remove "--verify" flag
# TESTS='license_header' ADDLICENSE_FLAGS="--debug" ./scripts/lint.sh
_addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"}
function test_license_header {
go install -v github.com/google/addlicense@latest
local target="${1}"
go install -v github.com/palantir/go-license@v1.25.0
local files=()
while IFS= read -r line; do files+=("$line"); done < <(find_go_files "${target}")
while IFS= read -r line; do files+=("$line"); done < <(find . -type f -name '*.go' ! -name '*.pb.go' ! -name 'mock_*.go')

addlicense \
-f ./LICENSE.header \
go-license \
--config=./license.yml \
${_addlicense_flags} \
"${files[@]}"
}
Expand Down
13 changes: 12 additions & 1 deletion scripts/mock.gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ then
go install -v github.com/golang/mock/mockgen@v1.6.0
fi

if ! command -v go-license &> /dev/null
then
echo "go-license not found, installing..."
# https://github.com/palantir/go-license
go install -v github.com/palantir/go-license@v1.25.0
fi

# tuples of (source interface import path, comma-separated interface names, output file path)
input="scripts/mocks.mockgen.txt"
while IFS= read -r line
do
IFS='=' read src_import_path interface_name output_path <<< "${line}"
package_name=$(basename $(dirname $output_path))
echo "Generating ${output_path}..."
mockgen -copyright_file=./LICENSE.header -package=${package_name} -destination=${output_path} ${src_import_path} ${interface_name}
mockgen -package=${package_name} -destination=${output_path} ${src_import_path} ${interface_name}

go-license \
--config=./license.yml \
"${output_path}"
done < "$input"

echo "SUCCESS"
1 change: 1 addition & 0 deletions snow/engine/snowman/block/height_indexed_vm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package block

import (
Expand Down
2 changes: 1 addition & 1 deletion utils/linkedhashmap/iterator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2023, Ava Labs, Inte. All rights reserved.
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package linkedhashmap
Expand Down
2 changes: 1 addition & 1 deletion utils/linkedhashmap/linkedhashmap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2023, Ava Labs, Inte. All rights reserved.
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package linkedhashmap
Expand Down
6 changes: 3 additions & 3 deletions utils/storage/storage_unix.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !windows
// +build !windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !windows
// +build !windows

package storage

import "syscall"
Expand Down
6 changes: 3 additions & 3 deletions utils/storage/storage_windows.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build windows
// +build windows

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build windows
// +build windows

package storage

import (
Expand Down
6 changes: 3 additions & 3 deletions vms/rpcchainvm/runtime/subprocess/linux_stopper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build linux
// +build linux

// ^ SIGTERM signal is not available on Windows
// ^ syscall.SysProcAttr only has field Pdeathsig on Linux

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package subprocess

import (
Expand Down
6 changes: 3 additions & 3 deletions vms/rpcchainvm/runtime/subprocess/non_linux_stopper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//go:build !linux
// +build !linux

// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:build !linux
// +build !linux

package subprocess

import (
Expand Down