Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Detect and keep CGO dependencies from subfolders. #52

Merged
merged 2 commits into from
Oct 25, 2016

Conversation

karalabe
Copy link
Contributor

@karalabe karalabe commented Oct 24, 2016

This PR fixes an issue that's haunting all the dependency managers out there (e.g. tools/godep#422), namely that they only take into consideration Go dependencies, and not CGO ones. This results in build failures for all projects where C files are in subfolders (i.e. most of them), as the dependency manager deletes all those folders thinking they are unused.

This fixes the issue by doing a second round of import scanning, where instead of looking for Go import statements, the code looks for CGO preambles and extracts any #include "path"-s where the path points to an existing folder. This will result in any folders references by CGO code to be kept, instead of trashed.

@imikushin
Copy link
Contributor

Thanks for this, @karalabe! We've had issues with native code imports, so this contribution is very welcome.

I'll have just a couple minor comments.

// Extract any includes from the preamble
for _, line := range strings.Split(cg.Text(), "\n") {
if line = strings.TrimSpace(line); strings.HasPrefix(line, "#include \"") {
if path := filepath.Dir(line[10 : len(line)-1]); path != "." {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path var collides with an imported package name. Wanna rename to includePath?

if line = strings.TrimSpace(line); strings.HasPrefix(line, "#include \"") {
if path := filepath.Dir(line[10 : len(line)-1]); path != "." {
if _, err := os.Stat(filepath.Join(pkgPath, path)); !os.IsNotExist(err) {
sch <- filepath.Join(pkg, path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanna send filepath.Clean(filepath.Join(pkg, path)) instead?

@karalabe
Copy link
Contributor Author

Fixed :) PTAL

Copy link
Contributor

@imikushin imikushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@imikushin imikushin merged commit 2634e3b into rancher:master Oct 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants