Skip to content

Commit

Permalink
[vcpkg] Portfile Settings (#7292)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbezault committed Jul 19, 2019
1 parent cf9820b commit 618fa20
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
3 changes: 3 additions & 0 deletions scripts/get_triplet_environment.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
include(${CMAKE_TRIPLET_FILE})
if (DEFINED CMAKE_ENV_OVERRIDES_FILE)
include(${CMAKE_ENV_OVERRIDES_FILE} OPTIONAL)
endif()

# GUID used as a flag - "cut here line"
message("c35112b6-d1ba-415b-aa5d-81de856ef8eb")
Expand Down
1 change: 1 addition & 0 deletions scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if(CMD MATCHES "^BUILD$")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR} ${CURRENT_PACKAGES_DIR})

include(${CMAKE_TRIPLET_FILE})
include(${ENV_OVERRIDES_FILE} OPTIONAL)
set(TRIPLET_SYSTEM_ARCH ${VCPKG_TARGET_ARCHITECTURE})
include(${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_common_definitions.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_common_functions.cmake)
Expand Down
59 changes: 31 additions & 28 deletions toolsrc/include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,6 @@ namespace vcpkg::Build
std::string create_error_message(const BuildResult build_result, const PackageSpec& spec);
std::string create_user_troubleshooting_message(const PackageSpec& spec);

enum class VcpkgTripletVar
{
TARGET_ARCHITECTURE = 0,
CMAKE_SYSTEM_NAME,
CMAKE_SYSTEM_VERSION,
PLATFORM_TOOLSET,
VISUAL_STUDIO_PATH,
CHAINLOAD_TOOLCHAIN_FILE,
BUILD_TYPE,
ENV_PASSTHROUGH,
};

const std::unordered_map<std::string, VcpkgTripletVar> VCPKG_OPTIONS = {
{"VCPKG_TARGET_ARCHITECTURE", VcpkgTripletVar::TARGET_ARCHITECTURE},
{"VCPKG_CMAKE_SYSTEM_NAME", VcpkgTripletVar::CMAKE_SYSTEM_NAME},
{"VCPKG_CMAKE_SYSTEM_VERSION", VcpkgTripletVar::CMAKE_SYSTEM_VERSION},
{"VCPKG_PLATFORM_TOOLSET", VcpkgTripletVar::PLATFORM_TOOLSET},
{"VCPKG_VISUAL_STUDIO_PATH", VcpkgTripletVar::VISUAL_STUDIO_PATH},
{"VCPKG_CHAINLOAD_TOOLCHAIN_FILE", VcpkgTripletVar::CHAINLOAD_TOOLCHAIN_FILE},
{"VCPKG_BUILD_TYPE", VcpkgTripletVar::BUILD_TYPE},
{"VCPKG_ENV_PASSTHROUGH", VcpkgTripletVar::ENV_PASSTHROUGH},
};

/// <summary>
/// Settings from the triplet file which impact the build environment and post-build checks
/// </summary>
Expand All @@ -148,7 +125,9 @@ namespace vcpkg::Build
/// <summary>
/// Runs the triplet file in a "capture" mode to create a PreBuildInfo
/// </summary>
static PreBuildInfo from_triplet_file(const VcpkgPaths& paths, const Triplet& triplet);
static PreBuildInfo from_triplet_file(const VcpkgPaths& paths,
const Triplet& triplet,
Optional<const SourceControlFileLocation&> port = nullopt);

std::string triplet_abi_tag;
std::string target_architecture;
Expand All @@ -163,6 +142,29 @@ namespace vcpkg::Build

std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset);

enum class VcpkgTripletVar
{
TARGET_ARCHITECTURE = 0,
CMAKE_SYSTEM_NAME,
CMAKE_SYSTEM_VERSION,
PLATFORM_TOOLSET,
VISUAL_STUDIO_PATH,
CHAINLOAD_TOOLCHAIN_FILE,
BUILD_TYPE,
ENV_PASSTHROUGH,
};

const std::unordered_map<std::string, VcpkgTripletVar> VCPKG_OPTIONS = {
{"VCPKG_TARGET_ARCHITECTURE", VcpkgTripletVar::TARGET_ARCHITECTURE},
{"VCPKG_CMAKE_SYSTEM_NAME", VcpkgTripletVar::CMAKE_SYSTEM_NAME},
{"VCPKG_CMAKE_SYSTEM_VERSION", VcpkgTripletVar::CMAKE_SYSTEM_VERSION},
{"VCPKG_PLATFORM_TOOLSET", VcpkgTripletVar::PLATFORM_TOOLSET},
{"VCPKG_VISUAL_STUDIO_PATH", VcpkgTripletVar::VISUAL_STUDIO_PATH},
{"VCPKG_CHAINLOAD_TOOLCHAIN_FILE", VcpkgTripletVar::CHAINLOAD_TOOLCHAIN_FILE},
{"VCPKG_BUILD_TYPE", VcpkgTripletVar::BUILD_TYPE},
{"VCPKG_ENV_PASSTHROUGH", VcpkgTripletVar::ENV_PASSTHROUGH},
};

struct ExtendedBuildResult
{
ExtendedBuildResult(BuildResult code);
Expand All @@ -176,19 +178,20 @@ namespace vcpkg::Build

struct BuildPackageConfig
{
BuildPackageConfig(const SourceControlFile& src,
BuildPackageConfig(const SourceControlFileLocation& scfl,
const Triplet& triplet,
fs::path&& port_dir,
const BuildPackageOptions& build_package_options,
const std::set<std::string>& feature_list)
: scf(src)
: scfl(scfl)
, scf(*scfl.source_control_file)
, triplet(triplet)
, port_dir(std::move(port_dir))
, port_dir(scfl.source_location)
, build_package_options(build_package_options)
, feature_list(feature_list)
{
}

const SourceControlFileLocation& scfl;
const SourceControlFile& scf;
const Triplet& triplet;
fs::path port_dir;
Expand Down
24 changes: 18 additions & 6 deletions toolsrc/src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace vcpkg::Build::Command
features_as_set.emplace("core");

const Build::BuildPackageConfig build_config{
scf, spec.triplet(), fs::path(scfl.source_location), build_package_options, features_as_set};
scfl, spec.triplet(), build_package_options, features_as_set};

const auto build_timer = Chrono::ElapsedTimer::create_started();
const auto result = Build::build_package(paths, build_config, status_db);
Expand Down Expand Up @@ -402,6 +402,7 @@ namespace vcpkg::Build
{"CURRENT_PORT_DIR", config.port_dir},
{"TARGET_TRIPLET", triplet.canonical_name()},
{"TARGET_TRIPLET_FILE", paths.get_triplet_file_path(triplet).u8string()},
{"ENV_OVERRIDES_FILE", config.port_dir / "environment-overrides.cmake"},
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"DOWNLOADS", paths.downloads},
Expand Down Expand Up @@ -783,7 +784,8 @@ namespace vcpkg::Build
AbiEntry{status_it->get()->package.spec.name(), status_it->get()->package.abi});
}

const auto pre_build_info = PreBuildInfo::from_triplet_file(paths, triplet);
const auto pre_build_info =
PreBuildInfo::from_triplet_file(paths, triplet, config.scfl);

auto maybe_abi_tag_and_file = compute_abi_tag(paths, config, pre_build_info, dependency_abis);

Expand Down Expand Up @@ -998,19 +1000,29 @@ namespace vcpkg::Build
return inner_create_buildinfo(*pghs.get());
}

PreBuildInfo PreBuildInfo::from_triplet_file(const VcpkgPaths& paths, const Triplet& triplet)
PreBuildInfo PreBuildInfo::from_triplet_file(const VcpkgPaths& paths,
const Triplet& triplet,
Optional<const SourceControlFileLocation&> port)
{
static constexpr CStringView FLAG_GUID = "c35112b6-d1ba-415b-aa5d-81de856ef8eb";

const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
const fs::path ports_cmake_script_path = paths.scripts / "get_triplet_environment.cmake";
const fs::path triplet_file_path = paths.get_triplet_file_path(triplet);

std::vector<System::CMakeVariable> args{{"CMAKE_TRIPLET_FILE", triplet_file_path}};

if (port)
{
args.emplace_back(
"CMAKE_ENV_OVERRIDES_FILE",
port.value_or_exit(VCPKG_LINE_INFO).source_location / "environment-overrides.cmake");
}

const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path,
ports_cmake_script_path,
{
{"CMAKE_TRIPLET_FILE", triplet_file_path},
});
args);

const auto ec_data = System::cmd_execute_and_capture_output(cmd_launch_cmake);
Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, ec_data.output);

Expand Down
12 changes: 9 additions & 3 deletions toolsrc/src/vcpkg/commands.ci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ namespace vcpkg::Commands::CI
auto triplet = p->spec.triplet();

const Build::BuildPackageConfig build_config{
*scfl->source_control_file,
*scfl,
triplet,
static_cast<fs::path>(scfl->source_location),
build_options,
p->feature_list
};
Expand All @@ -254,7 +253,14 @@ namespace vcpkg::Commands::CI
return {spec.name(), it->second};
});
const auto& pre_build_info = pre_build_info_cache.get_lazy(
triplet, [&]() { return Build::PreBuildInfo::from_triplet_file(paths, triplet); });
triplet,
[&]() {
return Build::PreBuildInfo::from_triplet_file(
paths,
triplet,
*scfl);
}
);

auto maybe_tag_and_file =
Build::compute_abi_tag(paths, build_config, pre_build_info, dependency_abis);
Expand Down
3 changes: 1 addition & 2 deletions toolsrc/src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,8 @@ namespace vcpkg::Install

auto result = [&]() -> Build::ExtendedBuildResult {
const auto& scfl = action.source_control_file_location.value_or_exit(VCPKG_LINE_INFO);
const Build::BuildPackageConfig build_config{*scfl.source_control_file,
const Build::BuildPackageConfig build_config{scfl,
action.spec.triplet(),
static_cast<fs::path>(scfl.source_location),
action.build_options,
action.feature_list};
return Build::build_package(paths, build_config, status_db);
Expand Down

0 comments on commit 618fa20

Please sign in to comment.