Skip to content

Commit

Permalink
Prepare for Go 1.18 by replacing all our forked code (#549)
Browse files Browse the repository at this point in the history
* Prepare for Go 1.18 by replacing all our forked code

This hides our forked-from-gotip code behind a build tag so it's only
used when the build is run on Go <1.18. For builds >= 1.18, we'll use
the actual runtime/debug and debug/buildinfo packages.

Add preliminary support for building on Go 1.18beta1 to our Build
matrix, to ensure this code builds. It's all a terrible hack, but it'll
get less so when 1.18 is actually released.

* Fix lint and boilerplate
  • Loading branch information
imjasonh committed Dec 15, 2021
1 parent 6cc2d7f commit b813b95
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@ on:
jobs:

build:
name: Build
strategy:
fail-fast: false
matrix:
go-version: ['1.17.x', '1.18.x']
name: Build ${{ matrix.go-version }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.17.x
# TODO: when 1.18 is released, just make this
# ${{ matrix.go-version }} and delete the next step.
go-version: '1.17.x'

# Use the installed Go version to download and install the latest 1.18
# beta and replace our existing go with that one.
- if: ${{ matrix.go-version == '1.18.x' }}
run: |
go install golang.org/dl/go1.18beta1@latest
go1.18beta1 download
cp $(which go1.18beta1) $(which go)
go version
- run: |
go build ./...
Expand Down
3 changes: 3 additions & 0 deletions internal/sbom/mod.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !go1.18
// +build !go1.18

// Copyright 2021 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
33 changes: 33 additions & 0 deletions internal/sbom/mod_1.18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build go1.18
// +build go1.18

// Copyright 2021 Google LLC All Rights Reserved.
//
// 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 sbom

import (
"runtime/debug"
)

type BuildInfo debug.BuildInfo

func (bi *BuildInfo) UnmarshalText(data []byte) error {
dbi := (*debug.BuildInfo)(bi)
if err := dbi.UnmarshalText(data); err != nil {
return err
}
bi = (*BuildInfo)(dbi)
return nil
}

0 comments on commit b813b95

Please sign in to comment.