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 version constant #289

Merged
merged 6 commits into from
Aug 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v1
with:
go-version: '1.13.10'
Expand All @@ -18,7 +20,7 @@ jobs:
${{ runner.os }}-go-
- run: |
make test
make tidy
make check-tidy
make check-headers
lint:
runs-on: ubuntu-latest
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ install-tools:
lint:
golangci-lint run -v ./...

# this ensures there is no unused dependency being added by accident
.PHONY: tidy
tidy:
go mod tidy; git diff --exit-code

.PHONY: check-headers
check-headers:
@./check-headers.sh

.PHONY: check-tidy
check-tidy:
go generate -v ./...
go mod tidy
cd languageserver; go mod tidy
git diff --exit-code
2 changes: 1 addition & 1 deletion runtime/ast/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=Access
//go:generate go run golang.org/x/tools/cmd/stringer -type=Access

type Access uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/ast/conditionkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=ConditionKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=ConditionKind

type ConditionKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/ast/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=Operation
//go:generate go run golang.org/x/tools/cmd/stringer -type=Operation

type Operation uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/ast/transferoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=TransferOperation
//go:generate go run golang.org/x/tools/cmd/stringer -type=TransferOperation

type TransferOperation uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/ast/variablekind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=VariableKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=VariableKind

type VariableKind uint

Expand Down
3 changes: 2 additions & 1 deletion runtime/cmd/execute/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/c-bata/go-prompt"
"github.com/logrusorgru/aurora"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/runtime/cmd"
"github.com/onflow/cadence/runtime/interpreter"
Expand Down Expand Up @@ -144,7 +145,7 @@ func handleCommand(command string) {
}

func printWelcome() {
fmt.Printf("Welcome to Cadence!\n%s\n\n", assistanceMessage)
fmt.Printf("Welcome to Cadence %s!\n%s\n\n", cadence.Version, assistanceMessage)
}

func colorizeResult(value interpreter.Value) string {
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/compositekind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=CompositeKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=CompositeKind

type CompositeKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/controlstatement.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=ControlStatement
//go:generate go run golang.org/x/tools/cmd/stringer -type=ControlStatement

type ControlStatement uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/declarationkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=DeclarationKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=DeclarationKind

type DeclarationKind uint

Expand Down
5 changes: 3 additions & 2 deletions runtime/common/declarationkind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/common/operandside.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=OperandSide
//go:generate go run golang.org/x/tools/cmd/stringer -type=OperandSide

type OperandSide uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/operationkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=OperationKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=OperationKind

type OperationKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/pathdomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=PathDomain
//go:generate go run golang.org/x/tools/cmd/stringer -type=PathDomain

type PathDomain uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/primitivestatictype.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/onflow/cadence/runtime/sema"
)

//go:generate stringer -type=PrimitiveStaticType -trimprefix=PrimitiveStaticType
//go:generate go run golang.org/x/tools/cmd/stringer -type=PrimitiveStaticType -trimprefix=PrimitiveStaticType

// PrimitiveStaticType

Expand Down
2 changes: 1 addition & 1 deletion runtime/parser2/integerliteralkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=IntegerLiteralKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=IntegerLiteralKind

type IntegerLiteralKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/parser2/invalidnumberliteralkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=InvalidNumberLiteralKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=InvalidNumberLiteralKind

type InvalidNumberLiteralKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/accesscheckmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package sema

//go:generate stringer -type=AccessCheckMode
//go:generate go run golang.org/x/tools/cmd/stringer -type=AccessCheckMode

type AccessCheckMode uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/binaryoperationkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=BinaryOperationKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=BinaryOperationKind

type BinaryOperationKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/containerkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package sema

//go:generate stringer -type=ContainerKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=ContainerKind

type ContainerKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/resourceinvalidationkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/onflow/cadence/runtime/errors"
)

//go:generate stringer -type=ResourceInvalidationKind
//go:generate go run golang.org/x/tools/cmd/stringer -type=ResourceInvalidationKind

type ResourceInvalidationKind uint

Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/typeannotationstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package sema

//go:generate stringer -type=TypeAnnotationState
//go:generate go run golang.org/x/tools/cmd/stringer -type=TypeAnnotationState

type TypeAnnotationState uint

Expand Down
82 changes: 82 additions & 0 deletions utils/version/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright 2019-2020 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"os"
"os/exec"
"strings"
)

const template string = `// Code generated by utils/version. DO NOT EDIT.
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright 2019-2020 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

%s

package cadence

const Version = "%s"
`

const goGenerateComment = "//go:generate go run ./utils/version generate"

const target = "version.go"

func main() {
version := getLastTag()

f, err := os.Create(target)
if err != nil {
panic(fmt.Errorf("could not create file %s: %w\n", target, err))
}
defer func() {
_ = f.Close()
}()

_, err = f.WriteString(fmt.Sprintf(template, goGenerateComment, version))
if err != nil {
panic(fmt.Errorf("could not write to %s: %w\n", target, err))
}
}

func getLastTag() string {
gitOutput, err := exec.Command("git", "describe", "--tags", "--match", `v*`, "--abbrev=0").Output()
if err != nil {
panic(fmt.Errorf("could not get last tag: %w", err))
}

return strings.TrimSpace(string(gitOutput))
}
24 changes: 24 additions & 0 deletions version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.