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

Rework include file/path handling so we can install the compiler #265

Merged
merged 1 commit into from
Feb 1, 2017

Conversation

ChrisDodd
Copy link
Contributor

  • 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.

@ChrisDodd
Copy link
Contributor Author

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)?

Copy link
Contributor

@mihaibudiu mihaibudiu left a 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.

char buffer[PATH_MAX];
int len;
struct stat st;
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer))) > 0 ||
Copy link
Contributor

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.

Copy link
Contributor Author

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, '/')) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)

@mihaibudiu
Copy link
Contributor

One other major question is whether we need a versioning scheme for included files.

} else if (strchr(argv[0], '/')) {
getcwd(buffer, sizeof(buffer));
strncat(buffer, argv[0], sizeof(buffer) - strlen(buffer) - 1);
} else if (getenv("_")) {
Copy link
Contributor

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?

Copy link
Contributor Author

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=.
Copy link
Contributor

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)?

Copy link
Contributor Author

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 .

char buffer[PATH_MAX];
int len;
struct stat st;
if ((len = readlink("/proc/self/exe", buffer, sizeof(buffer))) > 0 ||
Copy link
Contributor

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.

Copy link
Contributor Author

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].

@ChrisDodd
Copy link
Contributor Author

One other major question is whether we need a versioning scheme for included files.

That's part of why I was thinking $(pkgdatadir) might be better than $(prefix) -- the former contains the package name which can include a version string, thought we don't currently version p4c

@ChrisDodd ChrisDodd force-pushed the cdodd-stage branch 3 times, most recently from a5b8144 to dde4a26 Compare January 30, 2017 17:03
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants