Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Added cxx_library() support for buck local generation #148

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions BuckLocal/ruby_scripts/project_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ def generate_buck_local_buck_file
FileUtils.touch(buck_file)

deps_targets = Targets.new(Targets.all_deps(@top_level_lib_target))
library_targets = deps_targets.apple_library_targets + deps_targets.cxx_library_targets

# Save the deps list into a file which will be used in build phase.
Query.generate_deps_list_file(deps_targets.apple_library_targets, output_file_path)
Query.generate_deps_list_file(library_targets, output_file_path)

# Generate the linker flag to link with all Buck built libraries when building the App binary.
libraries_linker_flag = deps_targets.apple_library_targets.select { |path| path.key?(BuckLocal::Targets::OUTPUT_PATH) }.map do |path|
libraries_linker_flag = library_targets.select { |path|
# Skip output_path which is not a library type
path.key?(BuckLocal::Targets::OUTPUT_PATH) &&
(File.extname(path[BuckLocal::Targets::OUTPUT_PATH]) == ".a" ||
File.extname(path[BuckLocal::Targets::OUTPUT_PATH]) == ".so")
}.map do |path|
# The `[3..-3]`` operator gets rid of the "lib" prefix and the ".a" suffix from the filename
'-l' + File.basename(path[BuckLocal::Targets::OUTPUT_PATH])[3..-3]
end
Expand Down
5 changes: 4 additions & 1 deletion BuckLocal/ruby_scripts/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class Query
# @param [String] output_file_path The path for the generated dependencies list file.
#
def self.generate_dep_list_file(target_name, output_file_path)
generate_deps_list_file(Targets.new(Targets.all_deps(target_name)).apple_library_targets, output_file_path)
targets = Targets.new(Targets.all_deps(target_name))
libraries = targets.apple_library_targets + targets.cxx_library_targets

generate_deps_list_file(libraries, output_file_path)
end

#
Expand Down
9 changes: 9 additions & 0 deletions BuckLocal/ruby_scripts/spec/buck_local_targets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
end
end

describe '#cxx_library_targets' do
it 'gets all cxx_library targets' do
expected_target_names = [
'//BuckLocal/tests_fixture:CxxLib#iphonesimulator-x86_64,static',
]
expect(subject.class.qualified_names(subject.cxx_library_targets)).to match_array(expected_target_names)
end
end

describe '#prebuilt_cxx_library_targets' do
it 'gets all prebuilt_cxx_library targets' do
expected_target_names = [
Expand Down
21 changes: 19 additions & 2 deletions BuckLocal/ruby_scripts/targets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ def apple_library_targets
@apple_library_targets
end

# A list of cxx_library targets
# Each target contains the output path of the .a file if there is.
def cxx_library_targets
if @cxx_library_targets.nil?
# For cxx_library, we need their output path (the location of the .a files).
# We can only get the output path from the query of their fully qualified names, e.g. //ios/Module:Module#iphonesimulator-x86_64,static
target_qualified_names = self.class.qualified_names(filter_targets(@targets, 'cxx_library'))

if target_qualified_names.empty?
@cxx_library_targets = []
return @cxx_library_targets
end
@cxx_library_targets = JSON.parse(Targets.get_command_output("targets #{target_qualified_names.join(' ')} --show-output --output-attributes #{COMMON_ATTRIBUTES.join(' ')} #{OUTPUT_PATH}"))
end
@cxx_library_targets
end

# A list of prebuilt_cxx_library targets
# Each target contains the path of the of library.
def prebuilt_cxx_library_targets
Expand Down Expand Up @@ -87,9 +104,9 @@ def apple_bundle_targets
@apple_bundle_targets
end

# Consodidate exported linker flags from apple_library and prebuilt_cxx_library
# Consodidate exported linker flags from apple_library, cxx_library and prebuilt_cxx_library
def exported_linker_flags
(filter_targets(@targets, 'apple_library') + filter_targets(@targets, 'prebuilt_cxx_library')).map { |json| json[LINKER_FLAGS] }.compact.flatten
(filter_targets(@targets, 'apple_library') + filter_targets(@targets, 'cxx_library') + filter_targets(@targets, 'prebuilt_cxx_library')).map { |json| json[LINKER_FLAGS] }.compact.flatten
end

# Filter a list of Buck targets based on the target type.
Expand Down
5 changes: 5 additions & 0 deletions BuckLocal/tests_fixture/BUCK.fixture
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ apple_library(
name = "Lib3",
deps = [
":PrebuiltLib1",
":CxxLib",
":AssetCatalog1",
]
)

cxx_library(
name = "CxxLib"
)

prebuilt_cxx_library(
name = "PrebuiltLib1",
static_lib = "lib1.a",
Expand Down