Skip to content

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

Merged
merged 4 commits into from
Feb 23, 2017

Conversation

adbridge
Copy link
Contributor

No description provided.

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.
@adbridge
Copy link
Contributor Author

@bridadan @theotherjimmy please review.

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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"
Copy link
Contributor

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?

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 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.


OFFICIAL_MBED_LIBRARY_BUILD = get_mbed_official_release('2')

def log_message(str):
Copy link
Contributor

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?

Copy link
Contributor Author

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...

Copy link
Contributor

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']
Copy link
Contributor

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.

Copy link
Contributor Author

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.

fail_type = None

# poll for output
for check in range(0, polls):
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

# 3) Internal failure of the online compiler
result = bool(response['result']['data']['compilation_success'])
if result:
sys.stdout.write("SUCCESSFUL \n")
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Cmd again.

exit(1)

print("Latest mbed lib version = %s" % mbed)
print("Latest mbed-dev lib version = %s" % mbed_dev)
Copy link
Contributor

Choose a reason for hiding this comment

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

More logging here.


# Compile each test for each supported target
for test in tests:
print("Test compiling program: %s\n" % test)
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging here too please.

if not result:
if mesg == 'Internal':
# Internal compiler error thus retry
sys.stdout.write("FAILURE \n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging.

continue
else:
# Genuine compilation error, thus print it out
print("\t\tError: %s\n" % mesg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging.

Copy link
Contributor

@bridadan bridadan left a 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!


# send task to api
log_message(url + begin + "| data: " + str(payload))
r = requests.post(url + begin, data=payload, auth=auth)
Copy link
Contributor

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

Copy link
Contributor Author

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....

Copy link
Contributor

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.

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's actually the remnants of Sarah's original script and I didn't look too closely at it until you mentioned it !


# Get a list of the officially supported mbed-os 2 targets
for tgt in OFFICIAL_MBED_LIBRARY_BUILD:
if 'ARM' in tgt[1]:
Copy link
Contributor

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

Copy link
Contributor Author

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 ?

Copy link
Contributor

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)

Copy link
Contributor Author

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.
@adbridge
Copy link
Contributor Author

@theotherjimmy @bridadan please check review comments

Copy link
Contributor

@theotherjimmy theotherjimmy left a 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.

logging.debug(r.request.body)

if r.status_code != 200:
raise Exception("Error while talking to the mbed API")
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.")
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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...

Copy link
Contributor

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)
Copy link
Contributor

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')
Copy link
Contributor

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.

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 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.

Copy link
Contributor

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")))
Copy link
Contributor

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?

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@theotherjimmy theotherjimmy left a comment

Choose a reason for hiding this comment

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

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants