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 a github workflow plus some cleanups #3

Merged
merged 10 commits into from
Jan 25, 2022
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
43 changes: 43 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Continuous integration
on: [push]
env:
# Bump this number to invalidate the GH actions cache
cache-version: 0

jobs:
test-nixpkgs:
name: Build & Test - Nixpkgs
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Mount Bazel cache
uses: actions/cache@v2
with:
path: ~/repo-cache
key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}
- uses: cachix/install-nix-action@v12
with:
nix_path: nixpkgs=./nixpkgs.nix
- name: Configure
env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
run: |
cat >.bazelrc.local <<EOF
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://cloud.buildbuddy.io
build --remote_cache=grpcs://cloud.buildbuddy.io
build --remote_header=x-buildbuddy-api-key="$BUILDBUDDY_API_KEY"
build --repository_cache=~/repo-cache/
EOF
ln -s ../.bazelrc.local example/.bazelrc.local
- name: Build & run gazelle
run: cd example; nix-shell --pure --run 'bazel run //:gazelle'
- name: Build & test generated rules
run: cd example; nix-shell --pure --run 'bazel test //...'
- name: Test for buildifier suggestions
run: nix-shell --pure --run 'bazel run //:buildifier-diff'
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports_files(["defs.bzl"])

buildifier(
name = "buildifier-diff",
diff_command = "diff -u",
mode = "diff",
)

Expand Down
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,36 +215,6 @@ haskell_module(
)
```

## What's next

- [X] Have `haskell_module` rules depend on each other.
- [X] Investigate how to index external repositories, which would be needed
to recognize the provenance of modules coming from external dependencies.
- [X] Have Haskell rules depend on `haskell_module` rules
- [X] Copy `extra_srcs` from the originating rule
- [X] Copy `tools` from the originating rule
- [X] Copy `plugins` from the originating rule
- [X] Skip CPP directives when scanning for imports
- [X] Have a story for preprocessed modules like those needing tasty-discover
- [X] Update `haskell_module` rules when imports change
- [X] Solve interferences with `gazelle_cabal` (removes keep comments on srcs, libsodium label is not understood, deps attribute is reset)
- [X] Lift restriction to name only `haskell_module` rules with dots.
- [X] Lift restriction to name custom `haskell_module` rules as `<package>.<module>`
- [X] Propagate compiler flags and other attributes of libraries, tests, and binaries, to `haskell_module` rules listed in the dependencies.
- [X] Use the `modules` attribute of `haskell_library` instead of `deps`
- [X] Address feedback from code review session.
- [X] Implement gazelle directive to erase library boundaries
- [X] Implement gazelle\_haskell\_modules:keep
- [ ] Check if linker options need special treatment
- [ ] Copy `data` from the originating rule (?)
- [X] Document how `gazelle_haskell_modules` works
- [X] Support the fix command to remove outdated `haskell_module` rules
- [X] See whether we can run `gazelle_haskell_modules` and `gazelle_cabal` in one pass
- [ ] Implement tests
- [ ] Setup CI
- [X] Have himportscan support lhs files
- [ ] Move the update-repos feature of gazelle\_cabal to gazelle\_haskell\_modules
Copy link
Member

Choose a reason for hiding this comment

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

Are the open ones done already, or if not have corresponding GH issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm keeping track of the ones that are still relevant, and I hope to resolve them this week.


## Sponsors

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Expand Down
40 changes: 0 additions & 40 deletions example/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ rules_haskell_dependencies()
load(
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_local_repository",
"nixpkgs_package",
"nixpkgs_python_configure",
)

Expand Down Expand Up @@ -122,42 +121,3 @@ http_archive(
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

####################
# zlib
####################

#nixpkgs_package(
# name = "nixpkgs_zlib",
# attribute_path = "zlib",
# repository = "@nixpkgs",
#)
#
#nixpkgs_package(
# name = "zlib.dev",
# build_file_content = """
#load("@rules_cc//cc:defs.bzl", "cc_library")
#
#filegroup(
# name = "include",
# srcs = glob(["include/*.h"]),
# visibility = ["//visibility:public"],
#)
#
#cc_library(
# name = "zlib",
# srcs = ["@nixpkgs_zlib//:lib"],
# hdrs = [":include"],
# strip_include_prefix = "include",
# visibility = ["//visibility:public"],
# # This rule only bundles headers and a library and doesn't compile or link by itself.
# # We set linkstatic = 1 to quiet to quiet the following warning:
# #
# # in linkstatic attribute of cc_library rule @zlib.dev//:zlib:
# # setting 'linkstatic=1' is recommended if there are no object files.
# #
# linkstatic = 1,
#)
#""",
# repository = "@nixpkgs",
#)
12 changes: 11 additions & 1 deletion example/package-a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_haskell//haskell:defs.bzl", "haskell_binary", "haskell_toolchain_library")
load("@rules_haskell//haskell:defs.bzl", "haskell_binary")

# a-haskell-binary and another-haskell-binary use the same files
#
Expand Down Expand Up @@ -64,3 +64,13 @@ haskell_module(
name = "non-enclosed-module",
src = "app/Main.hs",
)

sh_test(
name = "test-a-haskell-binary",
srcs = [":a-haskell-binary"],
)

sh_test(
name = "test-another-haskell-binary",
srcs = [":another-haskell-binary"],
)
5 changes: 1 addition & 4 deletions gazelle_haskell_modules/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "gazelle_haskell_modules",
Expand All @@ -14,12 +14,9 @@ go_library(
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
"@bazel_gazelle//language:go_default_library",
"@bazel_gazelle//language/go:go_default_library",
"@bazel_gazelle//language/proto:go_default_library",
"@bazel_gazelle//repo:go_default_library",
"@bazel_gazelle//resolve:go_default_library",
"@bazel_gazelle//rule:go_default_library",
"@bazel_gazelle//walk:go_default_library",
"@com_github_bazelbuild_buildtools//build:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
Expand Down
6 changes: 0 additions & 6 deletions gazelle_haskell_modules/dependency_resolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ package gazelle_haskell_modules
import (
"fmt"

//"github.com/bazelbuild/buildtools/build"
//"github.com/bazelbuild/bazel-gazelle/config"
"github.com/bazelbuild/bazel-gazelle/label"
//"github.com/bazelbuild/bazel-gazelle/language"
//golang "github.com/bazelbuild/bazel-gazelle/language/go"
//"github.com/bazelbuild/bazel-gazelle/language/proto"
"github.com/bazelbuild/bazel-gazelle/resolve"
"github.com/bazelbuild/bazel-gazelle/rule"
//"github.com/bazelbuild/bazel-gazelle/walk"

"log"
"path/filepath"
Expand Down
32 changes: 8 additions & 24 deletions gazelle_haskell_modules/rule_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func nonHaskellModuleRulesToRuleInfos(
if !isNonHaskellModule(r.Kind()) || !shouldModularize(r) {
continue
}
srcs, err := srcsFromRuleExceptKeep(pkgRoot, r.Attr("srcs"))
srcs, err := srcsFromRule(pkgRoot, r.Attr("srcs"))
handleRuleError(err, r, "srcs")

modules, err := depsFromRule(r.Attr("modules"), repo, pkg)
Expand Down Expand Up @@ -196,7 +196,7 @@ func addNonHaskellModuleRules(
}
}

srcs, err := srcsFromRuleExceptKeep(pkgRoot, r.Attr("srcs"))
srcs, err := srcsFromRule(pkgRoot, r.Attr("srcs"))
handleRuleError(err, r, "srcs")
modules, err := depsFromRule(r.Attr("modules"), repo, pkg)
handleRuleError(err, r, "modules")
Expand Down Expand Up @@ -253,17 +253,9 @@ func concatRuleInfos(xs [][]*RuleInfo) []*RuleInfo {
return ys
}

func NotShouldKeep(expr build.Expr) bool {
return !rule.ShouldKeep(expr)
}

func ConstTrue(expr build.Expr) bool {
return true
}

// Collects the source files referenced in the given expression
func srcsFromRuleExceptKeep(pkgRoot string, expr build.Expr) ([]string, error) {
srcs, err := getSources(expr, NotShouldKeep)
func srcsFromRule(pkgRoot string, expr build.Expr) ([]string, error) {
srcs, err := getSources(expr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -358,8 +350,8 @@ func ParseLabel(v string) (label.Label, error) {
return label.Parse(v)
}

func getSources(expr build.Expr, p func(build.Expr) bool) (map[string]bool, error) {
xs, err := getStringListP(expr, p)
func getSources(expr build.Expr) (map[string]bool, error) {
xs, err := getStringList(expr)
if err != nil {
return nil, err
}
Expand All @@ -374,9 +366,7 @@ func getSources(expr build.Expr, p func(build.Expr) bool) (map[string]bool, erro
// but yields an empty list if the attribute isn't set, and
// gives an error if the attribute is set to something that
// isn't a list.
//
// Yields only the values satisfying the given predicate.
func getStringListP(expr build.Expr, p func(build.Expr) bool) ([]string, error) {
func getStringList(expr build.Expr) ([]string, error) {
switch expr.(type) {
case nil:
return []string{}, nil
Expand All @@ -387,9 +377,7 @@ func getStringListP(expr build.Expr, p func(build.Expr) bool) ([]string, error)
switch e.(type) {
case *build.StringExpr:
estr := e.(*build.StringExpr)
if p(estr) {
xs = append(xs, estr.Value)
}
xs = append(xs, estr.Value)
default:
return nil, fmt.Errorf("Unhandled expression type %T (expected a string)", e)
}
Expand All @@ -400,10 +388,6 @@ func getStringListP(expr build.Expr, p func(build.Expr) bool) ([]string, error)
}
}

func getStringList(expr build.Expr) ([]string, error) {
return getStringListP(expr, ConstTrue)
}

func isNonHaskellModule(kind string) bool {
return kind == "haskell_library" ||
kind == "haskell_binary" ||
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mkShell {
bazel_4
binutils
cacert
diffutils # for buildifier-diff
git
nix
openjdk11
Expand Down