Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

[App/Ruby] Get information of user’s projects/targets. #161

Merged
merged 1 commit into from
Jan 1, 2016
Merged
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
14 changes: 12 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,24 @@ installed_readline = readline_tasks.installed_path
# ------------------------------------------------------------------------------

class RubyTasks < BundleDependencyTasks
attr_accessor :installed_libruby_path
attr_accessor :installed_libruby_path, :installed_dependencies

# TODO Look into using ext/extinit.c instead, but this will autoload the extensions,
# so that makes more sense to look into when switching to a dynamic libruby.
def define_install_libruby_task
file installed_libruby_path => artefact_path do
cp artefact_path, installed_libruby_path
%w{ bigdecimal date/date_core.a pathname stringio }.each do |ext|
%w{ bigdecimal date/date_core.a digest fiddle pathname psych stringio strscan }.each do |ext|
ext = "#{ext}/#{ext}.a" unless File.extname(ext) == '.a'
execute '/usr/bin/libtool', '-static', '-o', installed_libruby_path, installed_libruby_path, File.join(build_dir, 'ext', ext)
end

execute '/usr/bin/libtool', '-static', '-o', installed_libruby_path, installed_libruby_path, File.join(build_dir, 'enc', 'libenc.a')
execute '/usr/bin/libtool', '-static', '-o', installed_libruby_path, installed_libruby_path, File.join(build_dir, 'enc', 'libtrans.a')

installed_dependencies.each do |installed_dependency|
execute '/usr/bin/libtool', '-static', '-o', installed_libruby_path, installed_libruby_path, installed_dependency
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this all to get xcodeproj working?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly yeah.

end
end

Expand All @@ -490,6 +499,7 @@ ruby_tasks = RubyTasks.define do |t|
t.dependencies = [installed_pkg_config, installed_yaml, installed_openssl]

t.installed_libruby_path = File.join('app', 'CPReflectionService', 'libruby+exts.a')
t.installed_dependencies = [installed_yaml]
end

installed_ruby = ruby_tasks.installed_path
Expand Down
9 changes: 6 additions & 3 deletions app/CPReflectionService/CPReflectionService.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ - (void)installedPlugins:(void (^ _Nonnull)(NSArray<NSString *> * _Nullable plug
}];
}

- (void)getXcodeIntegrationInformation:(void (^ _Nonnull)(NSDictionary * _Nullable information, NSError * _Nullable error))reply
- (void)XcodeIntegrationInformationFromPodfile:(NSString * _Nonnull)contents
installationRoot:(NSString * _Nonnull)installationRoot
withReply:(void (^ _Nonnull)(NSDictionary * _Nullable information, NSError * _Nullable error))reply;
{
[RBObject performBlock:^{
RBPathname *pathname = [RBObjectFromString(@"Pathname") new:@"Podfile"];

reply(@{}, nil);
RBPodfile *podfile = [RBObjectFromString(@"Pod::Podfile") from_ruby:pathname :contents];
NSDictionary *info = [RBObjectFromString(@"Pod::App") analyze_podfile:podfile :[RBObjectFromString(@"Pathname") new:installationRoot]];
reply(info, nil);

} error:^(NSError * _Nonnull error) {
reply(nil, error);
Expand Down
4 changes: 3 additions & 1 deletion app/CPReflectionService/CPReflectionServiceProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

@protocol CPReflectionServiceProtocol

- (void)getXcodeIntegrationInformation:(void (^ _Nonnull)(NSDictionary * _Nullable information, NSError * _Nullable error))reply;
- (void)XcodeIntegrationInformationFromPodfile:(NSString * _Nonnull)contents
installationRoot:(NSString * _Nonnull)installationRoot
withReply:(void (^ _Nonnull)(NSDictionary * _Nullable information, NSError * _Nullable error))reply;

- (void)installedPlugins:(void (^ _Nonnull)(NSArray<NSString *> * _Nullable plugins, NSError * _Nullable error))reply;

Expand Down
6 changes: 6 additions & 0 deletions app/CPReflectionService/RBObject+CocoaPods.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ typedef void (^RBObjectErrorBlock)(NSError * _Nonnull error);
// https://github.com/CocoaPods/CLAide/pull/54
- (NSArray<NSString *> * _Nonnull)plugin_load_paths:(NSString * _Nonnull)prefix;
- (RBGemSpecification * _Nonnull)specification:(NSString * _Nonnull)pluginPath;
@end

// Defined in RBObject+CocoaPods.rb
@interface RBApp : RBObject
- (void)require_gems;
- (NSDictionary * _Nonnull)analyze_podfile:(RBPodfile * _Nonnull)contents :(NSString * _Nonnull)installationRoot;
@end
36 changes: 27 additions & 9 deletions app/CPReflectionService/RBObject+CocoaPods.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,49 @@
static VALUE rb_cPodInformativeError = Qnil;


// Defined in RBObject+CocoaPods.rb
@interface RBApp : RBObject
- (id)require_gems;
@end


static void
CPRubyInit(Class bundleClass)
{
NSCAssert([NSThread currentThread] == (NSThread *)RBThreadInstance, @"Should only be called from the Ruby thread.");

// setenv("RUBYCOCOA_DEBUG", "1", 1);

// Initialize the Ruby runtime and load our Ruby setup file.
RBBundleInit("RBObject+CocoaPods.rb", bundleClass, nil);

// These are C exts that are included in libruby, but we need
// to initialize them ourselves and tell the runtime that they
// have been loaded (provided).
#define INIT_EXT(name) void Init_##name(void); Init_##name();
#define PROVIDE_EXT(name) INIT_EXT(name); rb_provide(#name);
rb_provide("thread");

#define INIT_EXT(name) void Init_##name(void); Init_##name();

// Load encoding related extensions
INIT_EXT(encdb);
rb_provide("enc/trans/single_byte");
INIT_EXT(transdb);

// These encodings are used by Psych (YAML extension) and are normally autoloaded by load_encoding in encoding.c,
// however this does not happen in static libruby or I simply have not figured out how to make it work normally.
INIT_EXT(utf_16le);
INIT_EXT(utf_16be);
INIT_EXT(utf_32le);
INIT_EXT(utf_32be);

INIT_EXT(pathname);
rb_provide("pathname.so");
PROVIDE_EXT(date_core);
INIT_EXT(digest);
rb_provide("digest.so");
INIT_EXT(fiddle);
rb_provide("fiddle.so");
INIT_EXT(psych);
rb_provide("psych.so");

#define PROVIDE_EXT(name) INIT_EXT(name); rb_provide(#name);
PROVIDE_EXT(bigdecimal);
PROVIDE_EXT(date_core);
PROVIDE_EXT(stringio);
PROVIDE_EXT(strscan);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, def. Wow, I'd have never figure this stuff out :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was "easy", the encoding stuff above was the real hard part, had to do some reversing of a normal ruby bin to figure out how to load them.


// Now we can load RubyGems and the gems we need.
RBApp *app = RBObjectFromString(@"Pod::App");
Expand Down
38 changes: 37 additions & 1 deletion app/CPReflectionService/RBObject+CocoaPods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,47 @@ module App
# Doing this here so that you get nicer errors when a require fails.
def self.require_gems
require 'rubygems'
require 'cocoapods-core'
require 'cocoapods'

require 'claide/command/plugin_manager'
require 'claide/ansi'
CLAide::ANSI.disabled = true
end

# TODO This needs tests.
def self.analyze_podfile(podfile, installation_root)
config = Pod::Config.new
config.podfile = podfile
config.installation_root = installation_root
Pod::Config.instance = config

analyzer = Pod::Installer::Analyzer.new(config.sandbox, config.podfile, config.lockfile)
analysis = analyzer.send(:inspect_targets_to_integrate).values

user_projects = {}
analysis.each do |target|
user_project = user_projects[target.project_path.to_s] ||= {}
user_targets = user_project["targets"] ||= {}
target.project_target_uuids.each do |uuid|
user_target = target.project.objects_by_uuid[uuid]
user_target_info = user_targets[user_target.name] ||= begin
{
"info_plist" => user_target.resolved_build_setting("INFOPLIST_FILE").values.first,
"type" => user_target.product_type,
"platform" => target.platform.to_s,
"pod_targets" => []
}
end
user_target_info["pod_targets"] << target.target_definition.label
end
end

pod_targets = config.podfile.target_definitions.values.inject({}) do |h, target_definition|
h[target_definition.label] = target_definition.dependencies.map(&:name) unless target_definition.empty?
h
end

{ "projects" => user_projects, "pod_targets" => pod_targets }
end
end
end
8 changes: 6 additions & 2 deletions app/CocoaPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
51165E571A1B925300DCFC94 /* CPUserProject.m in Sources */ = {isa = PBXBuildFile; fileRef = 51165E551A1B925300DCFC94 /* CPUserProject.m */; };
5127C3291A23E6CA0093143B /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5127C3281A23E6CA0093143B /* CoreFoundation.framework */; };
5127C32B1A23E6DD0093143B /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5127C32A1A23E6DD0093143B /* CoreServices.framework */; };
514280CA1C36C1BD00DCE23D /* libffi.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 514280C91C36C1BD00DCE23D /* libffi.tbd */; };
5180FE941AD2A51300314D61 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 5180FE931AD2A51300314D61 /* LICENSE */; };
51CFC7841A2DF88700F9ABCB /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51CFC7831A2DF88700F9ABCB /* Security.framework */; };
51CFC7861A2DF8E000F9ABCB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51CFC7851A2DF8E000F9ABCB /* Cocoa.framework */; };
Expand Down Expand Up @@ -61,9 +62,9 @@
606D1EDA1BF911EF000B7148 /* CPPodfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 606D1ED91BF911EF000B7148 /* CPPodfileViewController.swift */; };
6075BA651C068B5F00A5C491 /* Podfile.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6075BA641C068B5F00A5C491 /* Podfile.xcassets */; };
6075BA671C06963700A5C491 /* CPInstallAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6075BA661C06963700A5C491 /* CPInstallAction.swift */; };
60814A8A1C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60814A891C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift */; };
60814A851C2B100F00D6663E /* CPBorderedButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 60814A841C2B100F00D6663E /* CPBorderedButton.m */; };
60814A881C2BCFEA00D6663E /* CPWhiteCheckedButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 60814A871C2BCFEA00D6663E /* CPWhiteCheckedButton.m */; };
60814A8A1C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60814A891C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift */; };
6085133F1BB6A3D500595B97 /* CPRecentDocumentsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6085133E1BB6A3D500595B97 /* CPRecentDocumentsController.m */; };
60F02D1C1C0A2A6D003600FE /* CocoaPodsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60F02D1B1C0A2A6D003600FE /* CocoaPodsTests.swift */; };
60F02D251C0A2E63003600FE /* Pods-CocoaPods.debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 60F02D231C0A2E63003600FE /* Pods-CocoaPods.debug.xcconfig */; };
Expand Down Expand Up @@ -178,6 +179,7 @@
51165E551A1B925300DCFC94 /* CPUserProject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPUserProject.m; sourceTree = "<group>"; };
5127C3281A23E6CA0093143B /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
5127C32A1A23E6DD0093143B /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
514280C91C36C1BD00DCE23D /* libffi.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libffi.tbd; path = usr/lib/libffi.tbd; sourceTree = SDKROOT; };
5180FE931AD2A51300314D61 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE; path = ../../../LICENSE; sourceTree = "<group>"; };
519C328E1C029E3C003BDC49 /* libruby+exts.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libruby+exts.a"; sourceTree = "<group>"; };
51CFC7831A2DF88700F9ABCB /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -214,11 +216,11 @@
606D1ED91BF911EF000B7148 /* CPPodfileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPPodfileViewController.swift; sourceTree = "<group>"; };
6075BA641C068B5F00A5C491 /* Podfile.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Podfile.xcassets; sourceTree = "<group>"; };
6075BA661C06963700A5C491 /* CPInstallAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPInstallAction.swift; sourceTree = "<group>"; };
60814A891C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPInterfaceBuilderOnlyLabels.swift; sourceTree = "<group>"; };
60814A831C2B100F00D6663E /* CPBorderedButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPBorderedButton.h; sourceTree = "<group>"; };
60814A841C2B100F00D6663E /* CPBorderedButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPBorderedButton.m; sourceTree = "<group>"; };
60814A861C2BCFEA00D6663E /* CPWhiteCheckedButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPWhiteCheckedButton.h; sourceTree = "<group>"; };
60814A871C2BCFEA00D6663E /* CPWhiteCheckedButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPWhiteCheckedButton.m; sourceTree = "<group>"; };
60814A891C2C420600D6663E /* CPInterfaceBuilderOnlyLabels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPInterfaceBuilderOnlyLabels.swift; sourceTree = "<group>"; };
6085133D1BB6A3D500595B97 /* CPRecentDocumentsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPRecentDocumentsController.h; sourceTree = "<group>"; };
6085133E1BB6A3D500595B97 /* CPRecentDocumentsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPRecentDocumentsController.m; sourceTree = "<group>"; };
60F02D191C0A2A6D003600FE /* CocoaPodsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CocoaPodsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -243,6 +245,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
514280CA1C36C1BD00DCE23D /* libffi.tbd in Frameworks */,
510254331C0A68040045FCD8 /* libruby+exts.a in Frameworks */,
510254341C0A68100045FCD8 /* RubyCocoa.framework in Frameworks */,
);
Expand Down Expand Up @@ -291,6 +294,7 @@
46126B404240E403B2193EE7 /* Frameworks */ = {
isa = PBXGroup;
children = (
514280C91C36C1BD00DCE23D /* libffi.tbd */,
51EA178F1C0155E9000DC69A /* RubyCocoa.framework */,
51CFC7851A2DF8E000F9ABCB /* Cocoa.framework */,
51CFC7831A2DF88700F9ABCB /* Security.framework */,
Expand Down
6 changes: 6 additions & 0 deletions app/CocoaPods/CPPodfileReflection.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ - (void)parsePodfile;
}
});
}];

[reflectionService.remoteObjectProxy XcodeIntegrationInformationFromPodfile:project.contents
installationRoot:project.fileURL.URLByDeletingLastPathComponent.path
withReply:^(NSDictionary * _Nullable information, NSError * _Nullable error) {
NSLog(@"INFO: %@", information);
}];
}

static SMLSyntaxError * _Nullable
Expand Down
4 changes: 2 additions & 2 deletions app/CocoaPods/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.39.0</string>
<string>1.0.0.beta.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand All @@ -73,7 +73,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>0.39.0</string>
<string>1.0.0.beta.1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
2 changes: 1 addition & 1 deletion app/RubyCocoa