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 MacOS notarization support #3725

Merged
merged 5 commits into from Oct 30, 2019
Merged

Add MacOS notarization support #3725

merged 5 commits into from Oct 30, 2019

Conversation

mbacchi
Copy link
Contributor

@mbacchi mbacchi commented Oct 16, 2019

Fixes issue brave/brave-browser#5177
Related brave/brave-browser#5485

Submitter Checklist:

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

]
}

-_packaging_dir = "$root_out_dir/$chrome_product_full_name Packaging"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to change the path of the packaging directory to have underscores rather than spaces in the directory name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand what it's doing, but why do we need to do that?

@property
def packaging_dir(self):
"""Returns the path to the packaging and installer tools."""
- return '{.product} Packaging'.format(self)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above, why are we changing this path?

'--volname', config.app_product,
'--icon', os.path.join(packaging_dir, icon_file),
'--copy', '{}:/'.format(app_path),
- '--copy',
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The keystone_install.sh part of the command isn't copied or called, leaving it in caused a build break during my testing.

Copy link
Collaborator

@bridiver bridiver Oct 23, 2019

Choose a reason for hiding this comment

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

where did it break? Can we remove it later or use a dummy script just to satisfy the copy? We need to find other ways to avoid patches like this

Copy link
Member

Choose a reason for hiding this comment

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

OK so we can do a touch (to create blank files for keystone_install and chrome_dmg_background.png) and then remove it before packaging

notarize.staple(package_path)
+ else:
+ # Copy the notarized app to the orig_paths.output dir where the user expects it.
+ commands.copy_files(dest_dir, orig_paths.output)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can copy files in a separate target after the signing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the brave/build/mac/BUILD.gn file, I output signed .dmg/.pkg files into the signed subdir, then I notarize them from that subdir, and add a directory that outputs the notarized .dmg/.pkg files. This also allows us to avoid a duplicate outputs error in GN because if notarization is not being done, we want the same file names to be created in the src/out/Release output directory whether only signing is requested or also if notarization is requested. To work around that I use the copy_dmg_pkg target to determine which files to copy to the output directory, depending on whether notarize is defined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't you just use a different directory to avoid the duplicate outputs? Or better yet, why don't we just plug our own notarize.py into the python path and use the existing calls with do_notarization enabled?
If we did need to keep the patch for some reason we never add comments in patches and there's no reason for the else because in this case we know that do_notarization is false. When we do have to patch files the patches should be as small as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

and actually it's not clear to me how this solves the problem anyway because now this target needs to specify the outputs that the copy would have

Copy link
Member

@bsclifton bsclifton Oct 29, 2019

Choose a reason for hiding this comment

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

@bridiver can we keep this as-is for now? I believe because we use --disable-packaging (to set custom icons, path to install location (/Applications/ etc)). We could follow up on this later (I can create an issue and @mbacchi can make sure it's tracked in the regular Devops meeting). Since this works as-is, this would eat some time ☹️

Copy link
Collaborator

Choose a reason for hiding this comment

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

it actually doesn't work as-is. It breaks gn's ability to known when things need to be updated because this script no longer specifies the correct outputs

Copy link
Collaborator

Choose a reason for hiding this comment

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

the other target that has the same output won't necessarily run when it should now

Returns:
Path to the packaging directory.
"""
- return os.path.join(self.input, '{} Packaging'.format(config.product))
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above, why are we adding underscores everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't make GN call the build/mac/notarize_dmg_pkg.py script (as an action) with an argument that contained spaces (i.e. Brave Browser Nightly Packaging). It needs the packaging directory as the argument --pkgdir which failed with spaces.

Copy link
Collaborator

Choose a reason for hiding this comment

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

there shouldn't be any problem with spaces, you just need to quote it properly. Can you link me to the gn target where you are using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is used specifically as an argument to the notarize_dmg_pkg.py script here: https://github.com/brave/brave-core/pull/3725/files#diff-39842cb5e3be671a7dd386e445aca164R328

@@ -0,0 +1,153 @@
#!/usr/bin/env python
Copy link
Collaborator

Choose a reason for hiding this comment

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

was this copied from chrome? It looks like it was and I'm curious why, but also we can't copy a chromium file and use our own copyright. That's a violation of their copyright

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it merges the brave/script/signing_helper.py create_config section with the notarization calls from chrome/installer/mac/signing/pipeline.py, but otherwise it is not copied from Chromium.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if it includes any copied chromium code we should include their copyright notice as well

Copy link
Member

Choose a reason for hiding this comment

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

@bridiver only a few lines are similar to the Chromium one, the rest is all ours- it's def not copied. Looks good to me 👍

We could reference the area which has similarities and say something like "Logic based on Chromium one at src/components/blah/installer/" to attribute it

Copy link
Collaborator

Choose a reason for hiding this comment

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

this file is also in the wrong place. Scripts should go in the scripts directory

]
}

copy("copy_notarize_script") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we copying the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to run it from the packaging directory where the chrome/installer/mac/signing Python modules have been copied. If we ran it out of the brave/build/mac directory those Python modules aren't accessible to be imported.

Copy link
Collaborator

Choose a reason for hiding this comment

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

copying the file doesn't change where it runs from and it shouldn't be in build/mac in the first place. The scripts go in brave/scripts and they work just fine there

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess chrome also does this for some reason so don't worry about it for now

provisioning_profile = "//brave/build/mac/dummy.provisionprofile"
}

script = "$packaging_dir/notarize_dmg_pkg.py"
Copy link
Member

Choose a reason for hiding this comment

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

(per Zoom review) Can we do the rebase_path on this too?

Copy link
Member

Choose a reason for hiding this comment

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

well crap. @bridiver given this, I'd like to propose we keep the underscores in right now- but create a follow up issue and prioritize it on the Devops board

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried a few invocations of this:
rebase_path("$packaging_dir/notarize_dmg_pkg.py") a well as rebase_path("notarize_dmg_pkg.py", "$packaging_dir") but in both cases I get the error:

python ../../brave/build/mac/notarize_dmg_pkg.py ...
Traceback (most recent call last):
  File "../../brave/build/mac/notarize_dmg_pkg.py", line 27, in <module>
    from signing import config, commands, model, notarize, pipeline, signing  # noqa: E402
ImportError: No module named signing

This shows that its running the python script from the root_build_dir rather than the $packaging_dir. I think the first argument to the python interpreter in an action() target is the script but having spaces in the python script path may not be supported. I haven't seen any examples of this in the Brave or Chromium codebase after a little searching.

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

I think this is a good v1 attempt; there are two things called out which we could do in follow ups:

  1. Reduce patch size in patches/chrome-installer-mac-signing-pipeline.py.patch; we can do a touch and let the script copy an empty background/keystone script and then remove at a later point
  2. Get rid of the underscores for the action (if possible). This might mean reworking things to try use more of what Chrome has in place already (which could be tough; since we do --disable-packaging)

@bsclifton bsclifton added this to the 0.73.x - Nightly milestone Oct 30, 2019
* extend and use GetBraveSigningConfig from signing_helper.py
* remove commented out section from create_config
* remove check for do_notarization
@mihaiplesa mihaiplesa merged commit 7f7a2a8 into master Oct 30, 2019
@mihaiplesa mihaiplesa deleted the issue_5177 branch October 30, 2019 17:45
brave-builds pushed a commit that referenced this pull request Nov 1, 2019
brave-builds pushed a commit that referenced this pull request Nov 1, 2019
brave-builds pushed a commit that referenced this pull request Nov 1, 2019
mbacchi added a commit that referenced this pull request Nov 3, 2019
bsclifton pushed a commit that referenced this pull request Nov 3, 2019
mbacchi added a commit that referenced this pull request Nov 4, 2019
mbacchi added a commit that referenced this pull request Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants