You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/04/20 07:38:21 UTC

[GitHub] michal-narajowski closed pull request #161: cmake: Use paths relative to project root

michal-narajowski closed pull request #161: cmake: Use paths relative to project root
URL: https://github.com/apache/mynewt-newt/pull/161
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go
index e415521a..1ff538d9 100644
--- a/newt/builder/cmake.go
+++ b/newt/builder/cmake.go
@@ -30,6 +30,7 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/interfaces"
 	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/newt/target"
 	"mynewt.apache.org/newt/newt/toolchain"
@@ -46,6 +47,18 @@ func EscapeName(name string) string {
 	return strings.Replace(name, "/", "_", -1)
 }
 
+func trimProjectPath(path string) string {
+	proj := interfaces.GetProject()
+	path = strings.TrimPrefix(path, proj.Path()+"/")
+	return path
+}
+
+func trimProjectPathSlice(elements []string) {
+	for e := range elements {
+		elements[e] = trimProjectPath(elements[e])
+	}
+}
+
 func extractIncludes(flags *[]string, includes *[]string, other *[]string) {
 	for _, f := range *flags {
 		if strings.HasPrefix(f, "-I") {
@@ -96,6 +109,7 @@ func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs *
 	}
 
 	extractIncludes(&compileFlags, includeDirs, &otherFlags)
+	cj.Filename = trimProjectPath(cj.Filename)
 
 	fmt.Fprintf(w, `set_property(SOURCE %s APPEND_STRING
 														PROPERTY
@@ -127,6 +141,7 @@ func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage) (*Buil
 		}
 
 		CmakeSourceObjectWrite(w, s, &otherIncludes)
+		s.Filename = trimProjectPath(s.Filename)
 		files = append(files, s.Filename)
 	}
 
@@ -142,7 +157,8 @@ func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage) (*Buil
 		EscapeName(pkgName),
 		strings.Join(files, " "))
 
-	archivePath, _ := filepath.Abs(filepath.Dir(b.ArchivePath(bpkg)))
+	archivePath := filepath.Dir(b.ArchivePath(bpkg))
+	archivePath = trimProjectPath(archivePath)
 	CmakeCompilerInfoWrite(w, archivePath, bpkg, entries[0], otherIncludes)
 
 	return bpkg, nil
@@ -175,7 +191,7 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil
 			EscapeName(bpkg.rpkg.Lpkg.Name())))
 	}
 
-	elfOutputDir := filepath.Dir(b.AppElfPath())
+	elfOutputDir := trimProjectPath(filepath.Dir(b.AppElfPath()))
 	fmt.Fprintf(w, "file(WRITE %s \"\")\n", filepath.Join(elfOutputDir, "null.c"))
 	fmt.Fprintf(w, "add_executable(%s %s)\n\n", elfName, filepath.Join(elfOutputDir, "null.c"))
 
@@ -243,6 +259,7 @@ func CmakeCompilerInfoWrite(w io.Writer, archiveFile string, bpkg *BuildPackage,
 	includes = append(includes, otherIncludes...)
 
 	includes = removeDuplicates(includes)
+	trimProjectPathSlice(includes)
 
 	fmt.Fprintf(w, `set_target_properties(%s
 							PROPERTIES


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services