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

Fix #13: Use bashlex to preprocess substitution commands #34

Merged
merged 7 commits into from
May 21, 2018
Merged

Conversation

nickdiego
Copy link
Owner

The following command should work as expected:

compiledb -i sample.txt -o-

  • Output:
## Processing build commands from <stdin>
## Writing compilation database with 1 entries to <stdout>
[
 {
  "directory": "/home/nick/projects/compiledb/compiledb-generator",
  "file": "./main.c",
  "arguments": [
   "cc",
   "-DPACKAGE_NAME=\"hello\"",
   "-DPACKAGE_TARNAME=\"hello\"",
   "-DPACKAGE_VERSION=\"1.0.0\"",
   "-DPACKAGE_STRING=\"hello\\ 1.0.0\"",
   "-DPACKAGE_BUGREPORT=\"info@hello.org\"",
   "-DPACKAGE_URL=\"http://www.hello.org\"",
   "-DSTDC_HEADERS=1",
   "-DHAVE_SYS_TYPES_H=1",
   "-DHAVE_SYS_STAT_H=1",
   "-DHAVE_STDLIB_H=1",
   "-DHAVE_STRING_H=1",
   "-DHAVE_MEMORY_H=1",
   "-DHAVE_STRINGS_H=1",
   "-DHAVE_INTTYPES_H=1",
   "-DHAVE_STDINT_H=1",
   "-DHAVE_UNISTD_H=1",
   "-DHAVE_DLFCN_H=1",
   "-DLT_OBJDIR=\".libs/\"",
   "-I-/.",
   "-I-/../../src/libhello",
   "-c",
   "./main.c"
  ]
 }
]
## Done.
  • sample.txt
gcc -DPACKAGE_NAME=\"hello\" -DPACKAGE_TARNAME=\"hello\" -DPACKAGE_VERSION=\"1.0.0\" -DPACKAGE_STRING=\"hello\ 1.0.0\" -DPACKAGE_BUGREPORT=\"info@hello.org\" -DPACKAGE_URL=\"http://www.hello.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I../../src/libhello -g -O2 -MT hello_world1-main.o -MD -MP -MF .deps/hello_world1-main.Tpo -c -o hello_world1-main.o `test -f 'main.c' || echo './'`main.c

TODO: There is still an issue with autotools-based builds with the -B, which causes configure script to be executed for every command.

@nickdiego nickdiego added this to the v0.9 milestone May 20, 2018
Nick Diego Yamane added 7 commits May 21, 2018 01:01
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
…tion

Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
…essfully

Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
@nickdiego nickdiego changed the title [WIP] Fix #13: Use bashlex to preprocess substitution commands Fix #13: Use bashlex to preprocess substitution commands May 21, 2018
@nickdiego nickdiego merged commit b04fd13 into master May 21, 2018
@lyonlh
Copy link
Contributor

lyonlh commented May 22, 2018

Hi @nickdiego ,

I used compile-0.9.1 to verify this issue on xfce4-hardware-monitor-plugin. And encountered some errors. Please refer to the attached log.
compiledb.log

@nickdiego
Copy link
Owner Author

nickdiego commented May 22, 2018

I've just setup build environment for xfce-hardware-monitor-plugin and successfully extracted its compilation database, using the following commands:

$ ./configure
$ make -nkw | compiledb

NOTE: I didn't use compiledb make command due to #35
Anyway, I'll investigate that issue, looks like the parser tried to parse (using bashlex) non-valid bash command line from build log entries (most probably some configure script output), what resulted in an non-handled Exception. Just created #38 to track this issue.

Thanks

@lyonlh
Copy link
Contributor

lyonlh commented May 22, 2018

Hi @nickdiego ,

I ran $ make -nkw | compiledb and generated the compilation database same as yours.
But I found an issue about it. There some lines like "-DHARDWARE_MONITOR_GLADEDIR=\"\"/usr/local/share/xfce4-hardware-monitor-plugin/glade/\"\"", which has double \"\" at right side.
In my opinion, the right one is like "-DHARDWARE_MONITOR_GLADEDIR=\"/usr/local/share/xfce4-hardware-monitor-plugin/glade/\"",.

@nickdiego
Copy link
Owner Author

It looks like it's being set explicitly to be "double" quoted, at:

src/Makefile.am
44:                        -DHARDWARE_MONITOR_GLADEDIR=\""$(gladedir)/"\" \

I'm not sure about what should be the correct way to handle this.

@lyonlh
Copy link
Contributor

lyonlh commented May 22, 2018

Sure, but the \" would be consumed by shell. It seems bashlex does not evaluate/interpret it.
In my opinion, the result is not reliable if the compile commands are not interpreted by shell. In other words, the arguments shell passes to compiler are definitely wanted.
This is one important reason I wrote https://github.com/lyonlh/ABCD.

@lyonlh
Copy link
Contributor

lyonlh commented May 22, 2018

@nickdiego , I've opened a new issue #40 to track the \"\" issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants