Skip to content

--project does not properly handle absolute paths with . or .. components #6995

@nwf

Description

@nwf

Xmake Version

xmake v3.0.4+master.b3a2dba93

Operating System Version and Architecture

Linux 1f76ee561333 6.12.17-powerpc64le-64k #1 SMP Debian 6.12.17-1 (2025-03-01) ppc64le GNU/Linux

Describe Bug

If --project begins with a / but has . or .. components, then includes()-ed target()s will fail to find their files.

Given the following four files in /tmp/xmake-test:

  1. s/s.cc:
    int s(int v) { return v; }
  2. s/xmake.lua:
    target("s")
      set_default(false)
      set_kind("static")
      add_files("s.cc")
  3. b/b.cc:
    int s(int);
    int main() { return s(42); }
  4. b/xmake.lua:
    includes("../s")
    target("b")
      set_default(true)
      set_kind("binary")
      add_deps("s")
      add_files("b.cc")

and the following shell function to test things...

function test() {
  (rm -rf _ && mkdir _ && cd _; xmake config -v -D --project="$1" && xmake build -v -D)
}

then these work to build the b target() binary:

  1. test /tmp/xmake-test/b -- absolute project path
  2. (cd /tmp/xmake-test; test ../b)" -- relative (to /tmp/xmake-test/_) project path
  3. (cd /tmp/xmake-test; test .././b)" -- similarly
  4. (cd /tmp/xmake-test; test ../../xmake-test/b)" -- similarly

but these don't, because the final link step can't find the definition of s():

  1. test "/tmp/xmake-test/./b"; xmake warns:
    warning: /tmp/xmake-test/s/xmake.lua:4: cannot match add_files("../../s/s.cc") in target(s)
  2. test "/tmp/xmake-test/_/../b"; xmake warns:
    warning: /tmp/xmake-test/s/xmake.lua:4: cannot match add_files("../../../s/s.cc") in target(s)

Expected Behavior

xmake should treat all valid ways of referring to a --project path equivalently.

Project Configuration

See above.

Additional Information and Error Logs

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions