From bbd63af0c497efd8f0413e9e5b67b73a292330c8 Mon Sep 17 00:00:00 2001
From: Michael Schmuki <michael@schmuki.io>
Date: Thu, 27 Jun 2024 15:43:37 +0200
Subject: [PATCH] Fix compile action and remove QGIS_JS env vars

---
 build/actions/compile.ts             | 12 +++---------
 build/vcpkg-toolchains/qgis-js.cmake |  4 ++--
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/build/actions/compile.ts b/build/actions/compile.ts
index 04e161e..5f52dc2 100644
--- a/build/actions/compile.ts
+++ b/build/actions/compile.ts
@@ -1,4 +1,4 @@
-import { dirname } from "path";
+import { dirname, join } from "path";
 import { fileURLToPath } from "url";
 
 import {
@@ -53,7 +53,7 @@ export class CompileAction extends CommandLineAction {
       const v = this._options.verbose;
       $.verbose = true;
 
-      const repo = dirname(fileURLToPath(import.meta.url));
+      const repo = join(dirname(fileURLToPath(import.meta.url)), "../..");
 
       const buildType = (this._buildType.value || "Dev") as BuildType;
       const debug = this._debug.value || false;
@@ -88,10 +88,6 @@ export class CompileAction extends CommandLineAction {
         if (v) console.log(`"${CMakeCacheFile}" does not exist`);
       }
 
-      // set qgis-js internal environment variables
-      process.env.QGIS_JS_VCPKG = `${repo}/build/vcpkg`;
-      process.env.QGIS_JS_EMSDK = `${repo}/build/emsdk`;
-
       // set environment variables for CMake
       process.env.VCPKG_BINARY_SOURCES = "clear";
       if (debug) {
@@ -109,9 +105,7 @@ export class CompileAction extends CommandLineAction {
 -S . \
 -B build/wasm \
 -G Ninja \
--DCMAKE_TOOLCHAIN_FILE=${
-          process.env.QGIS_JS_VCPKG
-        }/scripts/buildsystems/vcpkg.cmake \
+-DCMAKE_TOOLCHAIN_FILE=${repo}/build/vcpkg/scripts/buildsystems/vcpkg.cmake \
 -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${repo}/build/vcpkg-toolchains/qgis-js.cmake \
 -DVCPKG_OVERLAY_TRIPLETS=./build/vcpkg-triplets \
 -DVCPKG_OVERLAY_PORTS=./build/vcpkg-ports \
diff --git a/build/vcpkg-toolchains/qgis-js.cmake b/build/vcpkg-toolchains/qgis-js.cmake
index 927e4bc..66ff307 100644
--- a/build/vcpkg-toolchains/qgis-js.cmake
+++ b/build/vcpkg-toolchains/qgis-js.cmake
@@ -3,10 +3,10 @@ message(STATUS "Using 'qgis-js' toolchain")
 
 # use/derrive EMSDK and EMSCRIPTEN_ROOT to locate EMSCRIPTEN_TOOLCHAIN_FILE
 if(NOT DEFINED ENV{EMSDK})
-  get_filename_component(QGIS_JS_EMSDK
+  get_filename_component(QGIS_JS_BUILD_EMSDK
   "${CMAKE_CURRENT_LIST_DIR}/../emsdk"
   ABSOLUTE)
-  set(ENV{EMSDK} ${QGIS_JS_EMSDK})
+  set(ENV{EMSDK} ${QGIS_JS_BUILD_EMSDK})
 endif()
 if(NOT EMSCRIPTEN_ROOT)
    if(NOT DEFINED ENV{EMSDK})