-
Notifications
You must be signed in to change notification settings - Fork 3k
Add new script to automate compilation of all mbed-os 2 targets in online IDE #3818
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
Conversation
Usage: python tools/check_release.py Run from the mbed-os directory. For details on how the script works and how to set up the configuration json file, please see the python file header.
@bridadan @theotherjimmy please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. Some stuff seems a bit silly though.
@@ -0,0 +1,16 @@ | |||
{ | |||
"config" : { | |||
"mbed_repo_path" : "C:/Users/annbri01/Work/Mercurial" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not check it stuff related to only your computer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of the config is it allows any path / user to use the script. So by modifying the version of this it could run in CI or in a general account.
tools/check_release.py
Outdated
|
||
OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2') | ||
|
||
def log_message(str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just import logging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look at that, now that I know we have a logging module...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's built into python.
for m in messages: | ||
if 'severity' in m and 'message' in m: | ||
if m['severity'] == 'error': | ||
return m['message'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be more than one error message, this just gets the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be fine for our purposes. We only really want to know that the compilation failed and what the first compilation error was.
tools/check_release.py
Outdated
fail_type = None | ||
|
||
# poll for output | ||
for check in range(0, polls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can safely drop the 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
tools/check_release.py
Outdated
# 3) Internal failure of the online compiler | ||
result = bool(response['result']['data']['compilation_success']) | ||
if result: | ||
sys.stdout.write("SUCCESSFUL \n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not flushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be, will add.
|
||
# get password | ||
cmd = ['hg', 'config', 'auth.x.password'] | ||
ret, output = run_cmd_with_output(cmd, exit_on_failure=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cmd again.
tools/check_release.py
Outdated
exit(1) | ||
|
||
print("Latest mbed lib version = %s" % mbed) | ||
print("Latest mbed-dev lib version = %s" % mbed_dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More logging here.
tools/check_release.py
Outdated
|
||
# Compile each test for each supported target | ||
for test in tests: | ||
print("Test compiling program: %s\n" % test) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging here too please.
tools/check_release.py
Outdated
if not result: | ||
if mesg == 'Internal': | ||
# Internal compiler error thus retry | ||
sys.stdout.write("FAILURE \n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging.
tools/check_release.py
Outdated
continue | ||
else: | ||
# Genuine compilation error, thus print it out | ||
print("\t\tError: %s\n" % mesg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just agree with @theotherjimmy, with one thing that should be changed when getting the list of mbed 2 targets. Everything else looks good though!
tools/check_release.py
Outdated
|
||
# send task to api | ||
log_message(url + begin + "| data: " + str(payload)) | ||
r = requests.post(url + begin, data=payload, auth=auth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't hold up this PR, but you may find the urljoin
function useful in this case: https://docs.python.org/2/library/urlparse.html#urlparse.urljoin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridadan that looks like a useful module but I'm wondering if it is overkill for this one use case....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw you use similar logic around the script so I thought I'd mention it if you get tired of doing URL concatenation yourself, but yeah no worries if you just want to stick with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually the remnants of Sarah's original script and I didn't look too closely at it until you mentioned it !
tools/check_release.py
Outdated
|
||
# Get a list of the officially supported mbed-os 2 targets | ||
for tgt in OFFICIAL_MBED_LIBRARY_BUILD: | ||
if 'ARM' in tgt[1]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think is a necessary check as the tools already do this for you when you call get_mbed_official_release('2')
. And in fact, it's incorrect because it excludes the one mbed 2 target that only supports uARM: https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json#L989
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridadan I thought the online IDE only supported the ARM compiler ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uARM is the ARM compiler, it just changes the standard library to a size optimized version (micro lib)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok I just wasn't sure if the online compiler supported that. I will remove the offending IF .
Replace use of print and write with logging (with different levels). Add the ability to choose the logging level on the command line. Fix the exclusion of uARM from compilation. Remove print_on_fail from run_cmd() functions, now use logging.
@theotherjimmy @bridadan please check review comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the use of logging. We should look into using the same logging module in the rest of the tools.
tools/check_release.py
Outdated
logging.debug(r.request.body) | ||
|
||
if r.status_code != 200: | ||
raise Exception("Error while talking to the mbed API") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this exception be more specific? "Error while talking to the mbed API" is a bit vague
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's from Sarah's original script and as I haven't actually seen that hit, I'm not sure what the actual exception is. Http code 200 means " the action requested by the client was received, understood, accepted, and processed successfully" , so not 200 means the request failed to be one of those options , ie a general communication with the API error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the exception could include the error code it got back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think including the status code would be helpful in this case.
|
||
os.rename(lib_file, bak_file) | ||
else: | ||
logging.error("!! Error trying to backup lib file prior to updating.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we get rid of the "!! Error"? I think marking it as an error should be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but it's not worth blocking the PR for at this stage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it's approved.
cmd = ['hg', 'push', '-f', repo] | ||
run_cmd(cmd, exit_on_failure=True) | ||
|
||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bare exception. Could we specialize this to use a particular Exception type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky as the documentation for client.rawcommand() is sparse to say the least and certainly doesn't specify what exceptions are raised...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser(description=__doc__, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is really long. I don't know how we could make it shorter other than to put a newline immediatly after the (
. This is a style thing, so feel free to ignore it.
|
||
parser = argparse.ArgumentParser(description=__doc__, | ||
formatter_class=argparse.RawDescriptionHelpFormatter) | ||
parser.add_argument('-l', '--log-level', help="Level for providing logging output", default='INFO') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is also really long, but making it shorter should be pretty simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the line length things again aren't worth blocking the PR for. If I need to do some more work on this script in the future I'll tidy these minor stylistic things up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That's why I approved the changes. style things should not block it at this stage.
logging.basicConfig(level=level) | ||
|
||
# Read configuration data | ||
json_data = json.load(open(os.path.join(os.path.dirname(__file__), "check_release.json"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another long line. maybe a newline after that comma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
No description provided.