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

+ Add support to "podspec" parameter for #452 #453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 29 additions & 4 deletions source/IOSResolver/src/IOSResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ public static string PropertyDictionaryToString(
/// <summary>
/// Get the path of a pod without quotes. If the path isn't present, returns an empty
/// string.
/// This also support "podspecPath" parameters. It will prefer podspecPath parameter over path
/// if present.
/// </summary>
public string LocalPath {
get {
string path;
if (!propertiesByName.TryGetValue("path", out path)) return "";
if (!propertiesByName.TryGetValue("podspecPath", out path)){
if (!propertiesByName.TryGetValue("path", out path)) return "";
}
Comment on lines +134 to +136
Copy link
Collaborator

@chkuang-g chkuang-g Aug 6, 2021

Choose a reason for hiding this comment

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

As mentioned. It is better to have two different properties for path and podspecPath, and handle them separately later.

        private string GetPathFromProperties(string name) {
            string path;
            if (!propertiesByName.TryGetValue(name, out path)) return "";
            if (path.StartsWith("'") && path.EndsWith("'")) {
                path = path.Substring(1, path.Length - 2);
            }
            return path;
        }

        public string LocalPath {
            get {
                return GetPathFromProperties("path");
            }
        }

        public string PodSpecPath {
            get {
                return GetPathFromProperties("podspec");
            }
        }

See the next comment.

if (path.StartsWith("'") && path.EndsWith("'")) {
path = path.Substring(1, path.Length - 2);
}
Expand All @@ -149,7 +153,23 @@ public string PodFilePodLine {
var outputPropertiesByName = new Dictionary<string, string>(propertiesByName);
var path = LocalPath;
if (!String.IsNullOrEmpty(path)) {
outputPropertiesByName["path"] = String.Format("'{0}'", Path.GetFullPath(path));
if(outputPropertiesByName.ContainsKey("podspecPath")) {
// Check if it is a local folder or http://
// If it is local folder add full path into OutputProperties
// If it is URI, kept as-is
if(Uri.IsWellFormedUriString(path, UriKind.Absolute)) {
outputPropertiesByName.Add("podspec", String.Format("'{0}'", path));
}
else {
outputPropertiesByName.Add("podspec", String.Format("'{0}'", Path.GetFullPath(path)));
}
// Remove "path" parameter and temporary "podspecPath" parameter
outputPropertiesByName.Remove("path");
outputPropertiesByName.Remove("podspecPath");
}
else {
outputPropertiesByName["path"] = String.Format("'{0}'", Path.GetFullPath(path));
}
Comment on lines +156 to +172
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, it is really nice to check redundancy here but I will leave that responsibility to the person who author Dependencies.xml, unless you are adding additional warning here when both properties exist.

I think it is much cleaner for you and your case now to just treat them as separate properties, like this

                var podSpecPath = PodSpecPath;
                if (!String.IsNullOrEmpty(podSpecPath)) {
                    if(Uri.IsWellFormedUriString(podSpecPath, UriKind.Absolute)) {
                        outputPropertiesByName.Add("podspec", String.Format("'{0}'", podSpecPath));
                    }
                    else {
                        outputPropertiesByName.Add("podspec", String.Format("'{0}'", Path.GetFullPath(podSpecPath)));
                    }
                }

                var localPath = LocalPath;
                if (!String.IsNullOrEmpty(localPath)) {
                    outputPropertiesByName["path"] = String.Format("'{0}'", Path.GetFullPath(localPath));
                }

}
var propertiesString = PropertyDictionaryToString(outputPropertiesByName);
if (!String.IsNullOrEmpty(propertiesString)) podLine += ", " + propertiesString;
Expand Down Expand Up @@ -268,15 +288,19 @@ private class IOSXmlDependencies : XmlDependencies {
// Properties to parse from a XML pod specification and store in the propert1iesByName
// dictionary of the Pod class. These are eventually expanded to the named arguments of the
// pod declaration in a Podfile.
// The value of each attribute with the exception of "path" is included as-is.
// The value of each attribute with the exception of "path" and "podspecPath" is included as-is.
// "path" is converted to a full path on the local filesystem when the Podfile is generated.
// "podspecPath": If the value is a directory it is converted to a full path on the local filesystem when the Podfile is generated.
// If the value is a URI then it is kept as-is.
// "podspecPath" will replace "path" if present
private static string[] PODFILE_POD_PROPERTIES = new string[] {
"configurations",
"configuration",
"modular_headers",
"source",
"subspecs",
"path"
"path",
"podspecPath"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is better to be just podspec to reduce confusion, since podspec is a real podfile properties like the other.

};

public IOSXmlDependencies() {
Expand All @@ -295,6 +319,7 @@ public IOSXmlDependencies() {
/// <iosPods>
/// <iosPod name="name"
/// path="pathToLocal"
/// podspecPath="pathToPodSpec"
/// version="versionSpec"
/// bitcodeEnabled="enabled"
/// minTargetSdk="sdk">
Expand Down