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

can not add new variables into Info.plist #1982

Closed
uiChuanqi opened this issue Jun 5, 2023 · 4 comments
Closed

can not add new variables into Info.plist #1982

uiChuanqi opened this issue Jun 5, 2023 · 4 comments

Comments

@uiChuanqi
Copy link

uiChuanqi commented Jun 5, 2023

Hi,

I'd like to add one key-value(Host_URL) to the Info.plist, this below is my original info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleVersion</key>
	<string>1</string>
        <key>CFBundleShortVersionString</key>
	<string>1.0</string>
        <key>Host_URL</key>
	<string>https://www.google.nl/</string>
</dict>
</plist>

i have added one personal rule named "ExpendInfo.bzl" which has an expand_template rule , then i have got the new info.plist.

My problem is that the value must be set as a constant, i can't set it as any variable ( such an Host_URL:$(Host_URL)),

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleVersion</key>
	<string>1</string>
        <key>CFBundleShortVersionString</key>
	<string>1.0</string>
        <key>Host_URL</key>
	<string>${Host_URL}</string>
</dict>
</plist>

if i do so, there will come out an error like this:
2023-06-05 18 14 54

Can you give me some suggestions? thank you.

@mattrobmattrob
Copy link
Contributor

Are you applying the substitution in your ExpendInfo rule? If so, are you referencing the output of that expansion as the input to your ios_application? Do you have a sample branch showing your issue?

In general, this should work especially if it's just a simple rule that replaces the variable(s) in the Info.plist then is used as input to the ios_application.

@uiChuanqi
Copy link
Author

uiChuanqi commented Jun 6, 2023

yeah, you are right, the generated NewInfo.plist has been changed, but it hasn't been merged into ios_application, could you please tell me how should i set the NewInfo.plist as the input to my ios_application ? thank you very much !

this is the generated NewInfo.plist:
2023-06-06 16 32 58
this is the Info.plist in project:
2023-06-06 16 34 24

This is the rule code in ExpendInfo which is the imitation of the rules/expand_template/hello.bzl

def _hello_implement(ctx):
    ctx.actions.expand_template(
        template = ctx.file.infoSrc,
        output = ctx.outputs.out,
        substitutions = ctx.attr.replaceDic,
    )

hello = rule(
    attrs = dict(
        infoSrc = attr.label(mandatory = True, allow_single_file = [".plist"]),
        replaceDic = attr.string_dict(allow_empty = False),
    ),
    outputs = {"out": "%{name}.plist"},
    implementation = _hello_implement,
)

This is my ios_application in BUILD:

load("@rules_xcodeproj//xcodeproj:defs.bzl","top_level_target","xcodeproj",)
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load(":ExpendInfo.bzl", "hello")

swift_library(
    name = "SampleAppLibrary",
    srcs = glob(["*.swift"]) ,
    visibility = ["//visibility:public"],
)

xcodeproj(
    name = "xcodeproj",
    build_mode = "bazel",
    project_name = "SampleApp",
    tags = ["manual"],
    config = "rules_xcodeproj",
    top_level_targets = [
          ":SampleApp",
    ],
    visibility = ["//visibility:public"],
)

ios_application(
    name = "SampleApp",
    bundle_id = "com.ui.SampleApp",
    families = ["iphone", "ipad"],
    minimum_os_version = "15.0",
    infoplists = [":NewInfo"],
    deps = [":SampleAppLibrary"],
    resources = glob(["Assets.xcassets/**"]) + glob(["*.xcconfig"]),
    visibility = ["//visibility:public"],
)

hello(
    name = "NewInfo",
    replacements = {
    "Host_URL" : "BUILD_test",
    },
    infoSrc = "Info.plist"
)

If i change the value for the key "Host_URL" to "${Host_URL}", that error will always come out :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleVersion</key>
	<string>1</string>
        <key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>Host_URL</key>
	<string>${Host_URL}</string>
</dict>
</plist>
243323821-3344c78b-fdc7-44d3-85b8-189c5d7ca4e2

Are you applying the substitution in your ExpendInfo rule? If so, are you referencing the output of that expansion as the input to your ios_application? Do you have a sample branch showing your issue?

In general, this should work especially if it's just a simple rule that replaces the variable(s) in the Info.plist then is used as input to the ios_application.

@mattrobmattrob
Copy link
Contributor

Can you try changing infoplists = [":NewInfo"], to infoplists = [":NewInfo.plist"], since that'll be the actual output from the target? Not sure if that'll work or not but worth a shot.

@uiChuanqi
Copy link
Author

uiChuanqi commented Jun 7, 2023

Can you try changing infoplists = [":NewInfo"], to infoplists = [":NewInfo.plist"], since that'll be the actual output from the target? Not sure if that'll work or not but worth a shot.

Finally nailed it! Thank you! I changed the statement as :

hello(
    name = "NewInfo",
    replacements = {
    "${Host_URL}" : "https://www.apple.com/",
    },
    infoSrc = "Info.plist",
)

and if i change the infoplists from ":NewInfo" to ":NewInfo.plist", the Info.plist will dispear from the project's directory, just like this below, but there is no difference when using the Host_URL in programming.

infoplists = [":NewInfo"]
2023-06-07 16 31 24

infoplists = [":NewInfo.plist"]
2023-06-07 16 32 01

@brentleyjones brentleyjones closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants