1
1
mirror of https://github.com/github/semantic.git synced 2024-11-26 09:07:39 +03:00

first attempt at doing bazel stuff - this is problematic

This commit is contained in:
Patrick Thomson 2020-05-19 12:16:16 -04:00
parent 10300b8c35
commit 7bbc93cc8a
14 changed files with 2267 additions and 4 deletions

15
.bazelrc Normal file
View File

@ -0,0 +1,15 @@
build:ci --loading_phase_threads=1
build:ci --jobs=2
build:ci --verbose_failures
common:ci --color=no
test:ci --test_output=errors
# test environment does not propagate locales by default
# some tests reads files written in UTF8, we need to propagate the correct
# environment variables, such as LOCALE_ARCHIVE
# We also need to setup an utf8 locale
test --test_env=LANG=en_US.utf8 --test_env=LOCALE_ARCHIVE
try-import .bazelrc.local

1
.gitignore vendored
View File

@ -18,6 +18,7 @@ dist-repl
tmp/ tmp/
/bin/ /bin/
/bazel-*
/src/Semantic/Version.hs.bak /src/Semantic/Version.hs.bak
/semanticd/test/current /semanticd/test/current

39
BUILD.bazel Normal file
View File

@ -0,0 +1,39 @@
# Set all targets visibility in this package to "public".
package(default_visibility = ["//visibility:public"])
# Load rules_haskell rules.
load(
"@rules_haskell//haskell:defs.bzl",
"haskell_toolchain_library",
"haskell_library",
"haskell_binary",
)
# haskell_toolchain_library can access builtin GHC packages
# and assign them a bazel target name, so that they
# can be referenced as dependencies.
haskell_toolchain_library(name = "base")
# You can add your own libraries with haskell_library.
# haskell_library(
# name = "MY_LIBRARY_NAME",
# src_strip_prefix = "src",
# srcs = glob(['src/**/*.hs']),
# deps = [
# "base_pkg"
# ],
# )
haskell_library(
name = "semantic-source"
src_strip_prefix = "semantic-source/src",
srcs = glob(['semantic-source/**/*.hs'])
)
# An example binary using the Prelude module from the
# GHC base package, to print the hello world.
haskell_binary(
name = "example",
srcs = [":Example.hs"],
deps = [":base"],
)

58
WORKSPACE Normal file
View File

@ -0,0 +1,58 @@
# Give your project a name. :)
workspace(name = "semantic")
# Load the repository rule to download an http archive.
load(
"@bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive"
)
# Download rules_haskell and make it accessible as "@rules_haskell".
http_archive(
name = "rules_haskell",
strip_prefix = "rules_haskell-0.12",
urls = ["https://github.com/tweag/rules_haskell/archive/v0.12.tar.gz"],
sha256 = "56a8e6337df8802f1e0e7d2b3d12d12d5d96c929c8daecccc5738a0f41d9c1e4",
)
load(
"@rules_haskell//haskell:repositories.bzl",
"rules_haskell_dependencies",
)
# Setup all Bazel dependencies required by rules_haskell.
rules_haskell_dependencies()
load(
"@rules_haskell//haskell:toolchain.bzl",
"rules_haskell_toolchains",
)
# Download a GHC binary distribution from haskell.org and register it as a toolchain.
rules_haskell_toolchains(version = "8.8.1")
load(
"@rules_haskell//haskell:cabal.bzl",
"stack_snapshot",
"haskell_cabal_library",
"haskell_cabal_binary",
)
stack_snapshot(
name = "stackage",
local_snapshot = "//:stack-snapshot.yaml",
packages = [
"aeson",
"bytestring",
"deepseq",
"containers",
"filepath",
"generic-monoid",
"hashable",
"pathtype",
"semilattices",
"text",
"transformers",
],
)

View File

@ -1,7 +1,7 @@
-- ATTENTION: care must be taken to keep this file in sync with cabal.project.ci and script/ghci-flags. If you add a package here, add it there (and add a package stanza with ghc-options to enable errors in CI at the bottom of that file). -- ATTENTION: care must be taken to keep this file in sync with cabal.project.ci and script/ghci-flags. If you add a package here, add it there (and add a package stanza with ghc-options to enable errors in CI at the bottom of that file).
-- Local packages -- Local packages
packages: . packages: semantic
semantic-analysis semantic-analysis
semantic-ast semantic-ast
semantic-codeql semantic-codeql

17
generate_hie_yaml.rb Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env ruby
require 'yaml'
components = []
Dir.glob("./semantic*").each do |dir|
components << {'path' => dir + '/src', 'component' => "lib:" + dir[2..]}
end
Dir.glob("./semantic*/test").each do |dir|
components << {'path' => dir, 'component' => "test:" + dir[2..-6]}
end
result = {'cradle' => { 'cabal' => components }}
puts YAML.dump(result)

View File

@ -1,4 +1,37 @@
---
cradle: cradle:
bios: cabal:
program: script/ghci-flags - path: "./semantic-core/src"
dependency-program: script/ghci-flags-dependencies component: lib:semantic-core
- path: "./semantic-ast/src"
component: lib:semantic-ast
- path: "./semantic-go/src"
component: lib:semantic-go
- path: "./semantic-java/src"
component: lib:semantic-java
- path: "./semantic-codeql/src"
component: lib:semantic-codeql
- path: "./semantic-analysis/src"
component: lib:semantic-analysis
- path: "./semantic-scope-graph/src"
component: lib:semantic-scope-graph
- path: "./semantic-json/src"
component: lib:semantic-json
- path: "./semantic-typescript/src"
component: lib:semantic-typescript
- path: "./semantic-source/src"
component: lib:semantic-source
- path: "./semantic-tags/src"
component: lib:semantic-tags
- path: "./semantic/src"
component: lib:semantic
- path: "./semantic-parse/src"
component: lib:semantic-parse
- path: "./semantic-ruby/src"
component: lib:semantic-ruby
- path: "./semantic-python/src"
component: lib:semantic-python
- path: "./semantic-tsx/src"
component: lib:semantic-tsx
- path: "./semantic-php/src"
component: lib:semantic-php

View File

@ -0,0 +1,46 @@
# Set all targets visibility in this package to "public".
package(default_visibility = ["//visibility:public"])
# Load rules_haskell rules.
load(
"@rules_haskell//haskell:defs.bzl",
"haskell_toolchain_library",
"haskell_library",
"haskell_binary",
)
load("@rules_haskell//haskell:cabal.bzl", "haskell_cabal_binary", "haskell_cabal_library")
# haskell_toolchain_library can access builtin GHC packages
# and assign them a bazel target name, so that they
# can be referenced as dependencies.
haskell_toolchain_library(name = "base")
# You can add your own libraries with haskell_library.
haskell_library(
name = "lib",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs']),
compiler_flags = ["-XOverloadedStrings"],
deps = [
":base",
"@stackage//:aeson",
"@stackage//:bytestring",
"@stackage//:containers",
"@stackage//:deepseq",
"@stackage//:filepath",
"@stackage//:generic-monoid",
"@stackage//:hashable",
"@stackage//:semilattices",
"@stackage//:text",
"@stackage//:pathtype",
],
)
# An example binary using the Prelude module from the
# GHC base package, to print the hello world.
# haskell_binary(
# name = "example",
# srcs = [":Example.hs"],
# deps = [":base"],
# )

View File

@ -0,0 +1,33 @@
-- | Primary interface for looking up the programming language of a file or
-- interacting with languages known to linguist
-- (https://github.com/github/linguist).
module Data.Languages
( languagesForPath
, languages
, languagesByExtension
, languagesByFileName
, LanguageKey
, Language(..)
) where
import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text
import Gen_Languages
import System.FilePath.Posix
-- | Find the set of possible languages for a given file path.
--
-- Multiple results will be returned for ambiguous files; for example, @.md@ files can be Markdown or GCC machine descriptions, and @.php@ files can be PHP or Hack source files.
languagesForPath :: FilePath -> [Language]
languagesForPath path = languageForFileName <|> languageForExtension
where
languageForFileName = languageFor (takeFileName path) languagesByFileName
languageForExtension = languageFor (takeExtension path) languagesByExtension
languageFor :: String -> Map.Map Text [LanguageKey] -> [Language]
languageFor k
= foldMap (maybeToList . flip Map.lookup languages)
. fromMaybe []
. Map.lookup (Text.pack k)

View File

@ -42,6 +42,7 @@ common haskell
library library
import: haskell import: haskell
exposed-modules: exposed-modules:
Data.Languages
Source.Language Source.Language
Source.Loc Source.Loc
Source.Range Source.Range

View File

@ -0,0 +1,33 @@
-- | Primary interface for looking up the programming language of a file or
-- interacting with languages known to linguist
-- (https://github.com/github/linguist).
module Data.Languages
( languagesForPath
, languages
, languagesByExtension
, languagesByFileName
, LanguageKey
, Language(..)
) where
import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text
import Gen_Languages
import System.FilePath.Posix
-- | Find the set of possible languages for a given file path.
--
-- Multiple results will be returned for ambiguous files; for example, @.md@ files can be Markdown or GCC machine descriptions, and @.php@ files can be PHP or Hack source files.
languagesForPath :: FilePath -> [Language]
languagesForPath path = languageForFileName <|> languageForExtension
where
languageForFileName = languageFor (takeFileName path) languagesByFileName
languageForExtension = languageFor (takeExtension path) languagesByExtension
languageFor :: String -> Map.Map Text [LanguageKey] -> [Language]
languageFor k
= foldMap (maybeToList . flip Map.lookup languages)
. fromMaybe []
. Map.lookup (Text.pack k)

File diff suppressed because it is too large Load Diff

0
semantic/BUILD.bazel Normal file
View File

3
stack-snapshot.yaml Normal file
View File

@ -0,0 +1,3 @@
resolver: lts-15.13
packages:
- semilattices-0.0.0.4