diff --git a/build_tests/typical/carat.rb b/build_tests/typical/carat.rb index 52acf4f..604ed2b 100644 --- a/build_tests/typical/carat.rb +++ b/build_tests/typical/carat.rb @@ -1,9 +1,10 @@ build do Environment.new(echo: :command) do |env| - env.append('CPPPATH' => glob('src/**').sort) + env.append("CPPPATH" => glob("src/**")) FileUtils.mkdir_p(env.build_root) FileUtils.mv("src/one/one.c", env.build_root) + FileUtils.mv("src/two/two.c", Rscons.application.build_dir) env.Object("^/one.o", "^/one.c") - env.Program("program.exe", glob('src/**/*.c') + ["^/one.o"]) + env.Program("^^/program.exe", ["^/one.o", "^^/two.c"]) end end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index c5c47bb..44761ed 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -475,10 +475,12 @@ module Rscons output_fname end - # Expand a path to be relative to the Environment's build root. + # Expand paths. # # Paths beginning with "^/" are expanded by replacing "^" with the - # Environment's build root. + # Environment's build root (e.g. "build/envname"). + # Paths beginning with "^^/" are expanded by replacing "^^" with the + # top-level build directory (e.g. "build"). # # @param path [String, Array] # The path(s) to expand. @@ -493,7 +495,7 @@ module Rscons expand_path(path) end else - path.sub(%r{^\^(?=[\\/])}, @build_root).gsub("\\", "/") + path.sub(%r{^\^\^(?=[\\/])}, Rscons.application.build_dir).sub(%r{^\^(?=[\\/])}, @build_root).gsub("\\", "/") end end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 4bea9ff..ad95cfb 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -338,14 +338,14 @@ EOF ] end - it "expands target and source paths starting with ^/ to be relative to the build root" do + it "expands target and source paths starting with ^/ and ^^/" do test_dir("typical") - result = run_rscons(rsconscript: "carat.rb") + result = run_rscons(rsconscript: "carat.rb", rscons_args: %w[-b bld]) expect(result.stderr).to eq "" verify_lines(lines(result.stdout), [ - %r{gcc -c -o build/e.1/one.o -MMD -MF build/e.1/one.o.mf -Isrc -Isrc/one -Isrc/two build/e.1/one.c}, - %r{gcc -c -o build/e.1/src/two/two.c.o -MMD -MF build/e.1/src/two/two.c.o.mf -Isrc -Isrc/one -Isrc/two src/two/two.c}, - %r{gcc -o program.exe build/e.1/src/two/two.c.o build/e.1/one.o}, + %r{gcc -c -o bld/e.1/one.o -MMD -MF bld/e.1/one.o.mf -Isrc -Isrc/one -Isrc/two bld/e.1/one.c}, + %r{gcc -c -o bld/e.1/bld/two.c.o -MMD -MF bld/e.1/bld/two.c.o.mf -Isrc -Isrc/one -Isrc/two bld/two.c}, + %r{gcc -o bld/program.exe bld/e.1/one.o bld/e.1/bld/two.c.o}, ]) end