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

Skip .bzl files generated by cargo raze. #52

Merged
merged 1 commit into from
Aug 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,15 @@ func hashBang(b []byte) []byte {
return nil
}

var reGenerated = regexp.MustCompile(`(?m)^.{1,2} Code generated .* DO NOT EDIT\.$`)
// go generate: ^// Code generated .* DO NOT EDIT\.$
var goGenerated = regexp.MustCompile(`(?m)^.{1,2} Code generated .* DO NOT EDIT\.$`)
// cargo raze: ^DO NOT EDIT! Replaced on runs of cargo-raze$
var cargoRazeGenerated = regexp.MustCompile(`(?m)^DO NOT EDIT! Replaced on runs of cargo-raze$`)

// isGenerated returns true if it contains a string that implies the file was
// generated.
func isGenerated(b []byte) bool {
return reGenerated.Match(b)
return goGenerated.Match(b) || cargoRazeGenerated.Match(b)
}

func hasLicense(b []byte) bool {
Expand Down
22 changes: 22 additions & 0 deletions testdata/expected/file_generated.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
cargo-raze crate workspace functions

DO NOT EDIT! Replaced on runs of cargo-raze
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _new_http_archive(name, **kwargs):
if not native.existing_rule(name):
http_archive(name=name, **kwargs)

def raze_fetch_remote_crates():

_new_http_archive(
name = "raze__log__0_4_11",
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/log/log-0.4.11.crate",
type = "tar.gz",
sha256 = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b",
strip_prefix = "log-0.4.11",
build_file = Label("//bazel/cargo/remote:log-0.4.11.BUILD"),
)

22 changes: 22 additions & 0 deletions testdata/initial/file_generated.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
cargo-raze crate workspace functions

DO NOT EDIT! Replaced on runs of cargo-raze
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _new_http_archive(name, **kwargs):
if not native.existing_rule(name):
http_archive(name=name, **kwargs)

def raze_fetch_remote_crates():

_new_http_archive(
name = "raze__log__0_4_11",
url = "https://crates-io.s3-us-west-1.amazonaws.com/crates/log/log-0.4.11.crate",
type = "tar.gz",
sha256 = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b",
strip_prefix = "log-0.4.11",
build_file = Label("//bazel/cargo/remote:log-0.4.11.BUILD"),
)