extconf_compile_commands_json 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c4119e56b170eeb8c7754f47f7735f14f9e2110aec9a55d2627d2be4b96e24d
4
- data.tar.gz: 8db262a1e1ceba1e9246fa88914c2cd44b5e36a1b0b80e4ef83be7d159d51f72
3
+ metadata.gz: 88de348e6640c23af1e07d9f0020a0ec522178b29582ceb9fea6d33688fd2724
4
+ data.tar.gz: 2d13985b767102f8106fa060417292c68b254912b761b67c8559ded462cbd837
5
5
  SHA512:
6
- metadata.gz: af7263343f4e56f58c8c49cd40b74bec3865b3bbea54fe32c730f69fd90decb0fbfd6cea29fb373bd319c34099a95c1df22cea09bd1e75132860636adc579f0c
7
- data.tar.gz: f547795042f887afd413b52e39310bcd0b3dfe106729c90bb3583ca6b8d8771eb4c8a31b81aac8beaa9592d026e5801d8ad755c05d130a78f24878c01446102a
6
+ metadata.gz: c146378f481ad9479e117f95e8a6e3a0f2a8780740c10f2146ef65cbfef3ad2ff9489c58e5541df2dd51eea08a941492322341917f8c09ebaa60a59828684a8e
7
+ data.tar.gz: 9e6375c68826300429d7849abc34c993577a7de0e2b9b1b7055ec3d1a0c1efbb5fe9b80b55d7854907c66fb7ba5d6e096ba603c95085a7035423625dfc4097c0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Requiring this file will patch MkMf to auto-magically generate compile_commands.json.
4
+ # Handy to add to a RUBYOPT env var or such, so you can work on a project not using
5
+ # this gem but benefit from it yourself, without having to modify the existing build
6
+ # scripts.
7
+
8
+ require "mkmf"
9
+ require "extconf_compile_commands_json"
10
+
11
+ module ExtconfCompileCommandsJson
12
+ module AutoloadPatch
13
+ def create_makefile(*args)
14
+ super
15
+ ExtconfCompileCommandsJson.generate!
16
+ ExtconfCompileCommandsJson.symlink!
17
+ end
18
+ end
19
+ end
20
+
21
+ MakeMakefile.prepend ExtconfCompileCommandsJson::AutoloadPatch
@@ -3,9 +3,10 @@
3
3
  require "mkmf"
4
4
  require "shellwords"
5
5
  require "json"
6
+ require "fileutils"
6
7
 
7
8
  module ExtconfCompileCommandsJson
8
- def self.generate_compile_commands_json
9
+ def self.generate!
9
10
  mkmf_cflags = []
10
11
  # Start by expanding what's in our magic variables
11
12
  [$INCFLAGS, $CPPFLAGS, $CFLAGS, $COUTFLAGS].each do |v|
@@ -41,4 +42,17 @@ module ExtconfCompileCommandsJson
41
42
  end
42
43
  File.write("compile_commands.json", compile_commands.to_json)
43
44
  end
45
+
46
+ # generate will put the compile_commands.json in the same folder as the
47
+ # compiled output (and Makefile); symlink will create a symlink in the
48
+ # same folder as the extconf.rb, so that clangd can find it.
49
+ def self.symlink!
50
+ # This is the same check mkmf does for deciding whether to spew errors onto your
51
+ # terminal, so I figure it'll do for spewing symlinks into your directory too.
52
+ return unless !$extmk && (/\A(extconf|makefile).rb\z/ =~ File.basename($0))
53
+ extconf_dir = File.dirname $0
54
+ compile_commands_file = File.realpath("./compile_commands.json")
55
+ return unless File.exist? compile_commands_file
56
+ FileUtils.ln_sf compile_commands_file, File.join(extconf_dir, "compile_commands.json")
57
+ end
44
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extconf_compile_commands_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KJ Tsanaktsidis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-03 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -34,6 +34,7 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - lib/extconf_compile_commands_json.rb
37
+ - lib/extconf_compile_commands_json/autoload.rb
37
38
  homepage: https://github.com/KJTsanaktsidis/extconf_compile_commands_json
38
39
  licenses:
39
40
  - MIT