create & edit commands now only handle package names

This commit is contained in:
Alexander Karatarakis 2016-09-30 18:21:38 -07:00
parent ce68e1a11e
commit e507c14229
5 changed files with 70 additions and 81 deletions

View File

@ -1,5 +1,11 @@
cmake_minimum_required(VERSION 3.5)
macro(debug_message)
if(DEFINED PORT_DEBUG AND PORT_DEBUG)
message(STATUS "[DEBUG] ${ARGN}")
endif()
endmacro()
#Detect .vcpkg-root to figure VCPKG_ROOT_DIR
SET(VCPKG_ROOT_DIR_CANDIDATE ${CMAKE_CURRENT_LIST_DIR})
while(IS_DIRECTORY ${VCPKG_ROOT_DIR_CANDIDATE} AND NOT EXISTS "${VCPKG_ROOT_DIR_CANDIDATE}/.vcpkg-root")
@ -13,14 +19,6 @@ endwhile()
set(VCPKG_ROOT_DIR ${VCPKG_ROOT_DIR_CANDIDATE})
string(REGEX REPLACE "([^-]*)-([^-]*)" "\\1" TRIPLET_SYSTEM_ARCH ${TARGET_TRIPLET})
string(REGEX REPLACE "([^-]*)-([^-]*)" "\\2" TRIPLET_SYSTEM_NAME ${TARGET_TRIPLET})
set(CMAKE_TRIPLET_FILE ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
if(NOT EXISTS ${CMAKE_TRIPLET_FILE})
message(FATAL_ERROR "Unsupported target triplet. Triplet file does not exist: ${CMAKE_TRIPLET_FILE}")
endif()
list(APPEND CMAKE_MODULE_PATH ${VCPKG_ROOT_DIR}/scripts/cmake)
set(CURRENT_INSTALLED_DIR ${VCPKG_ROOT_DIR}/installed/${TARGET_TRIPLET} CACHE PATH "Location to install final packages")
set(DOWNLOADS ${VCPKG_ROOT_DIR}/downloads CACHE PATH "Location to download sources and tools")
@ -32,43 +30,16 @@ if(PORT)
set(CURRENT_PACKAGES_DIR ${PACKAGES_DIR}/${PORT}_${TARGET_TRIPLET})
endif()
macro(debug_message)
if(DEFINED PORT_DEBUG AND PORT_DEBUG)
message(STATUS "[DEBUG] ${ARGN}")
endif()
endmacro()
if(CMD MATCHES "^CREATE$")
file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR)
file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS)
if(EXISTS ports/${PORT}/portfile.cmake)
message(FATAL_ERROR "Portfile already exists: '${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake'")
endif()
if(NOT FILENAME)
get_filename_component(FILENAME "${URL}" NAME)
endif()
string(REGEX REPLACE "(\\.(zip|gz|tar|tgz|bz2))+\$" "" ROOT_NAME ${FILENAME})
if(EXISTS ${DOWNLOADS}/${FILENAME})
message(STATUS "Using pre-downloaded: ${NATIVE_DOWNLOADS}\\${FILENAME}")
message(STATUS "If this is not desired, delete the file and ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}")
else()
include(vcpkg_download_distfile)
file(DOWNLOAD ${URL} ${DOWNLOADS}/${FILENAME} STATUS error_code)
if(NOT error_code MATCHES "0;")
message(FATAL_ERROR "Error downloading file: ${error_code}")
endif()
endif()
file(SHA512 ${DOWNLOADS}/${FILENAME} SHA512)
if(CMD MATCHES "^BUILD$")
string(REGEX REPLACE "([^-]*)-([^-]*)" "\\1" TRIPLET_SYSTEM_ARCH ${TARGET_TRIPLET})
string(REGEX REPLACE "([^-]*)-([^-]*)" "\\2" TRIPLET_SYSTEM_NAME ${TARGET_TRIPLET})
file(MAKE_DIRECTORY ports/${PORT})
configure_file(scripts/templates/portfile.in.cmake ports/${PORT}/portfile.cmake @ONLY)
configure_file(scripts/templates/CONTROL.in ports/${PORT}/CONTROL @ONLY)
set(CMAKE_TRIPLET_FILE ${VCPKG_ROOT_DIR}/triplets/${TARGET_TRIPLET}.cmake)
if(NOT EXISTS ${CMAKE_TRIPLET_FILE})
message(FATAL_ERROR "Unsupported target triplet. Triplet file does not exist: ${CMAKE_TRIPLET_FILE}")
endif()
message(STATUS "Generated portfile: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake")
message(STATUS "Generated CONTROL: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\CONTROL")
message(STATUS "To launch an editor for these new files, run")
message(STATUS " vcpkg edit ${PORT}")
elseif(CMD MATCHES "^BUILD$")
if(NOT DEFINED CURRENT_PORT_DIR)
message(FATAL_ERROR "CURRENT_PORT_DIR was not defined")
endif()
@ -100,4 +71,34 @@ elseif(CMD MATCHES "^BUILD$")
file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR} ${CURRENT_PACKAGES_DIR})
include(${CURRENT_PORT_DIR}/portfile.cmake)
elseif(CMD MATCHES "^CREATE$")
file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR)
file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS)
if(EXISTS ports/${PORT}/portfile.cmake)
message(FATAL_ERROR "Portfile already exists: '${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake'")
endif()
if(NOT FILENAME)
get_filename_component(FILENAME "${URL}" NAME)
endif()
string(REGEX REPLACE "(\\.(zip|gz|tar|tgz|bz2))+\$" "" ROOT_NAME ${FILENAME})
if(EXISTS ${DOWNLOADS}/${FILENAME})
message(STATUS "Using pre-downloaded: ${NATIVE_DOWNLOADS}\\${FILENAME}")
message(STATUS "If this is not desired, delete the file and ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}")
else()
include(vcpkg_download_distfile)
file(DOWNLOAD ${URL} ${DOWNLOADS}/${FILENAME} STATUS error_code)
if(NOT error_code MATCHES "0;")
message(FATAL_ERROR "Error downloading file: ${error_code}")
endif()
endif()
file(SHA512 ${DOWNLOADS}/${FILENAME} SHA512)
file(MAKE_DIRECTORY ports/${PORT})
configure_file(scripts/templates/portfile.in.cmake ports/${PORT}/portfile.cmake @ONLY)
configure_file(scripts/templates/CONTROL.in ports/${PORT}/CONTROL @ONLY)
message(STATUS "Generated portfile: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake")
message(STATUS "Generated CONTROL: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\CONTROL")
message(STATUS "To launch an editor for these new files, run")
message(STATUS " vcpkg edit ${PORT}")
endif()

View File

@ -17,8 +17,8 @@ namespace vcpkg
void install_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);
void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);
void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths);

View File

@ -6,43 +6,32 @@
namespace vcpkg
{
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
static const std::string example = create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###");
args.check_max_arg_count(3, example.c_str());
args.check_min_arg_count(2, example.c_str());
expected<package_spec> current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet);
if (const package_spec* spec = current_spec.get())
const std::string port_name = args.command_arguments.at(0);
Environment::ensure_utilities_on_path(paths);
// Space OR define the FILENAME with proper spacing
std::wstring custom_filename = L" ";
if (args.command_arguments.size() >= 3)
{
Input::check_triplet(spec->target_triplet, paths);
Environment::ensure_utilities_on_path(paths);
// Space OR define the FILENAME with proper spacing
std::wstring custom_filename = L" ";
if (args.command_arguments.size() >= 3)
{
const std::string& zip_file_name = args.command_arguments.at(2);
Checks::check_exit(!Files::has_invalid_chars_for_filesystem(zip_file_name),
R"(Filename cannot contain invalid chars %s, but was %s)",
Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name);
custom_filename = Strings::wformat(LR"( -DFILENAME="%s" )", Strings::utf8_to_utf16(zip_file_name));
}
const std::wstring cmdline = Strings::wformat(LR"(cmake -DCMD=CREATE -DPORT=%s -DTARGET_TRIPLET=%s -DURL=%s%s-P "%s")",
Strings::utf8_to_utf16(spec->name),
Strings::utf8_to_utf16(spec->target_triplet.value),
Strings::utf8_to_utf16(args.command_arguments.at(1)),
custom_filename,
paths.ports_cmake.generic_wstring());
exit(System::cmd_execute(cmdline));
}
else
{
System::println(System::color::error, "Error: %s: %s", current_spec.error_code().message(), args.command_arguments[0]);
print_example(Strings::format("%s zlib:x64-windows", args.command).c_str());
exit(EXIT_FAILURE);
const std::string& zip_file_name = args.command_arguments.at(2);
Checks::check_exit(!Files::has_invalid_chars_for_filesystem(zip_file_name),
R"(Filename cannot contain invalid chars %s, but was %s)",
Files::FILESYSTEM_INVALID_CHARACTERS, zip_file_name);
custom_filename = Strings::wformat(LR"( -DFILENAME="%s" )", Strings::utf8_to_utf16(zip_file_name));
}
const std::wstring cmdline = Strings::wformat(LR"(cmake -DCMD=CREATE -DPORT=%s -DURL=%s%s-P "%s")",
Strings::utf8_to_utf16(port_name),
Strings::utf8_to_utf16(args.command_arguments.at(1)),
custom_filename,
paths.ports_cmake.generic_wstring());
exit(System::cmd_execute(cmdline));
}
}

View File

@ -4,14 +4,13 @@
namespace vcpkg
{
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
static const std::string example = create_example_string("edit zlib");
args.check_exact_arg_count(1, example.c_str());
const package_spec spec = Input::check_and_get_package_spec(args.command_arguments.at(0), default_target_triplet, example.c_str());
Input::check_triplet(spec.target_triplet, paths);
const std::string port_name = args.command_arguments.at(0);
const fs::path portpath = paths.ports / spec.name;
const fs::path portpath = paths.ports / port_name;
// Find editor
std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR");

View File

@ -66,8 +66,6 @@ namespace vcpkg
{"install", install_command},
{"remove", remove_command},
{"build", build_command},
{"edit", edit_command},
{"create", create_command},
{"build_external", build_external_command}
};
return t;
@ -82,6 +80,8 @@ namespace vcpkg
{"integrate", integrate_command},
{"owns", owns_command},
{"update", update_command},
{"edit", edit_command},
{"create", create_command},
{"import", import_command},
{"cache", cache_command},
{"internal_test", internal_test_command},