You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/17 15:34:47 UTC
[mynewt-newt] 01/02: cmake: Fix trimming project path on Windows
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit 8655235ef89cd4349f444eff1ed2d1a701b1f71c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Mar 17 13:59:06 2022 +0100
cmake: Fix trimming project path on Windows
strings.TrimPrefix does not work properly if path already uses
backshasles as path separator, filepath.Rel will take care of that
automatically.
Also trimProjectPath should now replace backslashes internally to keep
returned value consistent.
---
newt/builder/cmake.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go
index 6e5767c..61f7767 100644
--- a/newt/builder/cmake.go
+++ b/newt/builder/cmake.go
@@ -88,8 +88,8 @@ func escapeFlagsSlice(flags []string) []string {
func trimProjectPath(path string) string {
proj := interfaces.GetProject()
- path = strings.TrimPrefix(path, proj.Path()+"/")
- return path
+ path, _ = filepath.Rel(proj.Path(), path)
+ return replaceBackslashes(path)
}
func trimProjectPathSlice(elements []string) {
@@ -198,7 +198,7 @@ func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage,
fmt.Fprintf(w, "add_library(%s %s)\n",
EscapePkgName(pkgName),
strings.Join(files, " "))
- archivePath := replaceBackslashes(trimProjectPath(filepath.Dir(b.ArchivePath(bpkg))))
+ archivePath := trimProjectPath(filepath.Dir(b.ArchivePath(bpkg)))
CmakeCompilerInfoWrite(w, archivePath, bpkg, entries[0], otherIncludes)
return bpkg, nil
@@ -241,7 +241,7 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil
ExtractLibraryName(filename)))
}
- elfOutputDir := replaceBackslashes(trimProjectPath(filepath.Dir(b.AppElfPath())))
+ elfOutputDir := trimProjectPath(filepath.Dir(b.AppElfPath()))
fmt.Fprintf(w, "file(WRITE %s \"\")\n", replaceBackslashes(filepath.Join(elfOutputDir, "null.c")))
fmt.Fprintf(w, "add_executable(%s %s)\n\n", elfName,
replaceBackslashes(filepath.Join(elfOutputDir, "null.c")))