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

Standard license headers across repo #38732

Closed
wants to merge 1 commit into from

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jul 3, 2020

We previously had a three-line license header on every file, except for files imported previously from mono, where we used a modified two-line license header on top of the one already there. The new guidance is to use a new two-line license header everywhere, such that we can have the same header regardless of whether the header originated in mono or not, and we can then enforce it via an editorconfig/analyzers/etc.

This PR automates the majority of the headers to be changed over.

This was done entirely with this (except for the addition to the .editorconfig file):

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

class Program
{
    static void Main()
    {
        var utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false);

        foreach (string path in Directory.EnumerateFiles(@"d:\repos\runtime\src\", "*", SearchOption.AllDirectories))
        {
            string[] lines = File.ReadAllLines(path);

            List<string> result = null;
            if (lines.Length >= 3 &&
                lines[0].Trim() == "// Licensed to the .NET Foundation under one or more agreements." &&
                lines[1].Trim() == "// The .NET Foundation licenses this file to you under the MIT license." &&
                lines[2].Trim() == "// See the LICENSE file in the project root for more information.")
            {
                result = new List<string>(lines);
                result.RemoveAt(2);
            }
            else if (lines.Length >= 2 &&
                lines[0].Trim() == "// Licensed to the .NET Foundation under one or more agreements." &&
                lines[1].Trim() == "// See the LICENSE file in the project root for more information.")
            {
                result = new List<string>(lines);
                result[1] = "// The .NET Foundation licenses this file to you under the MIT license.";
            }

            if (result != null)
            {
                bool bad = false;
                for (int i = 0; i < lines.Length && !bad; i++)
                {
                    foreach (char c in lines[i])
                    {
                        if (c >= 0x80)
                        {
                            Console.WriteLine(path + " @ " + i);
                            bad = true;
                            break;
                        }
                    }
                }


                if (!bad)
                {
                    File.WriteAllLines(path, result, utf8NoBom);
                }
            }
        }
    }
}

I will follow up subsequently to convert the stragglers, e.g. files with non-ASCII characters, VB, etc. I can also use the above to redo this at any time if we'd prefer to close this for now for whatever reason, e.g. concerns about conflicts, there's a better way to do it, etc.

cc: @richlander, @jkotas, @danmosemsft, @jeffschwMSFT

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@stephentoub
Copy link
Member Author

Heh, this is a first for me:
image

@stephentoub
Copy link
Member Author

/azp help

@GrabYourPitchforks
Copy link
Member

So that's why you wanted us to get to zero open PRs. ;)

@stephentoub
Copy link
Member Author

/azp list

@GrabYourPitchforks
Copy link
Member

I think there are so many files you broke the bot.
/azp run

@GrabYourPitchforks
Copy link
Member

Kicked off the pipeline manually -> https://dev.azure.com/dnceng/public/_build/results?buildId=715585

@stephentoub
Copy link
Member Author

fatal: reference is not a tree: db400d8b3af860b3228d3c78a3eac00d3124a908

@stephentoub
Copy link
Member Author

I pushed my commit as a branch to dotnet/runtime and kicked it off manually with that:
https://dev.azure.com/dnceng/public/_build/results?buildId=715595
We'll see if it makes more progress...

@GrabYourPitchforks
Copy link
Member

That'll probably work better. Both of the manual jobs I kicked off failed, probably because I didn't specify something correctly in the pipeline.

@stephentoub stephentoub force-pushed the updatelicenseheaders branch 2 times, most recently from 0603b0c to 8fa45a9 Compare July 3, 2020 20:36
@stephentoub stephentoub closed this Jul 3, 2020
@stephentoub stephentoub reopened this Jul 3, 2020
@stephentoub stephentoub closed this Jul 5, 2020
@stephentoub stephentoub deleted the updatelicenseheaders branch October 12, 2020 00:27
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants