rubydex 0.0.1 → 0.1.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/exe/rdx ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
5
+ require "optparse"
6
+
7
+ OptionParser.new do |parser|
8
+ parser.banner = "Usage: [path1, path2]"
9
+
10
+ parser.on("--version", "Print the gem's version") do
11
+ require "rubydex/version"
12
+ puts "v#{Rubydex::VERSION}"
13
+ exit
14
+ end
15
+
16
+ parser.on("-h", "--help", "Prints this help") do
17
+ puts parser
18
+ exit
19
+ end
20
+ end.parse!
21
+
22
+ require "rubydex"
23
+
24
+ workspace_path = ARGV.first
25
+
26
+ # If a workspace path is passed, we need to ensure that Bundler is setup in that context so that we find the
27
+ # dependencies for that project
28
+ if workspace_path
29
+ gemfile_path = File.join(workspace_path, "Gemfile")
30
+
31
+ if File.exist?(gemfile_path)
32
+ ENV["BUNDLE_GEMFILE"] = gemfile_path
33
+
34
+ begin
35
+ Bundler.setup
36
+ rescue Bundler::BundlerError => e
37
+ $stderr.puts(<<~MESSAGE)
38
+ Bundle setup failed for #{gemfile_path}. Indexing of dependencies may be partial
39
+ Error:
40
+ #{e.message}
41
+ MESSAGE
42
+ end
43
+ end
44
+ end
45
+
46
+ graph = Rubydex::Graph.new(workspace_path: workspace_path)
47
+ graph.index_workspace
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "pathname"
5
+
6
+ release = ENV["RELEASE"]
7
+ gem_dir = Pathname.new("../..").expand_path(__dir__)
8
+ root_dir = gem_dir.join("rust")
9
+ target_dir = root_dir.join("target")
10
+ target_dir = target_dir.join("x86_64-pc-windows-gnu") if Gem.win_platform?
11
+ target_dir = target_dir.join(release ? "release" : "debug")
12
+
13
+ bindings_path = root_dir.join("rubydex-sys").join("rustbindings.h")
14
+
15
+ cargo_args = ["--manifest-path #{root_dir.join("Cargo.toml")}"]
16
+ cargo_args << "--release" if release
17
+
18
+ if Gem.win_platform?
19
+ cargo_args << "--target x86_64-pc-windows-gnu"
20
+ ENV["RUSTFLAGS"] = "-C target-feature=+crt-static"
21
+ end
22
+
23
+ append_cflags("-Werror=unused-but-set-variable")
24
+ append_cflags("-Werror=implicit-function-declaration")
25
+
26
+ if Gem.win_platform?
27
+ $LDFLAGS << " #{target_dir.join("librubydex_sys.a")}"
28
+
29
+ # On Windows, statically link system libraries to avoid having to distribute and load DLLs
30
+ #
31
+ # These libraries are the ones informed by `cargo rustc -- --print native-static-libs`, which displays the
32
+ # libraries necessary for statically linking the Rust code on the current platform
33
+ ["kernel32", "ntdll", "userenv", "ws2_32", "dbghelp", "msvcrt"].each do |lib|
34
+ $LDFLAGS << " -l#{lib}"
35
+ end
36
+ else
37
+ append_ldflags("-Wl,-rpath,#{target_dir}")
38
+ # We cannot use append_ldflags here because the Rust code is only compiled later. If it's not compiled yet, this will
39
+ # fail and the flag will not be added
40
+ $LDFLAGS << " -L#{target_dir} -lrubydex_sys"
41
+ end
42
+
43
+ create_makefile("rubydex/rubydex")
44
+
45
+ cargo_command = if ENV["SANITIZER"]
46
+ ENV["RUSTFLAGS"] = "-Zsanitizer=#{ENV["SANITIZER"]}"
47
+ "cargo +nightly build -Zbuild-std #{cargo_args.join(" ")}".strip
48
+ else
49
+ "cargo build #{cargo_args.join(" ")}".strip
50
+ end
51
+
52
+ rust_srcs = Dir.glob("#{root_dir}/**/*.rs")
53
+
54
+ makefile = File.read("Makefile")
55
+ new_makefile = makefile.gsub("$(OBJS): $(HDRS) $(ruby_headers)", <<~MAKEFILE.chomp)
56
+ .PHONY: compile_rust
57
+ RUST_SRCS = #{File.expand_path("Cargo.toml", root_dir)} #{File.expand_path("Cargo.lock", root_dir)} #{rust_srcs.join(" ")}
58
+
59
+ .rust_built: $(RUST_SRCS)
60
+ \t#{cargo_command} || (echo "Compiling Rust failed" && exit 1)
61
+ \t$(COPY) #{bindings_path} #{__dir__}
62
+ \ttouch $@
63
+
64
+ compile_rust: .rust_built
65
+
66
+ $(OBJS): $(HDRS) $(ruby_headers) .rust_built
67
+ MAKEFILE
68
+
69
+ new_makefile.gsub!("$(Q) $(POSTLINK)", <<~MAKEFILE.chomp)
70
+ $(Q) $(POSTLINK)
71
+ \t$(Q)$(RM) .rust_built
72
+ MAKEFILE
73
+
74
+ # Bundle all dependency licenses when building a release version of the gem
75
+ if release
76
+ unless system("cargo about --version > /dev/null 2>&1")
77
+ abort <<~MESSAGE
78
+ ERROR: cargo-about is not installed and required to build the release version of the gem.
79
+ Please install it by running:
80
+ cargo install cargo-about
81
+ MESSAGE
82
+ end
83
+
84
+ licenses_file = root_dir.join("THIRD_PARTY_LICENSES.html")
85
+ about_config = root_dir.join("about.toml")
86
+ about_template = root_dir.join("about.hbs")
87
+
88
+ new_makefile.gsub!(".rust_built: $(RUST_SRCS)", <<~MAKEFILE.chomp)
89
+ #{licenses_file}: #{about_config} #{about_template}
90
+ \t$(Q)$(RM) #{licenses_file}
91
+ \tcargo about generate #{about_template} --manifest-path #{root_dir.join("Cargo.toml")} --workspace > #{licenses_file}
92
+ \t$(COPY) #{licenses_file} #{gem_dir}
93
+
94
+ .rust_built: $(RUST_SRCS) #{licenses_file}
95
+ MAKEFILE
96
+ end
97
+
98
+ File.write("Makefile", new_makefile)
99
+
100
+ begin
101
+ require "extconf_compile_commands_json"
102
+
103
+ ExtconfCompileCommandsJson.generate!
104
+ ExtconfCompileCommandsJson.symlink!
105
+ rescue LoadError # rubocop:disable Lint/SuppressedException
106
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Comment
5
+ #: String
6
+ attr_reader :string
7
+
8
+ #: Location
9
+ attr_reader :location
10
+
11
+ #: (?string: String, ?location: Location) -> void
12
+ def initialize(string:, location:)
13
+ @string = string
14
+ @location = location
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Diagnostic
5
+ #: Symbol
6
+ attr_reader :rule
7
+
8
+ #: String
9
+ attr_reader :message
10
+
11
+ #: Location
12
+ attr_reader :location
13
+
14
+ #: (rule: Symbol, message: String, location: Location) -> void
15
+ def initialize(rule:, message:, location:)
16
+ @rule = rule
17
+ @message = message
18
+ @location = location
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ # The global graph representing all declarations and their relationships for the workspace
5
+ #
6
+ # Note: this class is partially defined in C to integrate with the Rust backend
7
+ class Graph
8
+ #: (?workspace_path: String) -> void
9
+ def initialize(workspace_path: Dir.pwd)
10
+ @workspace_path = workspace_path
11
+ end
12
+
13
+ # Index all files and dependencies of the workspace that exists in `@workspace_path`
14
+ #: -> String?
15
+ def index_workspace
16
+ paths = Dir.glob("#{@workspace_path}/**/*.rb")
17
+ paths.concat(
18
+ workspace_dependency_paths.flat_map do |path|
19
+ Dir.glob("#{path}/**/*.rb")
20
+ end,
21
+ )
22
+ index_all(paths)
23
+ end
24
+
25
+ private
26
+
27
+ # Gathers the paths we have to index for all workspace dependencies
28
+ def workspace_dependency_paths
29
+ specs = Bundler.locked_gems&.specs
30
+ return [] unless specs
31
+
32
+ paths = specs.filter_map do |lazy_spec|
33
+ spec = Gem::Specification.find_by_name(lazy_spec.name)
34
+ spec.require_paths.map { |path| File.join(spec.full_gem_path, path) }
35
+ rescue Gem::MissingSpecError
36
+ nil
37
+ end
38
+
39
+ paths.flatten!
40
+ paths.uniq!
41
+ paths
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ class Location
5
+ include Comparable
6
+
7
+ #: String
8
+ attr_reader :uri
9
+
10
+ #: Integer
11
+ attr_reader :start_line, :end_line, :start_column, :end_column
12
+
13
+ #: (?uri: String, ?start_line: Integer, ?end_line: Integer, ?start_column: Integer, ?end_column: Integer) -> void
14
+ def initialize(uri:, start_line:, end_line:, start_column:, end_column:)
15
+ @uri = uri
16
+ @start_line = start_line
17
+ @end_line = end_line
18
+ @start_column = start_column
19
+ @end_column = end_column
20
+ end
21
+
22
+ #: () -> String
23
+ def path
24
+ uri = URI(@uri)
25
+ raise Rubydex::Error, "URI is not a file:// URI: #{@uri}" unless uri.scheme == "file"
26
+
27
+ path = uri.path
28
+ # TODO: This has to go away once we have a proper URI abstraction
29
+ path.delete_prefix!("/") if Gem.win_platform?
30
+ path
31
+ end
32
+
33
+ #: (other: BasicObject) -> Integer
34
+ def <=>(other)
35
+ return -1 unless other.is_a?(Location)
36
+
37
+ a = [@uri, @start_line, @start_column, @end_line, @end_column]
38
+ b = [other.uri, other.start_line, other.start_column, other.end_line, other.end_column]
39
+ a <=> b
40
+ end
41
+
42
+ #: -> String
43
+ def to_s
44
+ "#{path}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0.beta1"
5
5
  end
data/lib/rubydex.rb CHANGED
@@ -1,8 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "rubydex/version"
3
+ require "bundler"
4
+ require "uri"
4
5
 
5
6
  module Rubydex
6
7
  class Error < StandardError; end
7
- # Your code goes here...
8
8
  end
9
+
10
+ require "rubydex/version"
11
+
12
+ begin
13
+ # Load the precompiled version of the library
14
+ ruby_version = /(\d+\.\d+)/.match(RUBY_VERSION)
15
+ require "rubydex/#{ruby_version}/rubydex"
16
+ rescue LoadError
17
+ # It's important to leave for users that can not or don't want to use the gem with precompiled binaries.
18
+ require "rubydex/rubydex"
19
+ end
20
+
21
+ require "rubydex/location"
22
+ require "rubydex/comment"
23
+ require "rubydex/diagnostic"
24
+ require "rubydex/graph"
metadata CHANGED
@@ -1,35 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
- - Ufuk Kayserilioglu
7
+ - Shopify
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-01-21 00:00:00.000000000 Z
11
12
  dependencies: []
12
- description: A rolodex for Ruby
13
+ description: A high performance static analysis suite for Ruby, built in Rust with
14
+ Ruby APIs
13
15
  email:
14
- - ufuk@paralaus.com
15
- executables: []
16
- extensions: []
16
+ - ruby@shopify.com
17
+ executables:
18
+ - rdx
19
+ extensions:
20
+ - ext/rubydex/extconf.rb
17
21
  extra_rdoc_files: []
18
22
  files:
19
- - ".rubocop.yml"
20
- - CODE_OF_CONDUCT.md
21
23
  - LICENSE.txt
22
24
  - README.md
23
- - Rakefile
25
+ - THIRD_PARTY_LICENSES.html
26
+ - exe/rdx
27
+ - ext/rubydex/extconf.rb
24
28
  - lib/rubydex.rb
29
+ - lib/rubydex/comment.rb
30
+ - lib/rubydex/diagnostic.rb
31
+ - lib/rubydex/graph.rb
32
+ - lib/rubydex/location.rb
25
33
  - lib/rubydex/version.rb
26
- - sig/rubydex.rbs
27
- homepage: https://github.com/paracycle/rubydex
34
+ homepage: https://github.com/Shopify/rubydex
28
35
  licenses:
29
36
  - MIT
30
37
  metadata:
31
38
  allowed_push_host: https://rubygems.org
32
- homepage_uri: https://github.com/paracycle/rubydex
39
+ homepage_uri: https://github.com/Shopify/rubydex
40
+ source_code_uri: https://github.com/Shopify/rubydex
41
+ changelog_uri: https://github.com/Shopify/rubydex/releases
42
+ post_install_message:
33
43
  rdoc_options: []
34
44
  require_paths:
35
45
  - lib
@@ -37,14 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
47
  requirements:
38
48
  - - ">="
39
49
  - !ruby/object:Gem::Version
40
- version: 3.1.0
50
+ version: 3.2.0
41
51
  required_rubygems_version: !ruby/object:Gem::Requirement
42
52
  requirements:
43
53
  - - ">="
44
54
  - !ruby/object:Gem::Version
45
- version: '0'
55
+ version: 3.3.11
46
56
  requirements: []
47
- rubygems_version: 3.6.7
57
+ rubygems_version: 3.4.19
58
+ signing_key:
48
59
  specification_version: 4
49
- summary: A rolodex for Ruby
60
+ summary: A high performance static analysis suite for Ruby
50
61
  test_files: []
data/.rubocop.yml DELETED
@@ -1,8 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.1
3
-
4
- Style/StringLiterals:
5
- EnforcedStyle: double_quotes
6
-
7
- Style/StringLiteralsInInterpolation:
8
- EnforcedStyle: double_quotes
data/CODE_OF_CONDUCT.md DELETED
@@ -1,132 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, caste, color, religion, or sexual
10
- identity and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the overall
26
- community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or advances of
31
- any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email address,
35
- without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official email address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- [INSERT CONTACT METHOD].
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series of
86
- actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or permanent
93
- ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within the
113
- community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.1, available at
119
- [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
-
121
- Community Impact Guidelines were inspired by
122
- [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
-
124
- For answers to common questions about this code of conduct, see the FAQ at
125
- [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
- [https://www.contributor-covenant.org/translations][translations].
127
-
128
- [homepage]: https://www.contributor-covenant.org
129
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
- [Mozilla CoC]: https://github.com/mozilla/diversity
131
- [FAQ]: https://www.contributor-covenant.org/faq
132
- [translations]: https://www.contributor-covenant.org/translations
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
5
-
6
- Minitest::TestTask.create
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[test rubocop]
data/sig/rubydex.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Rubydex
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end