mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-22 12:17:36 -05:00
Project file creation tweaks
This commit is contained in:
@@ -42,27 +42,27 @@ class Project
|
|||||||
|
|
||||||
attr :src_dir, :bin_dir
|
attr :src_dir, :bin_dir
|
||||||
|
|
||||||
def create_file(target_path, text)
|
def create_file(target_path, text, args = {})
|
||||||
target_path = File.join(@src_dir, target_path)
|
target_path = File.join(@src_dir, target_path)
|
||||||
File.write target_path, text
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_file_with(target_path, source_path, args)
|
|
||||||
source_path = File.join(@src_dir, source_path)
|
|
||||||
raise "#{source_path} doesn't exist" if !File.file?(source_path)
|
|
||||||
|
|
||||||
# tweak args
|
# tweak args
|
||||||
args[:cpm_path] = TestLib::CPM_PATH if !args[:cpm_path]
|
args[:cpm_path] = TestLib::CPM_PATH if !args[:cpm_path]
|
||||||
args[:packages] = [args[:package]] if args[:package] # if args contain package, create the array
|
args[:packages] = [args[:package]] if args[:package] # if args contain package, create the array
|
||||||
args[:packages] = args[:packages].join("\n") if args[:packages] # join all packages if any
|
args[:packages] = args[:packages].join("\n") if args[:packages] # join all packages if any
|
||||||
|
|
||||||
|
File.write target_path, text % args
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_file_from_template(target_path, source_path, args = {})
|
||||||
|
source_path = File.join(@src_dir, source_path)
|
||||||
|
raise "#{source_path} doesn't exist" if !File.file?(source_path)
|
||||||
src_text = File.read source_path
|
src_text = File.read source_path
|
||||||
create_file target_path, src_text % args
|
create_file target_path, src_text, args
|
||||||
end
|
end
|
||||||
|
|
||||||
# common function to create ./CMakeLists.txt from ./lists.in.cmake
|
# common function to create ./CMakeLists.txt from ./lists.in.cmake
|
||||||
def create_lists_with(args)
|
def create_lists_from_default_template(args = {})
|
||||||
create_file_with 'CMakeLists.txt', 'lists.in.cmake', args
|
create_file_from_template 'CMakeLists.txt', 'lists.in.cmake', args
|
||||||
end
|
end
|
||||||
|
|
||||||
CommandResult = Struct.new :out, :err, :status
|
CommandResult = Struct.new :out, :err, :status
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class Basics < IntegrationTest
|
|||||||
# Test cpm caches with no cpm-related env vars
|
# Test cpm caches with no cpm-related env vars
|
||||||
def test_cpm_default
|
def test_cpm_default
|
||||||
prj = make_project 'no-deps'
|
prj = make_project 'no-deps'
|
||||||
prj.create_lists_with({})
|
prj.create_lists_from_default_template
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
@cache = prj.read_cache
|
@cache = prj.read_cache
|
||||||
@@ -39,7 +39,7 @@ class Basics < IntegrationTest
|
|||||||
ENV['CPM_SOURCE_CACHE'] = cur_test_dir
|
ENV['CPM_SOURCE_CACHE'] = cur_test_dir
|
||||||
|
|
||||||
prj = make_project 'no-deps'
|
prj = make_project 'no-deps'
|
||||||
prj.create_lists_with({})
|
prj.create_lists_from_default_template
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
@cache = prj.read_cache
|
@cache = prj.read_cache
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ class Simple < IntegrationTest
|
|||||||
adder_ver_file = nil
|
adder_ver_file = nil
|
||||||
|
|
||||||
create_with_commit_sha = -> {
|
create_with_commit_sha = -> {
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'
|
prj.create_lists_from_default_template package:
|
||||||
|
'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
cache = prj.read_cache
|
cache = prj.read_cache
|
||||||
@@ -35,7 +36,8 @@ class Simple < IntegrationTest
|
|||||||
adder_cache0 = adder_cache
|
adder_cache0 = adder_cache
|
||||||
}
|
}
|
||||||
update_to_version_1 = -> {
|
update_to_version_1 = -> {
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.0")'
|
prj.create_lists_from_default_template package:
|
||||||
|
'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.0")'
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
cache = prj.read_cache
|
cache = prj.read_cache
|
||||||
@@ -52,7 +54,7 @@ class Simple < IntegrationTest
|
|||||||
assert_equal '1.0.0', File.read(adder_ver_file).strip
|
assert_equal '1.0.0', File.read(adder_ver_file).strip
|
||||||
}
|
}
|
||||||
update_with_option_off_and_build = -> {
|
update_with_option_off_and_build = -> {
|
||||||
prj.create_lists_with package: <<~PACK
|
prj.create_lists_from_default_template package: <<~PACK
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME testpack-adder
|
NAME testpack-adder
|
||||||
GITHUB_REPOSITORY cpm-cmake/testpack-adder
|
GITHUB_REPOSITORY cpm-cmake/testpack-adder
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class SourceCache < IntegrationTest
|
|||||||
|
|
||||||
###################################
|
###################################
|
||||||
# create
|
# create
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")'
|
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")'
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
@cache = prj.read_cache
|
@cache = prj.read_cache
|
||||||
@@ -29,7 +29,7 @@ class SourceCache < IntegrationTest
|
|||||||
|
|
||||||
###################################
|
###################################
|
||||||
# add one package with a newer version
|
# add one package with a newer version
|
||||||
prj.create_lists_with packages: [
|
prj.create_lists_from_default_template packages: [
|
||||||
'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.1")',
|
'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.1")',
|
||||||
'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")',
|
'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")',
|
||||||
]
|
]
|
||||||
@@ -46,7 +46,7 @@ class SourceCache < IntegrationTest
|
|||||||
|
|
||||||
def test_second_project
|
def test_second_project
|
||||||
prj = make_project 'using-fibadder'
|
prj = make_project 'using-fibadder'
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0")'
|
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0")'
|
||||||
assert_success prj.configure
|
assert_success prj.configure
|
||||||
|
|
||||||
@cache = prj.read_cache
|
@cache = prj.read_cache
|
||||||
|
|||||||
Reference in New Issue
Block a user