-
Notifications
You must be signed in to change notification settings - Fork 445
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
Rework include file/path handling so we can install the compiler #265
Conversation
One major question here is whether the include files should be installed directly in $prefix ( /usr/local by default), or in a package specific directory (/usr/local/share/p4c/p4include)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this.
It addresses issue #192.
frontends/common/options.cpp
Outdated
char buffer[PATH_MAX]; | ||
int len; | ||
struct stat st; | ||
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer))) > 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this stuff portable on other operating systems?
Maybe it should be in a Linux-specific library. We haven't been too careful about this kind of system dependences so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its portable to Linux, *BSD, and Solaris, and it won't fail badly on other platforms. The fallback using argv[0] will work on OSX and I believe on Windows (cygwin/msys), though I haven't tried the latter
} else { | ||
buffer[0] = 0; } | ||
|
||
if (char *p = strrchr(buffer, '/')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you are assuming that the include path shares the same prefix with the binary path.
Is this a common assumption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for running tests with a binary in the build directory -- iff there's a p4include directory in the same directory as the executable, it overrides the installed config directory.
frontends/common/options.cpp
Outdated
@@ -145,8 +180,8 @@ FILE* CompilerOptions::preprocess() { | |||
#else | |||
std::string cmd("cpp"); | |||
#endif | |||
cmd += cstring(" -undef -nostdinc -I") + | |||
p4includePath + " " + preprocessor_options + " " + file; | |||
cmd += cstring(" -undef -nostdinc -I") + (isv1() ? p4_14includePath : p4includePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the p4includePath be appended at the end?
This way we cannot override it with -I.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it unchanged from before, but you're correct, the standard directory should be last in the path (that's the way C compilers do it; gcc has a special -idirafter option to add directories after the standard set)
One other major question is whether we need a versioning scheme for included files. |
frontends/common/options.cpp
Outdated
} else if (strchr(argv[0], '/')) { | ||
getcwd(buffer, sizeof(buffer)); | ||
strncat(buffer, argv[0], sizeof(buffer) - strlen(buffer) - 1); | ||
} else if (getenv("_")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know what getenv("_") is.
Maybe you can add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some shells (bash, ksh, and zsh) set the _
environment variable to the full path of the binary they're about to execute.
Makefile.am
Outdated
#### For testing, install headers in the build directory | ||
|
||
check-install-headers: | ||
@$(MAKE) install-data prefix=. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be @$(MAKE) install-data prefix=$(builddir)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, though I'm not sure under what circumstances $(builddir) could be anything other than .
frontends/common/options.cpp
Outdated
char buffer[PATH_MAX]; | ||
int len; | ||
struct stat st; | ||
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer))) > 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly this code is finding the directory from where the program was invoked. Why not use dirname(argv[0])? It is much more portable than using /proc. This implementation will not work on MacOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dirname(argv[0]) is the fallback and only works if the program was invoked with an absolute path. We use cwd+dirname(argv[0]) for a relative path. We could add searching through the $PATH envvar for cases where there is no path in argv[0].
That's part of why I was thinking |
a5b8144
to
dde4a26
Compare
- look for p4include in the same dir as the executable to override the install p4include path. - install includes in the build directory so tests run.
23bbed7
to
ae0560f
Compare
install p4include path.